Skip to content

Commit

Permalink
Fixed and improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Poslovitch committed Dec 15, 2019
1 parent 40a9b86 commit cd9baae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ private void registerPlaceholders() {
.filter(g -> !settings.getDisabledGameModes().contains(g.getDescription().getName()))
.forEach(g -> {
// Register placeholders
getPlugin().getPlaceholdersManager()
.registerPlaceholder(this, g.getDescription().getName().toLowerCase() + "_island_generator_tier",
user -> {
long level = isLevelProvided() ? 0L : getLevelAddon().getIslandLevel(g.getOverWorld(), user.getUniqueId());
Settings.GeneratorTier tier = getManager().getGeneratorTier(level, user.getWorld());
return tier != null ? tier.getName() : "";
});
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
g.getDescription().getName().toLowerCase() + "_island_generator_tier",
user -> {
long level = isLevelProvided() ? 0L : getLevelAddon().getIslandLevel(g.getOverWorld(), user.getUniqueId());
Settings.GeneratorTier tier = getManager().getGeneratorTier(level, user.getWorld());
return tier != null ? tier.getName() : "";
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.managers.AddonsManager;
import world.bentobox.bentobox.managers.PlaceholdersManager;
import world.bentobox.magiccobblestonegenerator.config.Settings;
import world.bentobox.magiccobblestonegenerator.tasks.MagicGenerator;

Expand All @@ -68,6 +69,9 @@ public class StoneGeneratorAddonTest {
@Mock
private GameModeAddon gameMode;

@Mock
private PlaceholdersManager placeholdersManager;

/**
* @throws java.lang.Exception
*/
Expand All @@ -77,6 +81,7 @@ public void setUp() throws Exception {
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
when(plugin.isEnabled()).thenReturn(true);
when(plugin.getLogger()).thenReturn(logger);
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
// Bukkit
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getLogger()).thenReturn(logger);
Expand Down Expand Up @@ -115,8 +120,6 @@ public void setUp() throws Exception {
@NonNull
Optional<CompositeCommand> opCmd = Optional.of(cmd );
when(gameMode.getPlayerCommand()).thenReturn(opCmd);


}

/**
Expand All @@ -140,27 +143,6 @@ private void deleteAll(File file) throws IOException {
}

}

/**
* Test method for {@link world.bentobox.magiccobblestonegenerator.StoneGeneratorAddon#onEnable()}.
*/
@Test
public void testOnEnableDisabledPlugin() {
when(plugin.isEnabled()).thenReturn(false);
addon.onEnable();
verify(logger).severe(eq("BentoBox is not available or disabled!"));
assertEquals(addon.getState(), State.DISABLED);
}

/**
* Test method for {@link world.bentobox.magiccobblestonegenerator.StoneGeneratorAddon#onEnable()}.
*/
@Test
public void testOnEnableDisabled() {
addon.setState(State.DISABLED);
addon.onEnable();
verify(logger).severe(eq("Magic Cobblestone Generator Addon is not available or disabled!"));
}

/**
* Test method for {@link world.bentobox.magiccobblestonegenerator.StoneGeneratorAddon#onEnable()}.
Expand Down Expand Up @@ -225,7 +207,7 @@ public void testOnReloadDisabled() {
public void testGetSettings() {
assertNull(addon.getSettings());
addon.onLoad();
assertTrue(addon.getSettings() instanceof Settings);
assertNotNull(addon.getSettings());

}

Expand All @@ -236,7 +218,7 @@ public void testGetSettings() {
public void testGetGenerator() {
assertNull(addon.getGenerator());
testOnEnable();
assertTrue(addon.getGenerator() instanceof MagicGenerator);
assertNotNull(addon.getGenerator());
}

/**
Expand All @@ -246,7 +228,7 @@ public void testGetGenerator() {
public void testGetManager() {
assertNull(addon.getManager());
testOnEnable();
assertTrue(addon.getManager() instanceof StoneGeneratorManager);
assertNotNull(addon.getManager());
}

/**
Expand Down

0 comments on commit cd9baae

Please sign in to comment.