Fixed 2 out of 3 tests

This commit is contained in:
Florian CUNY 2018-08-07 10:44:13 +02:00
parent 7d04d8acc2
commit e232452f65
2 changed files with 22 additions and 31 deletions

View File

@ -112,16 +112,7 @@ public class DefaultHelpCommandTest {
} }
} }
/*
@Test
public void testDefaultHelpCommand() throws Exception {
//CompositeCommand cc = mock(CompositeCommand.class);
//DefaultHelpCommand dhc = new DefaultHelpCommand(cc);
//assertNotNull(dhc);
//Mockito.verify(cc).getSubCommands();
}
*/
@Test @Test
public void testSetup() { public void testSetup() {
CompositeCommand cc = mock(CompositeCommand.class); CompositeCommand cc = mock(CompositeCommand.class);
@ -142,15 +133,15 @@ public class DefaultHelpCommandTest {
when(parent.getDescription()).thenReturn("description"); when(parent.getDescription()).thenReturn("description");
when(parent.getPermission()).thenReturn("permission"); when(parent.getPermission()).thenReturn("permission");
when(parent.getWorld()).thenReturn(mock(World.class)); when(parent.getWorld()).thenReturn(mock(World.class));
when(user.getTranslation("island")).thenReturn("island"); when(user.getTranslationOrNothing("island")).thenReturn("island");
when(user.getTranslation("parameters")).thenReturn(""); when(user.getTranslationOrNothing("parameters")).thenReturn("");
when(user.getTranslation("description")).thenReturn("the main island command"); when(user.getTranslationOrNothing("description")).thenReturn("the main island command");
DefaultHelpCommand dhc = new DefaultHelpCommand(parent); DefaultHelpCommand dhc = new DefaultHelpCommand(parent);
dhc.execute(user, dhc.getLabel(), new ArrayList<>()); dhc.execute(user, dhc.getLabel(), new ArrayList<>());
Mockito.verify(user).sendMessage("commands.help.header", "[label]", "BSkyBlock"); Mockito.verify(user).sendMessage("commands.help.header", "[label]", "BSkyBlock");
Mockito.verify(user).getTranslation("island"); Mockito.verify(user).getTranslationOrNothing("island");
Mockito.verify(user).getTranslation("parameters"); Mockito.verify(user).getTranslationOrNothing("parameters");
Mockito.verify(user).getTranslation("description"); Mockito.verify(user).getTranslationOrNothing("description");
Mockito.verify(user).sendMessage( Mockito.verify(user).sendMessage(
"commands.help.syntax", "commands.help.syntax",
"[usage]", "[usage]",
@ -171,17 +162,17 @@ public class DefaultHelpCommandTest {
when(parent.getParameters()).thenReturn("parameters"); when(parent.getParameters()).thenReturn("parameters");
when(parent.getDescription()).thenReturn("description"); when(parent.getDescription()).thenReturn("description");
when(parent.getPermission()).thenReturn("permission"); when(parent.getPermission()).thenReturn("permission");
when(user.getTranslation("island")).thenReturn("island"); when(user.getTranslationOrNothing("island")).thenReturn("island");
when(user.getTranslation("parameters")).thenReturn(""); when(user.getTranslationOrNothing("parameters")).thenReturn("");
when(user.getTranslation("description")).thenReturn("the main island command"); when(user.getTranslationOrNothing("description")).thenReturn("the main island command");
DefaultHelpCommand dhc = new DefaultHelpCommand(parent); DefaultHelpCommand dhc = new DefaultHelpCommand(parent);
List<String> args = new ArrayList<>(); List<String> args = new ArrayList<>();
args.add("1"); args.add("1");
dhc.execute(user, dhc.getLabel(), args); dhc.execute(user, dhc.getLabel(), args);
// There are no header or footer shown // There are no header or footer shown
Mockito.verify(user).getTranslation("island"); Mockito.verify(user).getTranslationOrNothing("island");
Mockito.verify(user).getTranslation("parameters"); Mockito.verify(user).getTranslationOrNothing("parameters");
Mockito.verify(user).getTranslation("description"); Mockito.verify(user).getTranslationOrNothing("description");
Mockito.verify(user).sendMessage( Mockito.verify(user).sendMessage(
"commands.help.syntax", "commands.help.syntax",
"[usage]", "[usage]",
@ -193,28 +184,25 @@ public class DefaultHelpCommandTest {
); );
} }
// FIXME Tastybento, I need help with this one! :(
@Test @Test
public void testExecuteDirectHelpHelp() { public void testExecuteDirectHelpHelp() {
CompositeCommand parent = mock(CompositeCommand.class); CompositeCommand parent = mock(CompositeCommand.class);
when(parent.getLabel()).thenReturn("island"); when(parent.getLabel()).thenReturn("island");
when(parent.getUsage()).thenReturn("island");
when(parent.getParameters()).thenReturn("parameters");
when(parent.getDescription()).thenReturn("description");
when(parent.getPermission()).thenReturn("permission");
when(user.getTranslation("island")).thenReturn("island"); when(user.getTranslation("island")).thenReturn("island");
when(user.getTranslation("parameters")).thenReturn(""); when(user.getTranslationOrNothing("island")).thenReturn("island");
when(user.getTranslation("description")).thenReturn("the main island command");
when(user.getTranslation("commands.help.parameters")).thenReturn("help-parameters"); when(user.getTranslation("commands.help.parameters")).thenReturn("help-parameters");
when(user.getTranslationOrNothing("commands.help.parameters")).thenReturn("help-parameters");
when(user.getTranslation("commands.help.description")).thenReturn("the help command"); when(user.getTranslation("commands.help.description")).thenReturn("the help command");
when(user.getTranslationOrNothing("commands.help.description")).thenReturn("the help command");
DefaultHelpCommand dhc = new DefaultHelpCommand(parent); DefaultHelpCommand dhc = new DefaultHelpCommand(parent);
List<String> args = new ArrayList<>(); List<String> args = new ArrayList<>();
// Test /island help team // Test /island help team
args.add("team"); args.add("team");
dhc.execute(user, dhc.getLabel(), args); dhc.execute(user, dhc.getLabel(), args);
// There are no header or footer shown // There are no header or footer shown
Mockito.verify(user).getTranslation("island"); Mockito.verify(user).getTranslationOrNothing("commands.help.parameters");
Mockito.verify(user).getTranslation("commands.help.parameters"); Mockito.verify(user).getTranslationOrNothing("commands.help.description");
Mockito.verify(user).getTranslation("commands.help.description");
Mockito.verify(user).sendMessage( Mockito.verify(user).sendMessage(
"commands.help.syntax", "commands.help.syntax",
"[usage]", "[usage]",

View File

@ -1,10 +1,12 @@
package world.bentobox.bentobox.api.commands.admin; package world.bentobox.bentobox.api.commands.admin;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
@ -109,7 +111,8 @@ public class AdminClearResetsAllCommandTest {
@Test @Test
public void testExecuteCheckConfirm() { public void testExecuteCheckConfirm() {
AdminClearResetsAllCommand itl = new AdminClearResetsAllCommand(ac); AdminClearResetsAllCommand itl = new AdminClearResetsAllCommand(ac);
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>(Arrays.asList("tastybento", "bobby"))));
assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>()));
Mockito.verify(user).sendMessage(Mockito.eq("general.confirm"), Mockito.eq("[seconds]"), Mockito.any()); Mockito.verify(user).sendMessage(Mockito.eq("general.confirm"), Mockito.eq("[seconds]"), Mockito.any());
} }