Skip to content

Commit f144a22

Browse files
tastybentoclaude
andcommitted
Bump version to 2.24.1 and expand JUnit test coverage
Adds 19 new test classes across all major packages: - calculators: ResultsTest (21 tests) - objects: IslandLevelsTest (22 tests), TopTenDataTest (4 tests) - util: CachedDataTest (6 tests), UtilsTest (13 tests) - requests: LevelRequestHandlerTest (8 tests), TopTenRequestHandlerTest (5 tests) - commands: IslandLevelCommand, IslandDonateCommand, AdminLevelCommand, AdminLevelStatusCommand, AdminTopCommand, IslandDetailCommand, IslandTopCommand, IslandValueCommand, AdminSetInitialLevelCommand - listeners: JoinLeaveListener, IslandActivitiesListeners, MigrationListener Total test count grows from ~30 to 175. All tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 58ff62f commit f144a22

20 files changed

Lines changed: 2218 additions & 1 deletion

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<!-- Do not change unless you want different name for local builds. -->
7070
<build.number>-LOCAL</build.number>
7171
<!-- This allows to change between versions. -->
72-
<build.version>2.24.0</build.version>
72+
<build.version>2.24.1</build.version>
7373
<sonar.projectKey>BentoBoxWorld_Level</sonar.projectKey>
7474
<sonar.organization>bentobox-world</sonar.organization>
7575
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package world.bentobox.level.calculators;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNotNull;
5+
import static org.junit.jupiter.api.Assertions.assertNull;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
8+
import org.bukkit.Material;
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.api.Test;
11+
12+
import world.bentobox.level.calculators.Results.Result;
13+
14+
/**
15+
* Tests for {@link Results}
16+
*/
17+
public class ResultsTest {
18+
19+
private Results results;
20+
21+
@BeforeEach
22+
public void setUp() {
23+
results = new Results();
24+
}
25+
26+
// --- State ---
27+
28+
@Test
29+
public void testDefaultStateIsAvailable() {
30+
assertEquals(Result.AVAILABLE, results.getState());
31+
}
32+
33+
@Test
34+
public void testConstructorWithInProgress() {
35+
Results r = new Results(Result.IN_PROGRESS);
36+
assertEquals(Result.IN_PROGRESS, r.getState());
37+
}
38+
39+
@Test
40+
public void testConstructorWithTimeout() {
41+
Results r = new Results(Result.TIMEOUT);
42+
assertEquals(Result.TIMEOUT, r.getState());
43+
}
44+
45+
// --- Level ---
46+
47+
@Test
48+
public void testSetAndGetLevel() {
49+
results.setLevel(42L);
50+
assertEquals(42L, results.getLevel());
51+
}
52+
53+
@Test
54+
public void testDefaultLevelIsZero() {
55+
assertEquals(0L, results.getLevel());
56+
}
57+
58+
// --- Points to next level ---
59+
60+
@Test
61+
public void testSetAndGetPointsToNextLevel() {
62+
results.setPointsToNextLevel(100L);
63+
assertEquals(100L, results.getPointsToNextLevel());
64+
}
65+
66+
@Test
67+
public void testDefaultPointsToNextLevelIsZero() {
68+
assertEquals(0L, results.getPointsToNextLevel());
69+
}
70+
71+
// --- Total points ---
72+
73+
@Test
74+
public void testSetAndGetTotalPoints() {
75+
results.setTotalPoints(500L);
76+
assertEquals(500L, results.getTotalPoints());
77+
}
78+
79+
@Test
80+
public void testDefaultTotalPointsIsZero() {
81+
assertEquals(0L, results.getTotalPoints());
82+
}
83+
84+
// --- Death handicap ---
85+
86+
@Test
87+
public void testSetAndGetDeathHandicap() {
88+
results.setDeathHandicap(3);
89+
assertEquals(3, results.getDeathHandicap());
90+
}
91+
92+
@Test
93+
public void testDefaultDeathHandicapIsZero() {
94+
assertEquals(0, results.getDeathHandicap());
95+
}
96+
97+
// --- Donated points ---
98+
99+
@Test
100+
public void testSetAndGetDonatedPoints() {
101+
results.setDonatedPoints(250L);
102+
assertEquals(250L, results.getDonatedPoints());
103+
}
104+
105+
@Test
106+
public void testDefaultDonatedPointsIsZero() {
107+
assertEquals(0L, results.getDonatedPoints());
108+
}
109+
110+
// --- Initial count ---
111+
112+
@Test
113+
public void testSetAndGetInitialCount() {
114+
results.setInitialCount(999L);
115+
assertEquals(999L, results.getInitialCount());
116+
}
117+
118+
@Test
119+
public void testDefaultInitialCountIsZero() {
120+
assertEquals(0L, results.getInitialCount());
121+
}
122+
123+
// --- Report ---
124+
125+
@Test
126+
public void testReportIsNullByDefault() {
127+
assertNull(results.getReport());
128+
}
129+
130+
// --- Multisets ---
131+
132+
@Test
133+
public void testMdCountStartsEmpty() {
134+
assertNotNull(results.getMdCount());
135+
assertTrue(results.getMdCount().isEmpty());
136+
}
137+
138+
@Test
139+
public void testUwCountStartsEmpty() {
140+
assertNotNull(results.getUwCount());
141+
assertTrue(results.getUwCount().isEmpty());
142+
}
143+
144+
@Test
145+
public void testMdCountCanAddElements() {
146+
results.getMdCount().add(Material.STONE, 5);
147+
assertEquals(5, results.getMdCount().count(Material.STONE));
148+
}
149+
150+
@Test
151+
public void testUwCountCanAddElements() {
152+
results.getUwCount().add(Material.SAND, 3);
153+
assertEquals(3, results.getUwCount().count(Material.SAND));
154+
}
155+
156+
// --- Result enum ---
157+
158+
@Test
159+
public void testResultEnumValues() {
160+
assertEquals(3, Result.values().length);
161+
assertEquals(Result.IN_PROGRESS, Result.valueOf("IN_PROGRESS"));
162+
assertEquals(Result.AVAILABLE, Result.valueOf("AVAILABLE"));
163+
assertEquals(Result.TIMEOUT, Result.valueOf("TIMEOUT"));
164+
}
165+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package world.bentobox.level.commands;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
import static org.mockito.ArgumentMatchers.any;
7+
import static org.mockito.ArgumentMatchers.anyString;
8+
import static org.mockito.Mockito.when;
9+
10+
import java.util.Collections;
11+
import java.util.List;
12+
import java.util.Optional;
13+
import java.util.UUID;
14+
import java.util.concurrent.CompletableFuture;
15+
16+
import world.bentobox.bentobox.util.Util;
17+
18+
import org.junit.jupiter.api.AfterEach;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
21+
import org.mockito.Mock;
22+
23+
import world.bentobox.bentobox.api.user.User;
24+
import world.bentobox.bentobox.managers.PlayersManager;
25+
import world.bentobox.level.CommonTestSetup;
26+
import world.bentobox.level.LevelsManager;
27+
import world.bentobox.level.calculators.Pipeliner;
28+
import world.bentobox.level.calculators.Results;
29+
import world.bentobox.level.calculators.Results.Result;
30+
import world.bentobox.level.config.ConfigSettings;
31+
32+
/**
33+
* Tests for {@link AdminLevelCommand}
34+
*/
35+
public class AdminLevelCommandTest extends CommonTestSetup {
36+
37+
@Mock
38+
private User user;
39+
@Mock
40+
private PlayersManager pm;
41+
@Mock
42+
private LevelsManager manager;
43+
@Mock
44+
private Pipeliner pipeliner;
45+
@Mock
46+
private ConfigSettings settings;
47+
48+
private AdminLevelCommand cmd;
49+
50+
@Override
51+
@BeforeEach
52+
public void setUp() throws Exception {
53+
super.setUp();
54+
when(plugin.getPlayers()).thenReturn(pm);
55+
when(addon.getManager()).thenReturn(manager);
56+
when(addon.getPipeliner()).thenReturn(pipeliner);
57+
when(addon.getSettings()).thenReturn(settings);
58+
when(settings.getLevelWait()).thenReturn(0);
59+
60+
when(user.getUniqueId()).thenReturn(uuid);
61+
when(user.isPlayer()).thenReturn(false); // admin command can run as console
62+
when(user.isOp()).thenReturn(true);
63+
when(user.getTranslation(any())).thenAnswer(i -> i.getArgument(0, String.class));
64+
when(user.getTranslation(any(), any())).thenAnswer(i -> i.getArgument(0, String.class));
65+
66+
when(pipeliner.getIslandsInQueue()).thenReturn(0);
67+
when(pipeliner.getTime()).thenReturn(1);
68+
when(pm.getUUID(anyString())).thenReturn(uuid);
69+
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
70+
when(island.getMemberSet()).thenReturn(com.google.common.collect.ImmutableSet.of(uuid));
71+
72+
Results results = new Results(Result.AVAILABLE);
73+
when(manager.calculateLevel(any(), any())).thenReturn(CompletableFuture.completedFuture(results));
74+
when(manager.getIslandLevelString(any(), any())).thenReturn("5");
75+
when(settings.isLogReportToConsole()).thenReturn(false);
76+
77+
cmd = new AdminLevelCommand(addon, ic);
78+
}
79+
80+
@Override
81+
@AfterEach
82+
public void tearDown() throws Exception {
83+
super.tearDown();
84+
}
85+
86+
@Test
87+
public void testSetup() {
88+
assertTrue(cmd.getPermission().contains("admin.level"));
89+
assertFalse(cmd.isOnlyPlayer());
90+
}
91+
92+
@Test
93+
public void testExecuteConsoleScanIsland() {
94+
// Console with player name arg scans island
95+
assertTrue(cmd.execute(user, "level", List.of("tastybento")));
96+
}
97+
98+
@Test
99+
public void testTabCompleteNoArgs() {
100+
Optional<List<String>> result = cmd.tabComplete(user, "level", Collections.emptyList());
101+
assertFalse(result.isPresent()); // empty args => return empty Optional
102+
}
103+
104+
@Test
105+
public void testTabCompleteWithArgs() {
106+
// getOnlinePlayerList calls Bukkit.getOnlinePlayers() — stub it to return empty list
107+
mockedUtil.when(() -> Util.getOnlinePlayerList(any())).thenReturn(List.of());
108+
Optional<List<String>> result = cmd.tabComplete(user, "level", List.of("tas"));
109+
assertTrue(result.isPresent()); // has args => provides list (possibly empty)
110+
}
111+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package world.bentobox.level.commands;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
import static org.mockito.ArgumentMatchers.any;
7+
import static org.mockito.ArgumentMatchers.anyString;
8+
import static org.mockito.ArgumentMatchers.eq;
9+
import static org.mockito.Mockito.verify;
10+
import static org.mockito.Mockito.when;
11+
12+
import java.util.Collections;
13+
14+
import org.junit.jupiter.api.AfterEach;
15+
import org.junit.jupiter.api.BeforeEach;
16+
import org.junit.jupiter.api.Test;
17+
import org.mockito.Mock;
18+
19+
import world.bentobox.bentobox.api.localization.TextVariables;
20+
import world.bentobox.bentobox.api.user.User;
21+
import world.bentobox.level.CommonTestSetup;
22+
import world.bentobox.level.calculators.Pipeliner;
23+
24+
/**
25+
* Tests for {@link AdminLevelStatusCommand}
26+
*/
27+
public class AdminLevelStatusCommandTest extends CommonTestSetup {
28+
29+
@Mock
30+
private User user;
31+
@Mock
32+
private Pipeliner pipeliner;
33+
34+
private AdminLevelStatusCommand cmd;
35+
36+
@Override
37+
@BeforeEach
38+
public void setUp() throws Exception {
39+
super.setUp();
40+
when(addon.getPipeliner()).thenReturn(pipeliner);
41+
when(user.getTranslation(any())).thenAnswer(i -> i.getArgument(0, String.class));
42+
cmd = new AdminLevelStatusCommand(addon, ic);
43+
}
44+
45+
@Override
46+
@AfterEach
47+
public void tearDown() throws Exception {
48+
super.tearDown();
49+
}
50+
51+
@Test
52+
public void testSetup() {
53+
assertTrue(cmd.getPermission().contains("admin.levelstatus"));
54+
assertFalse(cmd.isOnlyPlayer());
55+
assertEquals("levelstatus", cmd.getLabel());
56+
}
57+
58+
@Test
59+
public void testExecuteShowsQueueSizeZero() {
60+
when(pipeliner.getIslandsInQueue()).thenReturn(0);
61+
assertTrue(cmd.execute(user, "levelstatus", Collections.emptyList()));
62+
verify(user).sendMessage(eq("admin.levelstatus.islands-in-queue"), eq(TextVariables.NUMBER), eq("0"));
63+
}
64+
65+
@Test
66+
public void testExecuteShowsQueueSizeNonZero() {
67+
when(pipeliner.getIslandsInQueue()).thenReturn(5);
68+
assertTrue(cmd.execute(user, "levelstatus", Collections.emptyList()));
69+
verify(user).sendMessage(eq("admin.levelstatus.islands-in-queue"), eq(TextVariables.NUMBER), eq("5"));
70+
}
71+
}

0 commit comments

Comments
 (0)