Skip to content

Commit

Permalink
Fix tests and refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 20, 2024
1 parent 0db4013 commit 52fedee
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util;

/**
Expand Down Expand Up @@ -60,7 +61,8 @@ public boolean execute(User user, String label, List<String> args) {
Island island = Objects.requireNonNull(getIslands().getIsland(getWorld(), user));
int rank = island.getRank(user);
if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false;
}
// Get value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package world.bentobox.aoneblock.oneblocks;

import world.bentobox.aoneblock.oneblocks.Requirement.ReqType;

/**
* Requirement for finishing a phase
* @author tastybento
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ private PanelItem createPhaseButton(ItemTemplateRecord template, Map.Entry<Integ

case PERMISSION -> permissionText.append(this.user.getTranslationOrNothing(reference + "permission",
PERMISSION, requirement.getPermission()));
case COOLDOWN -> {
// do nothing
}
default -> throw new IllegalArgumentException("Unexpected value: " + requirement.getType());

}
});
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/world/bentobox/aoneblock/AOneBlockTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlaceholdersManager;
import world.bentobox.bentobox.managers.RanksManager;

/**
* @author tastybento
Expand Down Expand Up @@ -216,10 +215,6 @@ public void setUp() throws Exception {
when(plugin.getFlagsManager()).thenReturn(fm);
when(fm.getFlags()).thenReturn(Collections.emptyList());

// RanksManager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);

}

private void add(Path path, JarOutputStream tempJarOutputStream) throws FileNotFoundException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, DatabaseSetup.class })
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, DatabaseSetup.class, RanksManager.class })
public class IslandSetCountCommandTest {
@Mock
private BentoBox plugin;
Expand All @@ -89,6 +89,9 @@ public class IslandSetCountCommandTest {
private IslandSetCountCommand iscc;
@Mock
private BlockListener bl;
@Mock
private RanksManager rm;

private @NonNull OneBlockIslands oneBlockIsland = new OneBlockIslands(UUID.randomUUID().toString());

private static AbstractDatabaseHandler<Object> h;
Expand Down Expand Up @@ -131,6 +134,9 @@ public void setUp() throws Exception {
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);

// Set up RanksManager
Whitebox.setInternalState(RanksManager.class, "instance", rm);

// Command manager
CommandsManager cm = mock(CommandsManager.class);
when(plugin.getCommandsManager()).thenReturn(cm);
Expand Down Expand Up @@ -169,10 +175,6 @@ public void setUp() throws Exception {
Settings settings = new Settings();
when(addon.getSettings()).thenReturn(settings);

// RanksManager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);

// BlockListener
when(addon.getBlockListener()).thenReturn(bl);
when(bl.getIsland(island)).thenReturn(oneBlockIsland);
Expand Down Expand Up @@ -231,6 +233,7 @@ public void testExecuteUserStringListOfStringNoIsland() {
*/
@Test
public void testExecuteUserStringListOfStringLowRank() {
when(rm.getRank(anyInt())).thenReturn(RanksManager.MEMBER_RANK_REF);
assertFalse(iscc.execute(user, "", List.of("2000")));
verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, RanksManager.MEMBER_RANK_REF);
}
Expand Down

0 comments on commit 52fedee

Please sign in to comment.