mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 13:15:28 +01:00
Added assertions to tests per SonarCloud
This commit is contained in:
parent
272e99bc12
commit
fc2de2501c
@ -296,14 +296,14 @@ public class Flag implements Comparable<Flag> {
|
||||
}
|
||||
Island island = plugin.getIslands().getIslandAt(user.getLocation()).orElse(plugin.getIslands().getIsland(user.getWorld(), user.getUniqueId()));
|
||||
switch(getType()) {
|
||||
case PROTECTION:
|
||||
return createProtectionFlag(plugin, user, island, pib).build();
|
||||
case SETTING:
|
||||
return createSettingFlag(user, island, pib).build();
|
||||
case WORLD_SETTING:
|
||||
return createWorldSettingFlag(user, pib).build();
|
||||
default:
|
||||
return pib.build();
|
||||
case PROTECTION:
|
||||
return createProtectionFlag(plugin, user, island, pib).build();
|
||||
case SETTING:
|
||||
return createSettingFlag(user, island, pib).build();
|
||||
case WORLD_SETTING:
|
||||
return createWorldSettingFlag(user, pib).build();
|
||||
default:
|
||||
return pib.build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,18 +483,18 @@ public class Flag implements Comparable<Flag> {
|
||||
// If no clickHandler has been set, then apply default ones
|
||||
if (clickHandler == null) {
|
||||
switch (type){
|
||||
case PROTECTION:
|
||||
clickHandler = new CycleClick(id);
|
||||
break;
|
||||
case SETTING:
|
||||
clickHandler = new IslandToggleClick(id);
|
||||
break;
|
||||
case WORLD_SETTING:
|
||||
clickHandler = new WorldToggleClick(id);
|
||||
break;
|
||||
default:
|
||||
clickHandler = new CycleClick(id);
|
||||
break;
|
||||
case PROTECTION:
|
||||
clickHandler = new CycleClick(id);
|
||||
break;
|
||||
case SETTING:
|
||||
clickHandler = new IslandToggleClick(id);
|
||||
break;
|
||||
case WORLD_SETTING:
|
||||
clickHandler = new WorldToggleClick(id);
|
||||
break;
|
||||
default:
|
||||
clickHandler = new CycleClick(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,13 @@
|
||||
package world.bentobox.bentobox.api.commands.admin;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.eq;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -90,15 +94,15 @@ public class AdminTeleportCommandTest {
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true);
|
||||
when(im.getOwner(Mockito.any(),Mockito.any())).thenReturn(uuid);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||
when(im.isOwner(any(),any())).thenReturn(true);
|
||||
when(im.getOwner(any(),any())).thenReturn(uuid);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
@ -109,7 +113,7 @@ public class AdminTeleportCommandTest {
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
when(user.getTranslation(Mockito.anyString(),Mockito.anyString(), Mockito.anyString())).thenAnswer(new Answer<String>() {
|
||||
@ -122,12 +126,12 @@ public class AdminTeleportCommandTest {
|
||||
// Island location
|
||||
Location location = mock(Location.class);
|
||||
Vector vector = mock(Vector.class);
|
||||
when(vector.toLocation(Mockito.any())).thenReturn(location);
|
||||
when(vector.toLocation(any())).thenReturn(location);
|
||||
when(location.toVector()).thenReturn(vector);
|
||||
when(im.getIslandLocation(Mockito.any(), Mockito.any())).thenReturn(location);
|
||||
when(im.getIslandLocation(any(), any())).thenReturn(location);
|
||||
// We do no actually want to teleport in this test, so return no island
|
||||
Optional<Island> nothing = Optional.empty();
|
||||
when(im.getIslandAt(Mockito.any())).thenReturn(nothing );
|
||||
when(im.getIslandAt(any())).thenReturn(nothing );
|
||||
}
|
||||
|
||||
|
||||
@ -136,9 +140,12 @@ public class AdminTeleportCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfString() {
|
||||
new AdminTeleportCommand(ac,"tp");
|
||||
new AdminTeleportCommand(ac,"tpnether");
|
||||
new AdminTeleportCommand(ac,"tpend");
|
||||
AdminTeleportCommand c = new AdminTeleportCommand(ac,"tp");
|
||||
assertEquals("tp",c.getLabel());
|
||||
c = new AdminTeleportCommand(ac,"tpnether");
|
||||
assertEquals("tpnether",c.getLabel());
|
||||
c = new AdminTeleportCommand(ac,"tpend");
|
||||
assertEquals("tpend",c.getLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,66 +155,66 @@ public class AdminTeleportCommandTest {
|
||||
public void testExecuteUserStringListOfStringEmptyArgs() {
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tp");
|
||||
assertFalse(atc.execute(user, "tp", new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.anyString());
|
||||
verify(user).sendMessage(Mockito.anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringUnknownTarget() {
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tp");
|
||||
assertFalse(atc.execute(user, "tp", Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player"), Mockito.eq(TextVariables.NAME), Mockito.eq("tastybento"));
|
||||
verify(user).sendMessage(eq("general.errors.unknown-player"), eq(TextVariables.NAME), eq("tastybento"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringKnownTargetNoIsland() {
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(notUUID);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tp");
|
||||
assertFalse(atc.execute(user, "tp", Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.player-has-no-island"));
|
||||
verify(user).sendMessage(eq("general.errors.player-has-no-island"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringKnownTargetHasIsland() {
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(notUUID);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tp");
|
||||
assertTrue(atc.execute(user, "tp", Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).getTranslation(Mockito.eq("commands.admin.tp.manual"), Mockito.eq("[location]"), Mockito.eq("0 0 0"));
|
||||
verify(user).getTranslation(eq("commands.admin.tp.manual"), eq("[location]"), eq("0 0 0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringKnownTargetIsTeamMember() {
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(notUUID);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(any(), any(UUID.class))).thenReturn(true);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tp");
|
||||
assertTrue(atc.execute(user, "tp", Collections.singletonList("tastybento")));
|
||||
Mockito.verify(iwm, Mockito.never()).getNetherWorld(Mockito.any());
|
||||
Mockito.verify(iwm, Mockito.never()).getEndWorld(Mockito.any());
|
||||
Mockito.verify(user).getTranslation(Mockito.eq("commands.admin.tp.manual"), Mockito.eq("[location]"), Mockito.eq("0 0 0"));
|
||||
verify(iwm, Mockito.never()).getNetherWorld(any());
|
||||
verify(iwm, Mockito.never()).getEndWorld(any());
|
||||
verify(user).getTranslation(eq("commands.admin.tp.manual"), eq("[location]"), eq("0 0 0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringKnownTargetHasIslandNether() {
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(notUUID);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tpnether");
|
||||
assertTrue(atc.execute(user, "tpnether", Collections.singletonList("tastybento")));
|
||||
Mockito.verify(iwm).getNetherWorld(Mockito.any());
|
||||
Mockito.verify(iwm, Mockito.never()).getEndWorld(Mockito.any());
|
||||
Mockito.verify(user).getTranslation(Mockito.eq("commands.admin.tp.manual"), Mockito.eq("[location]"), Mockito.eq("0 0 0"));
|
||||
verify(iwm).getNetherWorld(any());
|
||||
verify(iwm, Mockito.never()).getEndWorld(any());
|
||||
verify(user).getTranslation(eq("commands.admin.tp.manual"), eq("[location]"), eq("0 0 0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringKnownTargetHasIslandEnd() {
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(notUUID);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
AdminTeleportCommand atc = new AdminTeleportCommand(ac,"tpend");
|
||||
assertTrue(atc.execute(user, "tpend", Collections.singletonList("tastybento")));
|
||||
Mockito.verify(iwm, Mockito.never()).getNetherWorld(Mockito.any());
|
||||
Mockito.verify(iwm).getEndWorld(Mockito.any());
|
||||
Mockito.verify(user).getTranslation(Mockito.eq("commands.admin.tp.manual"), Mockito.eq("[location]"), Mockito.eq("0 0 0"));
|
||||
verify(iwm, Mockito.never()).getNetherWorld(any());
|
||||
verify(iwm).getEndWorld(any());
|
||||
verify(user).getTranslation(eq("commands.admin.tp.manual"), eq("[location]"), eq("0 0 0"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -227,7 +227,8 @@ public class IslandTeamInviteCommandTest {
|
||||
when(s.getInviteCooldown()).thenReturn(10);
|
||||
IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ public class IslandTeamTrustCommandTest {
|
||||
when(s.getInviteCooldown()).thenReturn(10);
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -221,7 +221,7 @@ public class IslandTeamUncoopCommandTest {
|
||||
when(s.getInviteCooldown()).thenReturn(10);
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -255,8 +255,8 @@ public class IslandTeamUncoopCommandTest {
|
||||
public void testTabComplete() {
|
||||
|
||||
Builder<UUID> memberSet = new ImmutableSet.Builder<>();
|
||||
for (int j = 0; j < 11; j++) {
|
||||
memberSet.add(UUID.randomUUID());
|
||||
for (int j = 0; j < 11; j++) {
|
||||
memberSet.add(UUID.randomUUID());
|
||||
}
|
||||
|
||||
when(island.getMemberSet()).thenReturn(memberSet.build());
|
||||
|
@ -221,7 +221,7 @@ public class IslandTeamUntrustCommandTest {
|
||||
when(s.getInviteCooldown()).thenReturn(10);
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -255,8 +255,8 @@ public class IslandTeamUntrustCommandTest {
|
||||
public void testTabComplete() {
|
||||
|
||||
Builder<UUID> memberSet = new ImmutableSet.Builder<>();
|
||||
for (int j = 0; j < 11; j++) {
|
||||
memberSet.add(UUID.randomUUID());
|
||||
for (int j = 0; j < 11; j++) {
|
||||
memberSet.add(UUID.randomUUID());
|
||||
}
|
||||
|
||||
when(island.getMemberSet()).thenReturn(memberSet.build());
|
||||
|
@ -74,7 +74,8 @@ public class FlagTest {
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
|
||||
// Return world
|
||||
when(Util.getWorld(Mockito.any())).thenAnswer((Answer<World>) invocation -> invocation.getArgumentAt(0, World.class));
|
||||
|
||||
// World Settings
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
@ -193,6 +194,9 @@ public class FlagTest {
|
||||
@Test
|
||||
public void testSetDefaultSettingBoolean() {
|
||||
f.setDefaultSetting(true);
|
||||
assertTrue(f.isSetForWorld(world));
|
||||
f.setDefaultSetting(false);
|
||||
assertFalse(f.isSetForWorld(world));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,6 +205,9 @@ public class FlagTest {
|
||||
@Test
|
||||
public void testSetDefaultSettingWorldBoolean() {
|
||||
f.setDefaultSetting(world, true);
|
||||
assertTrue(f.isSetForWorld(world));
|
||||
f.setDefaultSetting(world, false);
|
||||
assertFalse(f.isSetForWorld(world));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,13 +63,6 @@ public class BentoBoxLocaleTest {
|
||||
localeObject = new BentoBoxLocale(locale, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.localization.BentoBoxLocale#BentoBoxLocale(java.util.Locale, org.bukkit.configuration.file.YamlConfiguration)}.
|
||||
*/
|
||||
@Test
|
||||
public void testBentoBoxLocale() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.localization.BentoBoxLocale#get(java.lang.String)}.
|
||||
*/
|
||||
|
@ -19,6 +19,7 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.PanelListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
@ -28,7 +29,7 @@ import world.bentobox.bentobox.api.user.User;
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class })
|
||||
@PrepareForTest({Bukkit.class})
|
||||
public class PanelBuilderTest {
|
||||
|
||||
/**
|
||||
@ -63,7 +64,8 @@ public class PanelBuilderTest {
|
||||
pb = pb.item(pi);
|
||||
pb = pb.item(pi);
|
||||
pb = pb.item(pi);
|
||||
|
||||
assertTrue(pb.slotOccupied(3));
|
||||
assertFalse(pb.slotOccupied(4));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,6 +80,11 @@ public class PanelBuilderTest {
|
||||
pb = pb.item(1, pi);
|
||||
pb = pb.item(10, pi);
|
||||
pb = pb.item(20, pi);
|
||||
assertTrue(pb.slotOccupied(0));
|
||||
assertTrue(pb.slotOccupied(1));
|
||||
assertTrue(pb.slotOccupied(10));
|
||||
assertTrue(pb.slotOccupied(20));
|
||||
assertFalse(pb.slotOccupied(4));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,7 +93,7 @@ public class PanelBuilderTest {
|
||||
@Test
|
||||
public void testSize() {
|
||||
PanelBuilder pb = new PanelBuilder();
|
||||
pb = pb.size(45);
|
||||
assertEquals(pb, pb.size(45));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,7 +106,7 @@ public class PanelBuilderTest {
|
||||
pb = pb.user(user);
|
||||
// Change user
|
||||
User user2 = mock(User.class);
|
||||
pb = pb.user(user2);
|
||||
assertEquals(pb, pb.user(user2));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,7 +116,7 @@ public class PanelBuilderTest {
|
||||
public void testListener() {
|
||||
PanelBuilder pb = new PanelBuilder();
|
||||
PanelListener listener = mock(PanelListener.class);
|
||||
pb = pb.listener(listener);
|
||||
assertEquals(pb, pb.listener(listener));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,7 +165,9 @@ public class PanelBuilderTest {
|
||||
@Test
|
||||
public void testBuild() {
|
||||
PanelBuilder pb = new PanelBuilder();
|
||||
pb.build();
|
||||
}
|
||||
pb.name("test");
|
||||
Panel p = pb.build();
|
||||
assertEquals("test", p.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
@ -59,6 +61,8 @@ public class UserTest {
|
||||
private LocalesManager lm;
|
||||
private User user;
|
||||
private IslandWorldManager iwm;
|
||||
private Server server;
|
||||
private UUID uuid;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@ -67,13 +71,15 @@ public class UserTest {
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
User.setPlugin(plugin);
|
||||
|
||||
Server server = mock(Server.class);
|
||||
server = mock(Server.class);
|
||||
World world = mock(World.class);
|
||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
when(server.getWorld("world")).thenReturn(world);
|
||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||
|
||||
player = mock(Player.class);
|
||||
uuid = UUID.randomUUID();
|
||||
when(player.getUniqueId()).thenReturn(uuid);
|
||||
when(server.getPlayer(Mockito.any(UUID.class))).thenReturn(player);
|
||||
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
@ -141,13 +147,21 @@ public class UserTest {
|
||||
|
||||
@Test
|
||||
public void testRemovePlayer() {
|
||||
assertNotNull(User.getInstance(uuid));
|
||||
assertEquals(user, User.getInstance(uuid));
|
||||
User.removePlayer(player);
|
||||
// If the player has been removed from the cache, then code will ask server for player
|
||||
// Return null and check if instance is null will show that the player is not in the cache
|
||||
when(Bukkit.getPlayer(Mockito.any(UUID.class))).thenReturn(null);
|
||||
assertNull(User.getInstance(uuid).getPlayer());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPlugin() {
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
User.setPlugin(plugin);
|
||||
user.addPerm("testing123");
|
||||
verify(player).addAttachment(eq(plugin), eq("testing123"), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -278,7 +292,7 @@ public class UserTest {
|
||||
@Test
|
||||
public void testSendMessage() {
|
||||
user.sendMessage("a.reference");
|
||||
Mockito.verify(player).sendMessage(Mockito.eq(TEST_TRANSLATION));
|
||||
verify(player).sendMessage(eq(TEST_TRANSLATION));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -290,10 +304,10 @@ public class UserTest {
|
||||
user.setAddon(addon);
|
||||
Optional<GameModeAddon> optionalAddon = Optional.of(addon);
|
||||
when(iwm .getAddon(any())).thenReturn(optionalAddon);
|
||||
when(lm.get(any(), Mockito.eq("name.a.reference"))).thenReturn("mockmockmock");
|
||||
when(lm.get(any(), eq("name.a.reference"))).thenReturn("mockmockmock");
|
||||
user.sendMessage("a.reference");
|
||||
Mockito.verify(player, Mockito.never()).sendMessage(Mockito.eq(TEST_TRANSLATION));
|
||||
Mockito.verify(player).sendMessage(Mockito.eq("mockmockmock"));
|
||||
verify(player, Mockito.never()).sendMessage(eq(TEST_TRANSLATION));
|
||||
verify(player).sendMessage(eq("mockmockmock"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -301,7 +315,7 @@ public class UserTest {
|
||||
// Nothing - blank translation
|
||||
when(lm.get(any(), any())).thenReturn("");
|
||||
user.sendMessage("a.reference");
|
||||
Mockito.verify(player, Mockito.never()).sendMessage(Mockito.anyString());
|
||||
verify(player, Mockito.never()).sendMessage(Mockito.anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -313,14 +327,14 @@ public class UserTest {
|
||||
}
|
||||
when(lm.get(any(), any())).thenReturn(allColors.toString());
|
||||
user.sendMessage("a.reference");
|
||||
Mockito.verify(player, Mockito.never()).sendMessage(Mockito.anyString());
|
||||
verify(player, Mockito.never()).sendMessage(Mockito.anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendRawMessage() {
|
||||
String raw = ChatColor.RED + "" + ChatColor.BOLD + "test message";
|
||||
user.sendRawMessage(raw);
|
||||
Mockito.verify(player).sendMessage(raw);
|
||||
verify(player).sendMessage(raw);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -328,7 +342,7 @@ public class UserTest {
|
||||
String raw = ChatColor.RED + "" + ChatColor.BOLD + "test message";
|
||||
user = User.getInstance((CommandSender)null);
|
||||
user.sendRawMessage(raw);
|
||||
Mockito.verify(player, Mockito.never()).sendMessage(Mockito.anyString());
|
||||
verify(player, Mockito.never()).sendMessage(Mockito.anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -340,10 +354,10 @@ public class UserTest {
|
||||
when(lm.get(any(), any())).thenReturn(translation);
|
||||
|
||||
// Set notify
|
||||
when(notifier.notify(any(), Mockito.eq(translation))).thenReturn(true);
|
||||
when(notifier.notify(any(), eq(translation))).thenReturn(true);
|
||||
|
||||
user.notify("a.reference");
|
||||
Mockito.verify(notifier).notify(user, translation);
|
||||
verify(notifier).notify(user, translation);
|
||||
}
|
||||
|
||||
|
||||
@ -352,7 +366,7 @@ public class UserTest {
|
||||
for (GameMode gm: GameMode.values()) {
|
||||
user.setGameMode(gm);
|
||||
}
|
||||
Mockito.verify(player, Mockito.times(GameMode.values().length)).setGameMode(Mockito.any());
|
||||
verify(player, Mockito.times(GameMode.values().length)).setGameMode(Mockito.any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -360,7 +374,7 @@ public class UserTest {
|
||||
when(player.teleport(Mockito.any(Location.class))).thenReturn(true);
|
||||
Location loc = mock(Location.class);
|
||||
user.teleport(loc);
|
||||
Mockito.verify(player).teleport(loc);
|
||||
verify(player).teleport(loc);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -374,7 +388,7 @@ public class UserTest {
|
||||
@Test
|
||||
public void testCloseInventory() {
|
||||
user.closeInventory();
|
||||
Mockito.verify(player).closeInventory();
|
||||
verify(player).closeInventory();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -406,13 +420,13 @@ public class UserTest {
|
||||
@Test
|
||||
public void testUpdateInventory() {
|
||||
user.updateInventory();
|
||||
Mockito.verify(player).updateInventory();
|
||||
verify(player).updateInventory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerformCommand() {
|
||||
user.performCommand("test");
|
||||
Mockito.verify(player).performCommand("test");
|
||||
verify(player).performCommand("test");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unlikely-arg-type")
|
||||
|
@ -65,11 +65,6 @@ public class FlagAdapterTest {
|
||||
when(plugin.getFlagsManager()).thenReturn(flagsManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlagAdapter() {
|
||||
new FlagTypeAdapter(plugin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteJsonWriterFlag() throws IOException {
|
||||
FlagTypeAdapter fa = new FlagTypeAdapter(plugin);
|
||||
|
@ -1,6 +1,9 @@
|
||||
package world.bentobox.bentobox.database.mysql;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.sql.Connection;
|
||||
@ -44,11 +47,13 @@ import world.bentobox.bentobox.util.Util;
|
||||
@PrepareForTest( { Bukkit.class, BentoBox.class, Util.class })
|
||||
public class MySQLDatabaseHandlerTest {
|
||||
|
||||
private static MySQLDatabaseHandler<Island> handler;
|
||||
private static Island instance;
|
||||
private static String UNIQUE_ID = "xyz";
|
||||
private static MySQLDatabaseConnector dbConn;
|
||||
private static World world;
|
||||
private MySQLDatabaseHandler<Island> handler;
|
||||
private Island instance;
|
||||
private String UNIQUE_ID = "xyz";
|
||||
private MySQLDatabaseConnector dbConn;
|
||||
private World world;
|
||||
@Mock
|
||||
private Location location;
|
||||
@Mock
|
||||
static BentoBox plugin = mock(BentoBox.class);
|
||||
private static IslandWorldManager iwm;
|
||||
@ -78,7 +83,7 @@ public class MySQLDatabaseHandlerTest {
|
||||
when(plugin.getSettings()).thenReturn(settings);
|
||||
|
||||
iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getDeathsMax(Mockito.any())).thenReturn(10);
|
||||
when(iwm.getDeathsMax(any())).thenReturn(10);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
@ -97,34 +102,41 @@ public class MySQLDatabaseHandlerTest {
|
||||
handler = new MySQLDatabaseHandler<>(plugin, Island.class, dbConn);
|
||||
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.sameWorld(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(Util.sameWorld(any(), any())).thenReturn(true);
|
||||
|
||||
// Flags
|
||||
FlagsManager fm = mock(FlagsManager.class);
|
||||
when(plugin.getFlagsManager()).thenReturn(fm);
|
||||
when(fm.getFlags()).thenReturn(new ArrayList<>());
|
||||
|
||||
// Location
|
||||
when(location.getWorld()).thenReturn(world);
|
||||
when(location.getBlockX()).thenReturn(0);
|
||||
when(location.getBlockY()).thenReturn(0);
|
||||
when(location.getBlockZ()).thenReturn(0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveNullObject() {
|
||||
handler.saveObject(null);
|
||||
verify(plugin).logError(eq("MySQL database request to store a null. "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveObject() {
|
||||
handler.saveObject(instance);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveObject2() {
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Settings settings = mock(Settings.class);
|
||||
when(plugin.getSettings()).thenReturn(settings);
|
||||
when(iwm.getDeathsMax(Mockito.any())).thenReturn(10);
|
||||
when(iwm.getDeathsMax(any())).thenReturn(10);
|
||||
Players players = new Players();
|
||||
players.setUniqueId(UUID.randomUUID().toString());
|
||||
players.setDeaths(world, 23);
|
||||
Location location = mock(Location.class);
|
||||
Mockito.when(location.getWorld()).thenReturn(world);
|
||||
Mockito.when(location.getBlockX()).thenReturn(0);
|
||||
Mockito.when(location.getBlockY()).thenReturn(0);
|
||||
Mockito.when(location.getBlockZ()).thenReturn(0);
|
||||
|
||||
players.setHomeLocation(location);
|
||||
players.setHomeLocation(location, 1);
|
||||
@ -140,6 +152,10 @@ public class MySQLDatabaseHandlerTest {
|
||||
MySQLDatabaseHandler<Players> h = new MySQLDatabaseHandler<>(plugin, Players.class, dbConn);
|
||||
h.saveObject(players);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveObject3() {
|
||||
Island island = new Island();
|
||||
island.setUniqueId(UNIQUE_ID);
|
||||
island.setCenter(location);
|
||||
|
Loading…
Reference in New Issue
Block a user