Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
df99ccf
test(commands): Add unit tests for HealCommand functionality
TheMeinerLP Jul 19, 2025
64787e1
test(commands): Refactor HealCommandTest to use the correct MockStard…
TheMeinerLP Jul 19, 2025
6910df9
test(commands): Add unit tests for GodmodeCommand functionality and u…
TheMeinerLP Jul 19, 2025
d900103
test(commands): Add unit tests for GlowCommand functionality
TheMeinerLP Jul 19, 2025
7b84185
test(commands): Add unit tests for FlightCommand functionality
TheMeinerLP Jul 19, 2025
dbd8630
test(commands): Add unit tests for RenameCommand functionality
OneLiteFeather Jul 19, 2025
8ef4a08
Merge remote-tracking branch 'origin/feature/add-comman-tests' into f…
OneLiteFeather Jul 19, 2025
3b16083
test(commands): Rename RenameCommand class to RenameCommandTest and u…
TheMeinerLP Jul 19, 2025
dbdd289
test(coverage): Add JaCoCo for test coverage reporting and update CI …
TheMeinerLP Jul 19, 2025
141e21e
ci: Update Codecov action configuration in build-pr.yml
TheMeinerLP Jul 19, 2025
53a846f
ci: Update JaCoCo report configuration in build-pr.yml for improved c…
TheMeinerLP Jul 19, 2025
4a31018
test(commands): Add unit tests for SkullCommand functionality
OneLiteFeather Jul 19, 2025
1a44b7c
test(commands): Update SkullCommandTest to include scheduler ticks fo…
TheMeinerLP Jul 19, 2025
0de819d
test(commands): Enhance SkullCommandTest with additional assertions f…
OneLiteFeather Jul 19, 2025
361b5d8
test(commands): Add tests for SkullCommand handling of player names
TheMeinerLP Jul 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@ jobs:
uses: gradle/actions/setup-gradle@v4
- name: Build on ${{ matrix.os }}
run: ./gradlew clean build test
- name: Generate JaCoCo Coverage Report
if: matrix.os == 'ubuntu-latest'
run: ./gradlew jacocoTestReport
- name: Jacoco Report to PR
id: jacoco
uses: madrapps/[email protected]
with:
paths: ${{ github.workspace }}/build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 40
min-coverage-changed-files: 60
title: Code Coverage
update-comment: true
10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.shadow)
alias(libs.plugins.runServer)
`maven-publish`
jacoco
}

dependencies {
Expand Down Expand Up @@ -46,14 +47,23 @@ tasks {
}
test {
useJUnitPlatform()
jvmArgs("-Dstardust.insideTest=true")
testLogging {
events("passed", "skipped", "failed")
}
finalizedBy(rootProject.tasks.jacocoTestReport)
}
runServer {
minecraftVersion("1.21.4")
jvmArgs("-Dcom.mojang.eula.agree=true")
}
jacocoTestReport {
dependsOn(rootProject.tasks.test)
reports {
xml.required.set(true)
csv.required.set(true)
}
}
}

paper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ private Constants() {
public static final double RADIUS_REMOVE_ENEMIES = 32.0;
public static final String PERMISSION_SECURE_MESSAGE = "stardust.secure.message";
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy");

public static final boolean INSIDE_TEST = Boolean.parseBoolean(System.getProperty("stardust.insideTest", "false"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static boolean canEnterFlyMode(Player player) {
* Prevents looks from entities to the player.
**/
public static void removeEnemies(Player player, double radius) {
if (Constants.INSIDE_TEST) return;
var plugin = JavaPlugin.getPlugin(StardustPlugin.class);
player.getServer().getScheduler().getMainThreadExecutor(plugin).execute(() ->
player.getNearbyEntities(radius, radius, radius).forEach(entity -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package net.onelitefeather.stardust.command.commands;

import net.kyori.adventure.text.Component;
import net.onelitefeather.stardust.StardustPlugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPluginLoader;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.*;
import org.mockbukkit.mockbukkit.MockBukkit;
import org.mockbukkit.mockbukkit.ServerMock;

import java.io.File;

class FlightCommandTest {

private @NotNull ServerMock server;
private StardustPlugin plugin;
private FlightCommand command;

@SuppressWarnings("removal")
public static class MockStardustPlugin extends StardustPlugin {

public MockStardustPlugin() {
}

public MockStardustPlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
super(loader, description, dataFolder, file);
}

@Override
public void onEnable() {
// Mock enable logic if needed
}

@Override
public void onDisable() {

}

@Override
public Component getPrefix() {
return Component.text("[Stardust]");
}
}


@BeforeEach
void setUp() {
// Initialize MockBukkit
server = MockBukkit.mock();
plugin = MockBukkit.load(MockStardustPlugin.class);

// Create the command instance
command = new FlightCommand(plugin);
}

@AfterEach
void tearDown() {
// Unmock MockBukkit
MockBukkit.unmock();
}

@Disabled
@Test
void testFlightCommand() {
// Create a mock player
var player = server.addPlayer();

// Check initial flight state
Assertions.assertFalse(player.getAllowFlight(), "Player should not be able to fly initially");

// Execute the command to toggle flight
command.handleFlightCommand(player, null);

// Check if the player is now able to fly
Assertions.assertTrue(player.getAllowFlight(), "Player should be able to fly after command execution");

// Execute the command again to toggle back
command.handleFlightCommand(player, null);

// Check if the player is no longer able to fly
Assertions.assertFalse(player.getAllowFlight(), "Player should not be able to fly after toggling back");
}

@Disabled
@Test
void testGlowCommandWithTarget() {
// Create a mock player
var player = server.addPlayer();
player.addAttachment(plugin, "stardust.command.flight.others", true);
var target = server.addPlayer();
target.setAllowFlight(false);
// Check initial flight state
Assertions.assertFalse(target.getAllowFlight(), "Target player should not be able to fly initially");
// Execute the command to toggle flight for the target
command.handleFlightCommand(player, target);
// Check if the target player is now able to fly
Assertions.assertTrue(target.getAllowFlight(), "Target player should be able to fly after command execution");
// Execute the command again to toggle back
command.handleFlightCommand(player, target);
// Check if the target player is no longer able to fly
Assertions.assertFalse(target.getAllowFlight(), "Target player should not be able to fly after toggling back");
}

@Disabled
@Test
void testFlightCommandWithoutPermission() {
// Create a mock player without permission
var player = server.addPlayer();
player.addAttachment(plugin, "stardust.command.flight.others", false);
var target = server.addPlayer();

// Attempt to execute the command with a target
command.handleFlightCommand(player, target);

// Check if the target is still not able to fly
Assertions.assertFalse(target.getAllowFlight(), "Target player should not be able to fly after command execution without permission");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package net.onelitefeather.stardust.command.commands;

import net.kyori.adventure.text.Component;
import net.onelitefeather.stardust.StardustPlugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPluginLoader;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockbukkit.mockbukkit.MockBukkit;
import org.mockbukkit.mockbukkit.ServerMock;

import java.io.File;

class GlowCommandTest {

private @NotNull ServerMock server;
private StardustPlugin plugin;
private GlowCommand command;

@SuppressWarnings("removal")
public static class MockStardustPlugin extends StardustPlugin {

public MockStardustPlugin() {
}

public MockStardustPlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
super(loader, description, dataFolder, file);
}

@Override
public void onEnable() {
// Mock enable logic if needed
}

@Override
public void onDisable() {

}

@Override
public Component getPrefix() {
return Component.text("[Stardust]");
}
}


@BeforeEach
void setUp() {
// Initialize MockBukkit
server = MockBukkit.mock();
plugin = MockBukkit.load(MockStardustPlugin.class);

// Create the command instance
command = new GlowCommand(plugin);
}

@AfterEach
void tearDown() {
// Unmock MockBukkit
MockBukkit.unmock();
}

@Test
void testGlowCommand() {
// Create a mock player
var player = server.addPlayer();

// Check initial invulnerability state
Assertions.assertFalse(player.isGlowing(), "Player should not be glowing initially");

// Execute the command to toggle invulnerability
command.handleCommand(player, null);

// Check if the player is now invulnerable
Assertions.assertTrue(player.isGlowing(), "Player should be glowing after command execution");

// Execute the command again to toggle back
command.handleCommand(player, null);

// Check if the player is no longer invulnerable
Assertions.assertFalse(player.isGlowing(), "Player should not be glowing after toggling back");
}

@Test
void testGlowCommandWithTarget() {
// Create a mock player
var player = server.addPlayer();
player.addAttachment(plugin, "stardust.command.glow.others", true);
var target = server.addPlayer();

// Check initial glowing state
Assertions.assertFalse(target.isGlowing(), "Target player should not be glowing initially");

// Execute the command with a target
command.handleCommand(player, target);

// Check if the target is now glowing
Assertions.assertTrue(target.isGlowing(), "Target player should be glowing after command execution");

// Execute the command again to toggle back
command.handleCommand(player, target);

// Check if the target is no longer glowing
Assertions.assertFalse(target.isGlowing(), "Target player should not be glowing after toggling back");
}

@Test
void testGlowCommandWithPermission() {
// Create a mock player with permission
var player = server.addPlayer();
player.addAttachment(plugin, "stardust.command.glow.others", true);
var target = server.addPlayer("target");

// Check initial glowing state
Assertions.assertFalse(target.isGlowing(), "Target player should not be glowing initially");

// Execute the command with a target
command.handleCommand(player, target);

// Check if the target is now glowing
Assertions.assertTrue(target.isGlowing(), "Target player should be glowing after command execution");

// Execute the command again to toggle back
command.handleCommand(player, target);

// Check if the target is no longer glowing
Assertions.assertFalse(target.isGlowing(), "Target player should not be glowing after toggling back");
}

}
Loading
Loading