Fixed code smells in tests (SonarCloud)

This commit is contained in:
Florian CUNY 2021-01-16 14:27:01 +01:00
parent 936f2747c9
commit c60833a054
20 changed files with 91 additions and 91 deletions

View File

@ -220,7 +220,7 @@ public class AdminResetFlagsCommandTest {
public void testTabCompleteUserStringListOfString() { public void testTabCompleteUserStringListOfString() {
Optional<List<String>> list = arf.tabComplete(user, "", Collections.emptyList()); Optional<List<String>> list = arf.tabComplete(user, "", Collections.emptyList());
assertTrue(list.isPresent()); assertTrue(list.isPresent());
assertTrue(list.get().size() == 2); assertEquals(2, list.get().size());
assertTrue(list.get().contains("FLAG1")); assertTrue(list.get().contains("FLAG1"));
assertTrue(list.get().contains("FLAG2")); assertTrue(list.get().contains("FLAG2"));
assertFalse(list.get().contains("FLAG3")); assertFalse(list.get().contains("FLAG3"));

View File

@ -234,7 +234,7 @@ public class AdminSetrankCommandTest {
Optional<List<String>> result = c.tabComplete(user, "", Arrays.asList("setrank", "")); Optional<List<String>> result = c.tabComplete(user, "", Arrays.asList("setrank", ""));
assertTrue(result.isPresent()); assertTrue(result.isPresent());
result.ifPresent(list -> { result.ifPresent(list -> {
assertTrue(list.size() == 1); assertEquals(1, list.size());
assertEquals("tastybento", list.get(0)); assertEquals("tastybento", list.get(0));
}); });
} }

View File

@ -224,9 +224,9 @@ public class IslandTeamCommandTest {
tc.addInvite(Invite.Type.TEAM, uuid, invitee); tc.addInvite(Invite.Type.TEAM, uuid, invitee);
@Nullable @Nullable
Invite invite = tc.getInvite(invitee); Invite invite = tc.getInvite(invitee);
assertEquals(invite.getInvitee(), invitee); assertEquals(invitee, invite.getInvitee());
assertEquals(invite.getType(), Type.TEAM); assertEquals(Type.TEAM, invite.getType());
assertEquals(invite.getInviter(), uuid); assertEquals(uuid, invite.getInviter());
} }
/** /**

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.api.flags;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -121,7 +122,7 @@ public class FlagTest {
} }
/** /**
* Test method for {@link world.bentobox.bentobox.api.flags.Flag#Flag(java.lang.String, org.bukkit.Material, org.bukkit.event.Listener, world.bentobox.bentobox.api.flags.Flag.Type, int, world.bentobox.bentobox.api.panels.PanelItem.ClickHandler, boolean, world.bentobox.bentobox.api.addons.GameModeAddon)}. * Test method for .
*/ */
@Test @Test
public void testFlag() { public void testFlag() {
@ -261,15 +262,15 @@ public class FlagTest {
public void testEqualsObject() { public void testEqualsObject() {
Flag flag1 = null; Flag flag1 = null;
assertFalse(f.equals(null)); assertNotEquals(null, f);
int i = 45; int i = 45;
assertFalse(f.equals(i)); assertNotEquals(f, i);
assertTrue(f.equals(f)); assertEquals(f, f);
Flag f2 = new Flag.Builder("flagID2", Material.ACACIA_PLANKS).type(Flag.Type.WORLD_SETTING).usePanel(true).build(); Flag f2 = new Flag.Builder("flagID2", Material.ACACIA_PLANKS).type(Flag.Type.WORLD_SETTING).usePanel(true).build();
assertFalse(f.equals(f2)); assertNotEquals(f, f2);
assertFalse(f2.equals(flag1)); assertNotEquals(f2, flag1);
} }
/** /**
@ -339,7 +340,7 @@ public class FlagTest {
} }
/** /**
* Test method for {@link world.bentobox.bentobox.api.flags.Flag#toPanelItem(world.bentobox.bentobox.BentoBox, world.bentobox.bentobox.api.user.User)}. * Test method for {@link world.bentobox.bentobox.api.flags.Flag#toPanelItem(BentoBox, User, Island, boolean)}.
*/ */
@Test @Test
public void testToPanelItem() { public void testToPanelItem() {
@ -379,7 +380,6 @@ public class FlagTest {
verify(user).getTranslation(Mockito.eq("protection.panel.flag-item.name-layout"), any()); verify(user).getTranslation(Mockito.eq("protection.panel.flag-item.name-layout"), any());
assertEquals(Material.ACACIA_PLANKS, pi.getItem().getType()); assertEquals(Material.ACACIA_PLANKS, pi.getItem().getType());
} }
/** /**
@ -398,8 +398,6 @@ public class FlagTest {
Flag aaa = new Flag.Builder("AAA", Material.ACACIA_DOOR).type(Flag.Type.PROTECTION).build(); Flag aaa = new Flag.Builder("AAA", Material.ACACIA_DOOR).type(Flag.Type.PROTECTION).build();
Flag bbb = new Flag.Builder("BBB", Material.ACACIA_DOOR).type(Flag.Type.PROTECTION).build(); Flag bbb = new Flag.Builder("BBB", Material.ACACIA_DOOR).type(Flag.Type.PROTECTION).build();
assertTrue(aaa.compareTo(bbb) < bbb.compareTo(aaa)); assertTrue(aaa.compareTo(bbb) < bbb.compareTo(aaa));
assertTrue(aaa.compareTo(aaa) == 0); assertEquals(0, aaa.compareTo(aaa));
} }
} }

View File

@ -12,14 +12,14 @@ public class TextVariablesTest {
@Test @Test
public void test() { public void test() {
assertEquals(TextVariables.NAME, "[name]"); assertEquals("[name]", TextVariables.NAME);
assertEquals(TextVariables.DESCRIPTION, "[description]"); assertEquals("[description]", TextVariables.DESCRIPTION);
assertEquals(TextVariables.NUMBER, "[number]"); assertEquals("[number]", TextVariables.NUMBER);
assertEquals(TextVariables.RANK, "[rank]"); assertEquals("[rank]", TextVariables.RANK);
assertEquals(TextVariables.LABEL, "[label]"); assertEquals("[label]", TextVariables.LABEL);
assertEquals(TextVariables.PERMISSION, "[permission]"); assertEquals("[permission]", TextVariables.PERMISSION);
assertEquals(TextVariables.SPAWN_HERE, "[spawn_here]"); assertEquals("[spawn_here]", TextVariables.SPAWN_HERE);
assertEquals(TextVariables.VERSION, "[version]"); assertEquals("[version]", TextVariables.VERSION);
assertEquals(TextVariables.START_TEXT, "[start]"); assertEquals("[start]", TextVariables.START_TEXT);
} }
} }

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.api.user;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -456,15 +457,15 @@ public class UserTest {
public void testEqualsObject() { public void testEqualsObject() {
User user1 = User.getInstance(UUID.randomUUID()); User user1 = User.getInstance(UUID.randomUUID());
User user2 = User.getInstance(UUID.randomUUID()); User user2 = User.getInstance(UUID.randomUUID());
assertTrue(user1.equals(user1)); assertEquals(user1, user1);
assertFalse(user1.equals(user2)); assertNotEquals(user1, user2);
assertFalse(user1.equals(null)); assertNotEquals(null, user1);
assertFalse(user2.equals(user1)); assertNotEquals(user2, user1);
assertFalse(user2.equals(null)); assertNotEquals(null, user2);
assertFalse(user2.equals("a string")); assertNotEquals("a string", user2);
user1 = User.getInstance((UUID)null); user1 = User.getInstance((UUID)null);
assertFalse(user2.equals(user1)); assertNotEquals(user2, user1);
} }
@Test @Test

View File

@ -114,21 +114,21 @@ public class PlayersTest {
@Test @Test
public void testDeaths() { public void testDeaths() {
assertTrue(p.getDeaths(world) == 0); assertEquals(0, p.getDeaths(world));
p.addDeath(world); p.addDeath(world);
assertTrue(p.getDeaths(world) == 1); assertEquals(1, p.getDeaths(world));
p.addDeath(world); p.addDeath(world);
assertTrue(p.getDeaths(world) == 2); assertEquals(2, p.getDeaths(world));
p.addDeath(world); p.addDeath(world);
assertTrue(p.getDeaths(world) == 3); assertEquals(3, p.getDeaths(world));
p.addDeath(world); p.addDeath(world);
assertTrue(p.getDeaths(world) == 3); assertEquals(3, p.getDeaths(world));
p.addDeath(world); p.addDeath(world);
assertTrue(p.getDeaths(world) == 3); assertEquals(3, p.getDeaths(world));
p.setDeaths(world, 10); p.setDeaths(world, 10);
assertTrue(p.getDeaths(world) == 3); assertEquals(3, p.getDeaths(world));
p.setDeaths(world, 0); p.setDeaths(world, 0);
assertTrue(p.getDeaths(world) == 0); assertEquals(0, p.getDeaths(world));
} }
/** /**

View File

@ -63,7 +63,7 @@ public class LogEntryListAdapterTest {
config.set("test.history", a.serialize(history)); config.set("test.history", a.serialize(history));
// Verify // Verify
List<LogEntry> historyCheck = a.deserialize(config.get("test.history")); List<LogEntry> historyCheck = a.deserialize(config.get("test.history"));
assertTrue(historyCheck.size() == 3); assertEquals(3, historyCheck.size());
for (int i = 0; i < historyCheck.size(); i++) { for (int i = 0; i < historyCheck.size(); i++) {
assertEquals(toLog.get(i).getTimestamp(), historyCheck.get(i).getTimestamp()); assertEquals(toLog.get(i).getTimestamp(), historyCheck.get(i).getTimestamp());
assertEquals(toLog.get(i).getType(), historyCheck.get(i).getType()); assertEquals(toLog.get(i).getType(), historyCheck.get(i).getType());

View File

@ -148,7 +148,7 @@ public class MySQLDatabaseHandlerTest {
when(ps.executeQuery(Mockito.anyString())).thenReturn(resultSet); when(ps.executeQuery(Mockito.anyString())).thenReturn(resultSet);
List<Island> objects = handler.loadObjects(); List<Island> objects = handler.loadObjects();
verify(ps).executeQuery("SELECT `json` FROM `Islands`"); verify(ps).executeQuery("SELECT `json` FROM `Islands`");
assertTrue(objects.size() == 3); assertEquals(3, objects.size());
assertEquals("xyz", objects.get(2).getUniqueId()); assertEquals("xyz", objects.get(2).getUniqueId());
} }
@ -167,7 +167,7 @@ public class MySQLDatabaseHandlerTest {
when(ps.executeQuery(Mockito.anyString())).thenReturn(resultSet); when(ps.executeQuery(Mockito.anyString())).thenReturn(resultSet);
List<Island> objects = handler.loadObjects(); List<Island> objects = handler.loadObjects();
verify(ps).executeQuery("SELECT `json` FROM `aIslands`"); verify(ps).executeQuery("SELECT `json` FROM `aIslands`");
assertTrue(objects.size() == 3); assertEquals(3, objects.size());
assertEquals("xyz", objects.get(2).getUniqueId()); assertEquals("xyz", objects.get(2).getUniqueId());
} }

View File

@ -286,7 +286,7 @@ public class PanelListenerManagerTest {
// No panels for this player // No panels for this player
InventoryCloseEvent event = new InventoryCloseEvent(view); InventoryCloseEvent event = new InventoryCloseEvent(view);
plm.onInventoryClose(event); plm.onInventoryClose(event);
assertTrue(PanelListenerManager.getOpenPanels().size() == 1); assertEquals(1, PanelListenerManager.getOpenPanels().size());
} }
/** /**

View File

@ -1,8 +1,7 @@
package world.bentobox.bentobox.listeners.flags.protection; package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
@ -257,7 +256,7 @@ public class BlockInteractionListenerTest {
when(clickedBlock.getType()).thenReturn(Material.ITEM_FRAME); when(clickedBlock.getType()).thenReturn(Material.ITEM_FRAME);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand); PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e); bil.onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Event.Result.DENY)); assertEquals(Event.Result.DENY, e.useInteractedBlock());
verify(notifier).notify(any(), eq("protection.protected")); verify(notifier).notify(any(), eq("protection.protected"));
} }
@ -271,7 +270,7 @@ public class BlockInteractionListenerTest {
when(clickedBlock.getType()).thenReturn(Material.ITEM_FRAME); when(clickedBlock.getType()).thenReturn(Material.ITEM_FRAME);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand); PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e); bil.onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Event.Result.DENY)); assertEquals(Event.Result.DENY, e.useInteractedBlock());
verify(notifier).notify(any(), eq("protection.protected")); verify(notifier).notify(any(), eq("protection.protected"));
} }
@ -284,7 +283,7 @@ public class BlockInteractionListenerTest {
when(clickedBlock.getType()).thenReturn(bm); when(clickedBlock.getType()).thenReturn(bm);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand); PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e); bil.onPlayerInteract(e);
assertTrue("Failure " + bm, e.useInteractedBlock().equals(Event.Result.DENY)); assertEquals("Failure " + bm, Event.Result.DENY, e.useInteractedBlock());
}); });
verify(notifier, times((int)Arrays.stream(Material.values()).filter(m -> m.name().startsWith("POTTED")).count())).notify(any(), eq("protection.protected")); verify(notifier, times((int)Arrays.stream(Material.values()).filter(m -> m.name().startsWith("POTTED")).count())).notify(any(), eq("protection.protected"));
} }
@ -327,7 +326,7 @@ public class BlockInteractionListenerTest {
when(clickedBlock.getType()).thenReturn(bm); when(clickedBlock.getType()).thenReturn(bm);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand); PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e); bil.onPlayerInteract(e);
assertFalse("Failure " + bm, e.useInteractedBlock().equals(Event.Result.DENY)); assertNotEquals("Failure " + bm, Event.Result.DENY, e.useInteractedBlock());
verify(notifier, never()).notify(any(), eq("protection.protected")); verify(notifier, never()).notify(any(), eq("protection.protected"));
verify(notifier, never()).notify(any(), eq("protection.world-protected")); verify(notifier, never()).notify(any(), eq("protection.world-protected"));
} }
@ -342,8 +341,8 @@ public class BlockInteractionListenerTest {
when(item.getType()).thenReturn(Material.BLAZE_SPAWN_EGG); when(item.getType()).thenReturn(Material.BLAZE_SPAWN_EGG);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand); PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e); bil.onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Event.Result.DENY)); assertEquals(Event.Result.DENY, e.useInteractedBlock());
assertTrue(e.useItemInHand().equals(Event.Result.DENY)); assertEquals(Event.Result.DENY, e.useItemInHand());
verify(notifier).notify(any(), eq("protection.protected")); verify(notifier).notify(any(), eq("protection.protected"));
} }
@ -357,8 +356,8 @@ public class BlockInteractionListenerTest {
when(item.getType()).thenReturn(Material.BLAZE_SPAWN_EGG); when(item.getType()).thenReturn(Material.BLAZE_SPAWN_EGG);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand); PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e); bil.onPlayerInteract(e);
assertFalse(e.useInteractedBlock().equals(Event.Result.DENY)); assertEquals(Event.Result.DENY, e.useInteractedBlock());
assertFalse(e.useItemInHand().equals(Event.Result.DENY)); assertEquals(Event.Result.DENY, e.useItemInHand());
verify(notifier, never()).notify(any(), eq("protection.protected")); verify(notifier, never()).notify(any(), eq("protection.protected"));
} }
@ -373,8 +372,8 @@ public class BlockInteractionListenerTest {
when(item.getType()).thenReturn(Material.BLAZE_SPAWN_EGG); when(item.getType()).thenReturn(Material.BLAZE_SPAWN_EGG);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand); PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e); bil.onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Event.Result.DENY)); assertEquals(Event.Result.DENY, e.useInteractedBlock());
assertTrue(e.useItemInHand().equals(Event.Result.DENY)); assertEquals(Event.Result.DENY, e.useItemInHand());
verify(notifier, times(2)).notify(any(), eq("protection.protected")); verify(notifier, times(2)).notify(any(), eq("protection.protected"));
} }

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.listeners.flags.protection; package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -331,7 +332,7 @@ public class BreakBlocksListenerTest {
when(block.getLocation()).thenReturn(location); when(block.getLocation()).thenReturn(location);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.LEFT_CLICK_AIR, item, block, BlockFace.EAST); PlayerInteractEvent e = new PlayerInteractEvent(player, Action.LEFT_CLICK_AIR, item, block, BlockFace.EAST);
bbl.onPlayerInteract(e); bbl.onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.ALLOW)); assertEquals(e.useInteractedBlock(), Result.ALLOW);
} }
/** /**
@ -345,7 +346,7 @@ public class BreakBlocksListenerTest {
when(block.getType()).thenReturn(Material.STONE); when(block.getType()).thenReturn(Material.STONE);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST); PlayerInteractEvent e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
bbl.onPlayerInteract(e); bbl.onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.ALLOW)); assertEquals(Result.ALLOW, e.useInteractedBlock());
} }
/** /**
@ -383,15 +384,15 @@ public class BreakBlocksListenerTest {
when(block.getType()).thenReturn(Material.CAKE); when(block.getType()).thenReturn(Material.CAKE);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST); PlayerInteractEvent e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
bbl.onPlayerInteract(e); bbl.onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.DENY)); assertEquals(Result.DENY, e.useInteractedBlock());
when(block.getType()).thenReturn(Material.SPAWNER); when(block.getType()).thenReturn(Material.SPAWNER);
e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST); e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
bbl.onPlayerInteract(e); bbl.onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.DENY)); assertEquals(Result.DENY, e.useInteractedBlock());
when(block.getType()).thenReturn(Material.DRAGON_EGG); when(block.getType()).thenReturn(Material.DRAGON_EGG);
e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST); e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
bbl.onPlayerInteract(e); bbl.onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.DENY)); assertEquals(Result.DENY, e.useInteractedBlock());
verify(notifier, times(3)).notify(any(), eq("protection.protected")); verify(notifier, times(3)).notify(any(), eq("protection.protected"));
} }

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.listeners.flags.protection; package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -376,7 +377,7 @@ public class PlaceBlocksListenerTest {
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.UP, EquipmentSlot.HAND); PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.UP, EquipmentSlot.HAND);
pbl.onPlayerInteract(e); pbl.onPlayerInteract(e);
assertTrue("Failed on " + item.getType().toString(), e.useInteractedBlock().equals(Result.ALLOW)); assertEquals("Failed on " + item.getType().toString(), Result.ALLOW, e.useInteractedBlock());
} }
} }
@ -394,7 +395,7 @@ public class PlaceBlocksListenerTest {
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.UP, EquipmentSlot.HAND); PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.UP, EquipmentSlot.HAND);
pbl.onPlayerInteract(e); pbl.onPlayerInteract(e);
assertTrue("Failed on " + item.getType().toString(), e.useInteractedBlock().equals(Result.DENY)); assertEquals("Failed on " + item.getType().toString(), Result.DENY, e.useInteractedBlock());
} }
verify(notifier, times(7)).notify(any(), eq("protection.protected")); verify(notifier, times(7)).notify(any(), eq("protection.protected"));
} }

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.listeners.flags.protection; package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -210,7 +211,7 @@ public class TNTListenerTest {
PlayerInteractEvent e = new PlayerInteractEvent(player , action, item, clickedBlock, clickedFace); PlayerInteractEvent e = new PlayerInteractEvent(player , action, item, clickedBlock, clickedFace);
listener.onTNTPriming(e); listener.onTNTPriming(e);
assertTrue(e.useInteractedBlock().equals(Result.DENY)); assertEquals(Result.DENY, e.useInteractedBlock());
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq("protection.protected")); Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq("protection.protected"));
} }
@ -441,7 +442,6 @@ public class TNTListenerTest {
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, 20D); EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, 20D);
listener.onExplosion(e); listener.onExplosion(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
} }
} }

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.listeners.flags.worldsettings; package world.bentobox.bentobox.listeners.flags.worldsettings;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -172,7 +173,7 @@ public class EnderChestListenerTest {
BlockFace clickedBlockFace = BlockFace.EAST; BlockFace clickedBlockFace = BlockFace.EAST;
PlayerInteractEvent e = new PlayerInteractEvent(player, action, item, clickedBlock, clickedBlockFace); PlayerInteractEvent e = new PlayerInteractEvent(player, action, item, clickedBlock, clickedBlockFace);
new BlockInteractionListener().onPlayerInteract(e); new BlockInteractionListener().onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.ALLOW)); assertEquals(Result.ALLOW, e.useInteractedBlock());
} }
@Test @Test
@ -183,7 +184,7 @@ public class EnderChestListenerTest {
when(iwm.inWorld(any(World.class))).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false); when(iwm.inWorld(any(Location.class))).thenReturn(false);
new BlockInteractionListener().onPlayerInteract(e); new BlockInteractionListener().onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.ALLOW)); assertEquals(Result.ALLOW, e.useInteractedBlock());
} }
@Test @Test
@ -193,7 +194,7 @@ public class EnderChestListenerTest {
// Op player // Op player
when(player.isOp()).thenReturn(true); when(player.isOp()).thenReturn(true);
new BlockInteractionListener().onPlayerInteract(e); new BlockInteractionListener().onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.ALLOW)); assertEquals(Result.ALLOW, e.useInteractedBlock());
} }
@Test @Test
@ -203,7 +204,7 @@ public class EnderChestListenerTest {
// Has bypass perm // Has bypass perm
when(player.hasPermission(anyString())).thenReturn(true); when(player.hasPermission(anyString())).thenReturn(true);
new BlockInteractionListener().onPlayerInteract(e); new BlockInteractionListener().onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.ALLOW)); assertEquals(Result.ALLOW, e.useInteractedBlock());
} }
@Test @Test
@ -214,7 +215,7 @@ public class EnderChestListenerTest {
Flags.ENDER_CHEST.setSetting(world, true); Flags.ENDER_CHEST.setSetting(world, true);
BlockInteractionListener bil = new BlockInteractionListener(); BlockInteractionListener bil = new BlockInteractionListener();
bil.onPlayerInteract(e); bil.onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.ALLOW)); assertEquals(Result.ALLOW, e.useInteractedBlock());
verify(notifier, Mockito.never()).notify(any(), anyString()); verify(notifier, Mockito.never()).notify(any(), anyString());
} }
@ -225,7 +226,7 @@ public class EnderChestListenerTest {
// Enderchest use is blocked // Enderchest use is blocked
Flags.ENDER_CHEST.setSetting(world, false); Flags.ENDER_CHEST.setSetting(world, false);
new BlockInteractionListener().onPlayerInteract(e); new BlockInteractionListener().onPlayerInteract(e);
assertTrue(e.useInteractedBlock().equals(Result.DENY)); assertEquals(Result.DENY, e.useInteractedBlock());
verify(notifier).notify(any(User.class), eq("protection.world-protected")); verify(notifier).notify(any(User.class), eq("protection.world-protected"));
} }

View File

@ -248,7 +248,7 @@ public class AddonsManagerTest {
public void testGetDataObjects() { public void testGetDataObjects() {
am.setClass("dataobj", DataObject.class); am.setClass("dataobj", DataObject.class);
assertFalse(am.getDataObjects().isEmpty()); assertFalse(am.getDataObjects().isEmpty());
assertTrue(am.getDataObjects().size() == 1); assertEquals(1, am.getDataObjects().size());
} }
/** /**

View File

@ -200,7 +200,7 @@ public class BlueprintsManagerTest {
BlueprintsManager bpm = new BlueprintsManager(plugin); BlueprintsManager bpm = new BlueprintsManager(plugin);
bpm.extractDefaultBlueprints(addon); bpm.extractDefaultBlueprints(addon);
// Nothing should happen // Nothing should happen
assertTrue(bpFile.listFiles().length == 0); assertEquals(0, bpFile.listFiles().length);
// Clean up // Clean up
Files.deleteIfExists(bpFile.toPath()); Files.deleteIfExists(bpFile.toPath());
} }
@ -333,7 +333,7 @@ public class BlueprintsManagerTest {
verify(plugin).log(eq("Added blueprint 'bedrock' for name")); verify(plugin).log(eq("Added blueprint 'bedrock' for name"));
// Add it again, it should replace the previous one // Add it again, it should replace the previous one
bpm.addBlueprint(addon, defaultBp); bpm.addBlueprint(addon, defaultBp);
assertTrue(bpm.getBlueprints(addon).size() == 1); assertEquals(1, bpm.getBlueprints(addon).size());
} }
/** /**
@ -376,7 +376,6 @@ public class BlueprintsManagerTest {
BlueprintsManager bpm = new BlueprintsManager(plugin); BlueprintsManager bpm = new BlueprintsManager(plugin);
bpm.saveBlueprintBundle(addon, bb); bpm.saveBlueprintBundle(addon, bb);
} }
/** /**

View File

@ -587,9 +587,9 @@ public class IslandsManagerTest {
@Test @Test
public void testGetCount() { public void testGetCount() {
IslandsManager im = new IslandsManager(plugin); IslandsManager im = new IslandsManager(plugin);
assertTrue(im.getIslandCount() == 0); assertEquals(0, im.getIslandCount());
im.createIsland(location, UUID.randomUUID()); im.createIsland(location, UUID.randomUUID());
assertTrue(im.getIslandCount() == 1); assertEquals(1, im.getIslandCount());
} }
/** /**

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.util;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.junit.Before; import org.junit.Before;
@ -17,7 +18,7 @@ public class PairTest {
public final void testHashCode() { public final void testHashCode() {
Pair<Integer, Integer> pair = new Pair<>(1,2); Pair<Integer, Integer> pair = new Pair<>(1,2);
Pair<Integer, Integer> pair2 = new Pair<>(1,2); Pair<Integer, Integer> pair2 = new Pair<>(1,2);
assertTrue(pair.hashCode() == pair2.hashCode()); assertEquals(pair.hashCode(), pair2.hashCode());
} }
@Test @Test
@ -40,12 +41,11 @@ public class PairTest {
Pair<Integer, Integer> pair3 = new Pair<>(1,2); Pair<Integer, Integer> pair3 = new Pair<>(1,2);
Pair<Integer, Integer> pair4 = new Pair<>(1,null); Pair<Integer, Integer> pair4 = new Pair<>(1,null);
Pair<Integer, Integer> pair5 = new Pair<>(null,2); Pair<Integer, Integer> pair5 = new Pair<>(null,2);
assertTrue(pair.equals(pair)); assertEquals(pair, pair);
assertTrue(pair.equals(pair3) && pair3.equals(pair)); assertTrue(pair.equals(pair3) && pair3.equals(pair));
assertFalse(pair.equals(pair2)); assertNotEquals(pair, pair2);
assertFalse(pair.equals(pair4)); assertNotEquals(pair, pair4);
assertFalse(pair.equals(pair5)); assertNotEquals(pair, pair5);
} }
} }

View File

@ -99,12 +99,12 @@ public class UtilTest {
Map<UUID, String> online = new HashMap<>(); Map<UUID, String> online = new HashMap<>();
Set<Player> onlinePlayers = new HashSet<>(); Set<Player> onlinePlayers = new HashSet<>();
for (int j = 0; j < NAMES.length; j++) { for (String name : NAMES) {
Player p1 = mock(Player.class); Player p1 = mock(Player.class);
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
when(p1.getUniqueId()).thenReturn(uuid); when(p1.getUniqueId()).thenReturn(uuid);
when(p1.getName()).thenReturn(NAMES[j]); when(p1.getName()).thenReturn(name);
online.put(uuid, NAMES[j]); online.put(uuid, name);
onlinePlayers.add(p1); onlinePlayers.add(p1);
} }
when(Bukkit.getOnlinePlayers()).then((Answer<Set<Player>>) invocation -> onlinePlayers); when(Bukkit.getOnlinePlayers()).then((Answer<Set<Player>>) invocation -> onlinePlayers);
@ -153,11 +153,11 @@ public class UtilTest {
assertNull(Util.getLocationString(" ")); assertNull(Util.getLocationString(" "));
Location result = Util.getLocationString("world_name:500:600:700.0:1092616192:1101004800"); Location result = Util.getLocationString("world_name:500:600:700.0:1092616192:1101004800");
assertEquals(world, result.getWorld()); assertEquals(world, result.getWorld());
assertTrue(result.getX() == 500.5D); assertEquals(500.5D, result.getX(), 0.0);
assertTrue(result.getY() == 600D); assertEquals(600D, result.getY(), 0.0);
assertTrue(result.getZ() == 700.5D); assertEquals(700.5D, result.getZ(), 0.0);
assertTrue(result.getYaw() == 10F); assertEquals(10F, result.getYaw(), 0.0);
assertTrue(result.getPitch() == 20F); assertEquals(20F, result.getPitch(), 0.0);
} }
/** /**