Fixed GameModePlaceholderManager tests

This commit is contained in:
Florian CUNY 2019-04-07 10:13:34 +02:00
parent 79ca7512d1
commit e66f3842b7

View File

@ -1,7 +1,6 @@
package world.bentobox.bentobox.managers;
import org.eclipse.jdt.annotation.NonNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -23,57 +22,49 @@ import static org.mockito.Mockito.when;
@PrepareForTest( {BentoBox.class} )
public class GameModePlaceholderManagerTest {
@Mock
@Mock
private BentoBox plugin;
@Mock
private GameModeAddon addon;
@Mock
private PlaceholdersManager pm;
private GameModePlaceholderManager gpm;
@Mock
private GameModeAddon addon;
@Mock
private PlaceholdersManager pm;
@Before
public void setUp() throws Exception {
gpm = new GameModePlaceholderManager(plugin);
// Addon
@NonNull
AddonDescription desc = new AddonDescription.Builder("main", "bskyblock", "1.0").build();
when(addon.getDescription()).thenReturn(desc);
when(plugin.getPlaceholdersManager()).thenReturn(pm);
// No placeholders registered yet
when(pm.isPlaceholder(Mockito.any(), Mockito.any())).thenReturn(false);
}
private GameModePlaceholderManager gpm;
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
@Before
public void setUp() throws Exception {
gpm = new GameModePlaceholderManager(plugin);
// Addon
@NonNull
AddonDescription desc = new AddonDescription.Builder("main", "bskyblock", "1.0").build();
when(addon.getDescription()).thenReturn(desc);
/**
* Test method for {@link world.bentobox.bentobox.managers.GameModePlaceholderManager#registerGameModePlaceholders(world.bentobox.bentobox.api.addons.GameModeAddon)}.
*/
@Test
public void testRegisterGameModePlaceholdersAllDefaults() {
gpm.registerGameModePlaceholders(addon);
// 7 registrations for this addon
Mockito.verify(pm, Mockito.times(7)).registerPlaceholder(Mockito.anyString(), Mockito.any());
}
/**
* Test method for {@link world.bentobox.bentobox.managers.GameModePlaceholderManager#registerGameModePlaceholders(world.bentobox.bentobox.api.addons.GameModeAddon)}.
*/
@Test
public void testRegisterGameModePlaceholdersSomePreregistered() {
// Some duplicates
when(pm.isPlaceholder(Mockito.any(), Mockito.any())).thenReturn(false, true, true, false, false, true, false);
when(plugin.getPlaceholdersManager()).thenReturn(pm);
// No placeholders registered yet
when(pm.isPlaceholder(Mockito.any(), Mockito.any())).thenReturn(false);
}
gpm.registerGameModePlaceholders(addon);
// 3 registrations for this addon
Mockito.verify(pm, Mockito.times(4)).registerPlaceholder(Mockito.anyString(), Mockito.any());
}
/**
* Test method for {@link world.bentobox.bentobox.managers.GameModePlaceholderManager#registerGameModePlaceholders(world.bentobox.bentobox.api.addons.GameModeAddon)}.
*/
@Test
public void testRegisterGameModePlaceholdersAllDefaults() {
gpm.registerGameModePlaceholders(addon);
// 7 registrations for this addon
Mockito.verify(pm, Mockito.atLeast(1)).registerPlaceholder(Mockito.anyString(), Mockito.any());
}
/**
* Test method for {@link world.bentobox.bentobox.managers.GameModePlaceholderManager#registerGameModePlaceholders(world.bentobox.bentobox.api.addons.GameModeAddon)}.
*/
@Test
public void testRegisterGameModePlaceholdersSomePreregistered() {
// Some duplicates
when(pm.isPlaceholder(Mockito.any(), Mockito.any())).thenReturn(false, true, true, false, false, true, false);
gpm.registerGameModePlaceholders(addon);
// 3 registrations for this addon
Mockito.verify(pm, Mockito.atLeast(1)).registerPlaceholder(Mockito.anyString(), Mockito.any());
}
}