Fixes tests.

This commit is contained in:
tastybento 2019-06-07 19:14:28 -07:00
parent 9b8c8f6bc8
commit 899315b437
2 changed files with 17 additions and 22 deletions

View File

@ -23,6 +23,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
@ -99,6 +100,9 @@ public class BentoBoxReloadCommandTest {
PowerMockito.mockStatic(Bukkit.class); PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch); when(Bukkit.getScheduler()).thenReturn(sch);
// User
when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgumentAt(0, String.class));
// Command // Command
reload = new BentoBoxReloadCommand(ac); reload = new BentoBoxReloadCommand(ac);
@ -140,36 +144,16 @@ public class BentoBoxReloadCommandTest {
"10"); "10");
} }
/**
* Test method for {@link world.bentobox.bentobox.commands.BentoBoxReloadCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfString() {
reload.execute(user, "", Collections.singletonList("bskyblock"));
Mockito.verify(user).sendMessage("commands.confirmation.confirm",
"[seconds]",
"10");
}
/**
* Test method for {@link world.bentobox.bentobox.commands.BentoBoxReloadCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringNoAddon() {
reload.execute(user, "", Collections.singletonList("warps"));
Mockito.verify(user).sendMessage("commands.bentobox.reload.unknown-addon");
}
/** /**
* Test method for {@link world.bentobox.bentobox.commands.BentoBoxReloadCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. * Test method for {@link world.bentobox.bentobox.commands.BentoBoxReloadCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */
@Test @Test
public void testExecuteUserStringListOfStringHelp() { public void testExecuteUserStringListOfStringHelp() {
reload.execute(user, "", Arrays.asList("warps", "fhfhfh")); reload.execute(user, "", Collections.singletonList("sdfsdfs"));
Mockito.verify(user).sendMessage( Mockito.verify(user).sendMessage(
"commands.help.header", "commands.help.header",
"[label]", "[label]",
null "commands.help.console"
); );
} }

View File

@ -28,7 +28,9 @@ import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
import world.bentobox.bentobox.database.objects.DataObject; import world.bentobox.bentobox.database.objects.DataObject;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@ -39,6 +41,8 @@ public class AddonsManagerTest {
private AddonsManager am; private AddonsManager am;
@Mock @Mock
private PluginManager pm; private PluginManager pm;
@Mock
private CommandsManager cm;
/** /**
* @throws Exception * @throws Exception
@ -54,6 +58,13 @@ public class AddonsManagerTest {
when(plugin.getFlagsManager()).thenReturn(fm); when(plugin.getFlagsManager()).thenReturn(fm);
am = new AddonsManager(plugin); am = new AddonsManager(plugin);
// Command Manager
when(plugin.getCommandsManager()).thenReturn(cm);
Settings s = mock(Settings.class);
when(s.getDatabaseType()).thenReturn(DatabaseType.MYSQL);
// settings
when(plugin.getSettings()).thenReturn(s);
} }
/** /**