Skip to content

Commit 8b3665d

Browse files
tastybentoclaude
andcommitted
Expand test coverage with new listener and placeholder tests
Adds PlaceholdersManagerTest (8 tests) and AdvancementListenerTest (25 tests) for previously untested classes, plus 6 branch-coverage tests in AdvancementsManagerTest for getScore, addAdvancement, and checkIslandSize edge cases. Full suite: 112 tests passing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 65b96b4 commit 8b3665d

File tree

3 files changed

+543
-0
lines changed

3 files changed

+543
-0
lines changed

src/test/java/world/bentobox/boxed/AdvancementsManagerTest.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,69 @@ public void testGetScoreAdvancement() {
293293
assertEquals(9, am.getScore(advancement));
294294
}
295295

296+
/**
297+
* Test method for {@link world.bentobox.boxed.AdvancementsManager#getScore(org.bukkit.advancement.Advancement)}.
298+
* Root advancements fall back to settings.default-root-increase (0 in the shipped config).
299+
*/
300+
@Test
301+
public void testGetScoreAdvancementRoot() {
302+
when(advancement.getKey()).thenReturn(NamespacedKey.fromString("story/root"));
303+
assertEquals(0, am.getScore(advancement));
304+
}
305+
306+
/**
307+
* Test method for {@link world.bentobox.boxed.AdvancementsManager#getScore(org.bukkit.advancement.Advancement)}.
308+
* Recipe advancements always score settings.unknown-recipe-increase (0 in the shipped config).
309+
*/
310+
@Test
311+
public void testGetScoreAdvancementRecipe() {
312+
when(advancement.getKey()).thenReturn(NamespacedKey.fromString("recipes/brewing/blaze_powder"));
313+
assertEquals(0, am.getScore(advancement));
314+
}
315+
316+
/**
317+
* Test method for {@link world.bentobox.boxed.AdvancementsManager#addAdvancement(org.bukkit.entity.Player, org.bukkit.advancement.Advancement)}.
318+
* No island for this player means no expansion and a zero score.
319+
*/
320+
@Test
321+
public void testAddAdvancementPlayerAdvancementNullIsland() {
322+
when(im.getIsland(world, player.getUniqueId())).thenReturn(null);
323+
assertEquals(0, am.addAdvancement(player, advancement));
324+
verify(island, never()).setProtectionRange(org.mockito.ArgumentMatchers.anyInt());
325+
}
326+
327+
/**
328+
* Test method for {@link world.bentobox.boxed.AdvancementsManager#addAdvancement(org.bukkit.entity.Player, org.bukkit.advancement.Advancement)}.
329+
* Visitors (rank below MEMBER_RANK) cannot expand the island.
330+
*/
331+
@Test
332+
public void testAddAdvancementPlayerAdvancementVisitorRank() {
333+
when(island.getRank(player.getUniqueId())).thenReturn(RanksManager.VISITOR_RANK);
334+
assertEquals(0, am.addAdvancement(player, advancement));
335+
verify(island, never()).setProtectionRange(org.mockito.ArgumentMatchers.anyInt());
336+
}
337+
338+
/**
339+
* Test method for {@link world.bentobox.boxed.AdvancementsManager#addAdvancement(org.bukkit.entity.Player, org.bukkit.advancement.Advancement)}.
340+
* An advancement that's already been recorded on the island cannot grant a second expansion.
341+
*/
342+
@Test
343+
public void testAddAdvancementPlayerAdvancementAlreadyHas() {
344+
// Seed the island with the exact same namespaced key the manager will try to record.
345+
am.addAdvancement(island, advancement.getKey().toString());
346+
assertEquals(0, am.addAdvancement(player, advancement));
347+
}
348+
349+
/**
350+
* Test method for {@link world.bentobox.boxed.AdvancementsManager#checkIslandSize(world.bentobox.bentobox.database.objects.Island)}.
351+
* Positive diff case: one scoring advancement grows a size-1 island to size 10.
352+
*/
353+
@Test
354+
public void testCheckIslandSizePositiveDiff() {
355+
when(island.getProtectionRange()).thenReturn(1);
356+
am.addAdvancement(island, "adventure/honey_block_slide");
357+
assertEquals(9, am.checkIslandSize(island));
358+
verify(island).setProtectionRange(10);
359+
}
360+
296361
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package world.bentobox.boxed;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.mockito.Mockito.when;
5+
6+
import java.util.List;
7+
import java.util.Optional;
8+
import java.util.UUID;
9+
10+
import org.bukkit.Location;
11+
import org.junit.jupiter.api.AfterEach;
12+
import org.junit.jupiter.api.BeforeEach;
13+
import org.junit.jupiter.api.Test;
14+
import org.mockito.Mock;
15+
16+
import world.bentobox.bentobox.api.user.User;
17+
import world.bentobox.boxed.objects.IslandAdvancements;
18+
19+
/**
20+
* @author tastybento
21+
*/
22+
public class PlaceholdersManagerTest extends CommonTestSetup {
23+
24+
@Mock
25+
private Boxed addon;
26+
@Mock
27+
private AdvancementsManager advManager;
28+
@Mock
29+
private IslandAdvancements islandAdv;
30+
@Mock
31+
private User user;
32+
@Mock
33+
private Location userLocation;
34+
35+
private PlaceholdersManager phm;
36+
private UUID uuid;
37+
38+
@Override
39+
@BeforeEach
40+
public void setUp() throws Exception {
41+
super.setUp();
42+
43+
uuid = UUID.randomUUID();
44+
when(user.getUniqueId()).thenReturn(uuid);
45+
when(user.getLocation()).thenReturn(userLocation);
46+
47+
when(addon.getIslands()).thenReturn(im);
48+
when(addon.getOverWorld()).thenReturn(world);
49+
when(addon.getAdvManager()).thenReturn(advManager);
50+
51+
when(advManager.getIsland(island)).thenReturn(islandAdv);
52+
when(islandAdv.getAdvancements()).thenReturn(List.of("a", "b", "c"));
53+
54+
phm = new PlaceholdersManager(addon);
55+
}
56+
57+
@Override
58+
@AfterEach
59+
public void tearDown() throws Exception {
60+
super.tearDown();
61+
}
62+
63+
@Test
64+
public void testGetCountNullUser() {
65+
assertEquals("", phm.getCount(null));
66+
}
67+
68+
@Test
69+
public void testGetCountNullUuid() {
70+
when(user.getUniqueId()).thenReturn(null);
71+
assertEquals("", phm.getCount(user));
72+
}
73+
74+
@Test
75+
public void testGetCountNoIsland() {
76+
when(im.getIsland(world, user)).thenReturn(null);
77+
assertEquals("", phm.getCount(user));
78+
}
79+
80+
@Test
81+
public void testGetCountReturnsAdvancementCount() {
82+
when(im.getIsland(world, user)).thenReturn(island);
83+
assertEquals("3", phm.getCount(user));
84+
}
85+
86+
@Test
87+
public void testGetCountByLocationNullUser() {
88+
assertEquals("", phm.getCountByLocation(null));
89+
}
90+
91+
@Test
92+
public void testGetCountByLocationNullLocation() {
93+
when(user.getLocation()).thenReturn(null);
94+
assertEquals("", phm.getCountByLocation(user));
95+
}
96+
97+
@Test
98+
public void testGetCountByLocationNoIslandAtLocation() {
99+
when(im.getIslandAt(userLocation)).thenReturn(Optional.empty());
100+
assertEquals("", phm.getCountByLocation(user));
101+
}
102+
103+
@Test
104+
public void testGetCountByLocationReturnsAdvancementCount() {
105+
when(im.getIslandAt(userLocation)).thenReturn(Optional.of(island));
106+
assertEquals("3", phm.getCountByLocation(user));
107+
}
108+
}

0 commit comments

Comments
 (0)