diff --git a/src/main/java/world/bentobox/level/LevelsManager.java b/src/main/java/world/bentobox/level/LevelsManager.java
index ac9c46b..d32bced 100644
--- a/src/main/java/world/bentobox/level/LevelsManager.java
+++ b/src/main/java/world/bentobox/level/LevelsManager.java
@@ -57,6 +57,7 @@ public LevelsManager(Level addon) {
// Set up the database handler to store and retrieve data
// Note that these are saved by the BentoBox database
handler = new Database<>(addon, IslandLevels.class);
+
// Initialize the cache
levelsCache = new HashMap<>();
// Initialize top ten lists
@@ -237,7 +238,6 @@ private long getNumBlocks(final long initialLevel) throws ParseException, IOExce
*
* @param world - world where the island is
* @param targetPlayer - target player UUID
- * @param ownerOnly - return level only if the target player is the owner
* @return Level of the player's island or zero if player is unknown or UUID is
* null
*/
@@ -492,7 +492,6 @@ public void setInitialIslandCount(@NonNull Island island, long lv) {
* member
*
* @param world - world
- * @param island - island
* @param lv - level
*/
public void setIslandLevel(@NonNull World world, @NonNull UUID targetPlayer, long lv) {
diff --git a/src/main/java/world/bentobox/level/calculators/Results.java b/src/main/java/world/bentobox/level/calculators/Results.java
index 6dbd2a5..db8124c 100644
--- a/src/main/java/world/bentobox/level/calculators/Results.java
+++ b/src/main/java/world/bentobox/level/calculators/Results.java
@@ -173,7 +173,7 @@ public long getInitialCount() {
}
/**
- * @param long1 the initialCount to set
+ * @param count the initialCount to set
*/
public void setInitialCount(Long count) {
this.initialCount.set(count);
diff --git a/src/main/java/world/bentobox/level/config/BlockConfig.java b/src/main/java/world/bentobox/level/config/BlockConfig.java
index feb7495..1ebfcba 100644
--- a/src/main/java/world/bentobox/level/config/BlockConfig.java
+++ b/src/main/java/world/bentobox/level/config/BlockConfig.java
@@ -240,7 +240,7 @@ public Integer getValue(World world, Object obj) {
/**
* Return true if the block should be hidden
- * @param m block material or entity type of spawner
+ * @param obj object that can be a material or string
* @return true if hidden
*/
public boolean isHiddenBlock(Object obj) {
@@ -254,7 +254,7 @@ public boolean isHiddenBlock(Object obj) {
/**
* Return true if the block should not be hidden
- * @param m block material
+ * @param obj object that can be a material or string
* @return false if hidden
*/
public boolean isNotHiddenBlock(Object obj) {
diff --git a/src/test/java/world/bentobox/level/CommonTestSetup.java b/src/test/java/world/bentobox/level/CommonTestSetup.java
new file mode 100644
index 0000000..876424a
--- /dev/null
+++ b/src/test/java/world/bentobox/level/CommonTestSetup.java
@@ -0,0 +1,336 @@
+package world.bentobox.level;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.block.Block;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.entity.Player.Spigot;
+import org.bukkit.event.entity.EntityExplodeEvent;
+import org.bukkit.event.entity.PlayerDeathEvent;
+import org.bukkit.inventory.ItemFactory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.PlayerInventory;
+import org.bukkit.metadata.FixedMetadataValue;
+import org.bukkit.metadata.MetadataValue;
+import org.bukkit.plugin.PluginManager;
+import org.bukkit.scheduler.BukkitScheduler;
+import org.bukkit.util.Vector;
+import org.eclipse.jdt.annotation.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.mockbukkit.mockbukkit.MockBukkit;
+import org.mockbukkit.mockbukkit.ServerMock;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.stubbing.Answer;
+
+import com.google.common.collect.ImmutableSet;
+
+import net.md_5.bungee.api.chat.TextComponent;
+import world.bentobox.bentobox.BentoBox;
+import world.bentobox.bentobox.Settings;
+import world.bentobox.bentobox.api.addons.GameModeAddon;
+import world.bentobox.bentobox.api.commands.CompositeCommand;
+import world.bentobox.bentobox.api.configuration.WorldSettings;
+import world.bentobox.bentobox.api.user.Notifier;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.bentobox.database.objects.Island;
+import world.bentobox.bentobox.database.objects.Players;
+import world.bentobox.bentobox.managers.BlueprintsManager;
+import world.bentobox.bentobox.managers.FlagsManager;
+import world.bentobox.bentobox.managers.HooksManager;
+import world.bentobox.bentobox.managers.IslandWorldManager;
+import world.bentobox.bentobox.managers.IslandsManager;
+import world.bentobox.bentobox.managers.LocalesManager;
+import world.bentobox.bentobox.managers.PlaceholdersManager;
+import world.bentobox.bentobox.managers.PlayersManager;
+import world.bentobox.bentobox.util.Util;
+
+/**
+ * Common items for testing. Don't forget to use super.setUp()!
+ *
+ * Sets up BentoBox plugin, pluginManager and ItemFactory.
+ * Location, world, playersManager and player.
+ * IWM, Addon and WorldSettings. IslandManager with one
+ * island with protection and nothing allowed by default.
+ * Owner of island is player with same UUID.
+ * Locales, placeholders.
+ * @author tastybento
+ *
+ */
+public abstract class CommonTestSetup {
+
+ protected UUID uuid = UUID.randomUUID();
+
+ @Mock
+ protected GameModeAddon gameModeAddon;
+ @Mock
+ protected Level addon;
+ @Mock
+ protected Player p;
+ @Mock
+ protected PluginManager pim;
+ @Mock
+ protected ItemFactory itemFactory;
+ @Mock
+ protected Location location;
+ @Mock
+ protected World world;
+ @Mock
+ protected IslandWorldManager iwm;
+ @Mock
+ protected IslandsManager im;
+ @Mock
+ protected Island island;
+ @Mock
+ protected BentoBox plugin;
+ @Mock
+ protected PlayerInventory inv;
+ @Mock
+ protected Notifier notifier;
+ @Mock
+ protected FlagsManager fm;
+ @Mock
+ protected Spigot spigot;
+ @Mock
+ protected HooksManager hooksManager;
+ @Mock
+ protected BlueprintsManager bm;
+
+ protected ServerMock server;
+
+ protected MockedStatic mockedBukkit;
+ protected MockedStatic mockedUtil;
+
+ protected AutoCloseable closeable;
+
+ @Mock
+ protected BukkitScheduler sch;
+ @Mock
+ protected LocalesManager lm;
+ @Mock
+ protected CompositeCommand ic;
+
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ MockitoAnnotations.openMocks(this);
+ // Processes the @Mock annotations and initializes the field
+ closeable = MockitoAnnotations.openMocks(this);
+ server = MockBukkit.mock();
+ // Bukkit
+ // Set up plugin
+ WhiteBox.setInternalState(BentoBox.class, "instance", plugin);
+
+ // Register the static mock
+ mockedBukkit = Mockito.mockStatic(Bukkit.class, Mockito.RETURNS_DEEP_STUBS);
+ mockedBukkit.when(Bukkit::getMinecraftVersion).thenReturn("1.21.10");
+ mockedBukkit.when(Bukkit::getBukkitVersion).thenReturn("");
+ mockedBukkit.when(Bukkit::getPluginManager).thenReturn(pim);
+ mockedBukkit.when(Bukkit::getItemFactory).thenReturn(itemFactory);
+ mockedBukkit.when(Bukkit::getServer).thenReturn(server);
+
+ // World
+ when(world.toString()).thenReturn("world");
+ when(world.getName()).thenReturn("BSkyBlock_world");
+
+ // Location
+ when(location.getWorld()).thenReturn(world);
+ when(location.getBlockX()).thenReturn(0);
+ when(location.getBlockY()).thenReturn(0);
+ when(location.getBlockZ()).thenReturn(0);
+ when(location.toVector()).thenReturn(new Vector(0,0,0));
+ when(location.clone()).thenReturn(location); // Paper
+
+ // Players Manager and meta data
+ PlayersManager pm = mock(PlayersManager.class);
+ when(plugin.getPlayers()).thenReturn(pm);
+ Players players = mock(Players.class);
+ when(players.getMetaData()).thenReturn(Optional.empty());
+ when(pm.getPlayer(any(UUID.class))).thenReturn(players);
+
+ // Player
+ when(p.getUniqueId()).thenReturn(uuid);
+ when(p.getLocation()).thenReturn(location);
+ when(p.getWorld()).thenReturn(world);
+ when(p.getName()).thenReturn("tastybento");
+ when(p.getInventory()).thenReturn(inv);
+ when(p.spigot()).thenReturn(spigot);
+ when(p.getType()).thenReturn(EntityType.PLAYER);
+ when(p.getWorld()).thenReturn(world);
+
+ User.setPlugin(plugin);
+ User.clearUsers();
+ User.getInstance(p);
+
+ // IWM
+ when(plugin.getIWM()).thenReturn(iwm);
+ when(iwm.inWorld(any(Location.class))).thenReturn(true);
+ when(iwm.inWorld(any(World.class))).thenReturn(true);
+ when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
+ // Addon
+ when(iwm.getAddon(any())).thenReturn(Optional.empty());
+
+ // World Settings
+ WorldSettings worldSet = new TestWorldSettings();
+ when(iwm.getWorldSettings(any())).thenReturn(worldSet);
+
+ // Island Manager
+ when(plugin.getIslands()).thenReturn(im);
+ Optional optionalIsland = Optional.of(island);
+ when(im.getProtectedIslandAt(any())).thenReturn(optionalIsland);
+
+ // Island - nothing is allowed by default
+ when(island.isAllowed(any())).thenReturn(false);
+ when(island.isAllowed(any(User.class), any())).thenReturn(false);
+ when(island.getOwner()).thenReturn(uuid);
+ when(island.getMemberSet()).thenReturn(ImmutableSet.of(uuid));
+
+ // Enable reporting from Flags class
+ MetadataValue mdv = new FixedMetadataValue(plugin, "_why_debug");
+ when(p.getMetadata(anyString())).thenReturn(Collections.singletonList(mdv));
+
+ // Locales & Placeholders
+ when(lm.get(any(), any())).thenAnswer((Answer) invocation -> invocation.getArgument(1, String.class));
+ PlaceholdersManager phm = mock(PlaceholdersManager.class);
+ when(plugin.getPlaceholdersManager()).thenReturn(phm);
+ when(phm.replacePlaceholders(any(), any())).thenAnswer((Answer) invocation -> invocation.getArgument(1, String.class));
+ when(plugin.getLocalesManager()).thenReturn(lm);
+ // Notifier
+ when(plugin.getNotifier()).thenReturn(notifier);
+
+ // Fake players
+ Settings settings = new Settings();
+ when(plugin.getSettings()).thenReturn(settings);
+
+ //Util
+ mockedUtil = Mockito.mockStatic(Util.class, Mockito.CALLS_REAL_METHODS);
+ mockedUtil.when(() -> Util.getWorld(any())).thenReturn(mock(World.class));
+ Util.setPlugin(plugin);
+
+ // Util
+ mockedUtil.when(() -> Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
+ // Util translate color codes (used in user translate methods)
+ //mockedUtil.when(() -> translateColorCodes(anyString())).thenAnswer((Answer) invocation -> invocation.getArgument(0, String.class));
+
+ // Server & Scheduler
+ mockedBukkit.when(() -> Bukkit.getScheduler()).thenReturn(sch);
+
+ // Hooks
+ when(hooksManager.getHook(anyString())).thenReturn(Optional.empty());
+ when(plugin.getHooks()).thenReturn(hooksManager);
+
+ // Blueprints Manager
+ when(plugin.getBlueprintsManager()).thenReturn(bm);
+
+ // Addon
+ when(addon.getPlugin()).thenReturn(plugin);
+ when(addon.getIslands()).thenReturn(im);
+ when(addon.getIslandsManager()).thenReturn(im);
+
+ // Command
+ when(ic.getAddon()).thenReturn(addon);
+ when(ic.getPermissionPrefix()).thenReturn("bskyblock.");
+ when(ic.getLabel()).thenReturn("island");
+ when(ic.getTopLabel()).thenReturn("island");
+ when(ic.getWorld()).thenReturn(world);
+ when(ic.getTopLabel()).thenReturn("bsb");
+
+ }
+
+ /**
+ * @throws Exception
+ */
+ @AfterEach
+ public void tearDown() throws Exception {
+ // IMPORTANT: Explicitly close the mock to prevent leakage
+ mockedBukkit.closeOnDemand();
+ mockedUtil.closeOnDemand();
+ closeable.close();
+ MockBukkit.unmock();
+ User.clearUsers();
+ Mockito.framework().clearInlineMocks();
+ deleteAll(new File("database"));
+ deleteAll(new File("database_backup"));
+ }
+
+ protected static void deleteAll(File file) throws IOException {
+ if (file.exists()) {
+ Files.walk(file.toPath()).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
+ }
+
+ }
+
+ /**
+ * Check that spigot sent the message
+ * @param message - message to check
+ */
+ public void checkSpigotMessage(String expectedMessage) {
+ checkSpigotMessage(expectedMessage, 1);
+ }
+
+ @SuppressWarnings("deprecation")
+ public void checkSpigotMessage(String expectedMessage, int expectedOccurrences) {
+ // Capture the argument passed to spigot().sendMessage(...) if messages are sent
+ ArgumentCaptor captor = ArgumentCaptor.forClass(TextComponent.class);
+
+ // Verify that sendMessage() was called at least 0 times (capture any sent messages)
+ verify(spigot, atLeast(0)).sendMessage(captor.capture());
+
+ // Get all captured TextComponents
+ List capturedMessages = captor.getAllValues();
+
+ // Count the number of occurrences of the expectedMessage in the captured messages
+ long actualOccurrences = capturedMessages.stream().map(component -> component.toLegacyText()) // Convert each TextComponent to plain text
+ .filter(messageText -> messageText.contains(expectedMessage)) // Check if the message contains the expected text
+ .count(); // Count how many times the expected message appears
+
+ // Assert that the number of occurrences matches the expectedOccurrences
+ assertEquals(expectedOccurrences,
+ actualOccurrences, "Expected message occurrence mismatch: " + expectedMessage);
+ }
+
+ /**
+ * Get the explode event
+ * @param entity
+ * @param l
+ * @param list
+ * @return
+ */
+ public EntityExplodeEvent getExplodeEvent(Entity entity, Location l, List list) {
+ //return new EntityExplodeEvent(entity, l, list, 0, null);
+ return new EntityExplodeEvent(entity, l, list, 0, null);
+ }
+
+ public PlayerDeathEvent getPlayerDeathEvent(Player player, List drops, int droppedExp, int newExp,
+ int newTotalExp, int newLevel, @Nullable String deathMessage) {
+ //Technically this null is not allowed, but it works right now
+ return new PlayerDeathEvent(player, null, drops, droppedExp, newExp,
+ newTotalExp, newLevel, deathMessage);
+ }
+
+}
diff --git a/src/test/java/world/bentobox/level/LevelTest.java b/src/test/java/world/bentobox/level/LevelTest.java
index 2dd0e87..550509a 100644
--- a/src/test/java/world/bentobox/level/LevelTest.java
+++ b/src/test/java/world/bentobox/level/LevelTest.java
@@ -16,8 +16,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
import java.util.Collections;
-import java.util.Comparator;
import java.util.Optional;
import java.util.UUID;
import java.util.jar.JarEntry;
@@ -25,78 +25,50 @@
import java.util.logging.Logger;
import org.bukkit.Bukkit;
-import org.bukkit.Server;
-import org.bukkit.UnsafeValues;
-import org.bukkit.World;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemFactory;
-import org.bukkit.inventory.meta.ItemMeta;
-import org.bukkit.plugin.PluginManager;
-import org.bukkit.scheduler.BukkitScheduler;
import org.eclipse.jdt.annotation.NonNull;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mock;
+import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
-import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.addons.AddonDescription;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
-import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.hooks.ItemsAdderHook;
import world.bentobox.bentobox.managers.AddonsManager;
import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.FlagsManager;
import world.bentobox.bentobox.managers.HooksManager;
-import world.bentobox.bentobox.managers.IslandWorldManager;
-import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlaceholdersManager;
import world.bentobox.bentobox.util.Util;
import world.bentobox.level.config.BlockConfig;
import world.bentobox.level.config.ConfigSettings;
import world.bentobox.level.listeners.IslandActivitiesListeners;
import world.bentobox.level.listeners.JoinLeaveListener;
-import world.bentobox.level.mocks.ServerMocks;
/**
* @author tastybento
*
*/
-@SuppressWarnings("deprecation")
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Util.class, ItemsAdderHook.class })
-public class LevelTest {
+public class LevelTest extends CommonTestSetup {
private static File jFile;
@Mock
private User user;
@Mock
- private IslandsManager im;
- @Mock
- private Island island;
- @Mock
- private BentoBox plugin;
- @Mock
private FlagsManager fm;
@Mock
private GameModeAddon gameMode;
@Mock
private AddonsManager am;
- @Mock
- private BukkitScheduler scheduler;
@Mock
private Settings pluginSettings;
@@ -111,29 +83,25 @@ public class LevelTest {
private CompositeCommand cmd;
@Mock
private CompositeCommand adminCmd;
- @Mock
- private World world;
- private UUID uuid;
- @Mock
- private PluginManager pim;
@Mock
private BlockConfig blockConfig;
@Mock
private HooksManager hm;
+ private MockedStatic itemsAdderMock;
- @BeforeClass
+ @BeforeAll
public static void beforeClass() throws IOException {
// Make the addon jar
jFile = new File("addon.jar");
// Copy over config file from src folder
Path fromPath = Paths.get("src/main/resources/config.yml");
Path path = Paths.get("config.yml");
- Files.copy(fromPath, path);
+ Files.copy(fromPath, path, StandardCopyOption.REPLACE_EXISTING);
// Copy over block config file from src folder
fromPath = Paths.get("src/main/resources/blockconfig.yml");
path = Paths.get("blockconfig.yml");
- Files.copy(fromPath, path);
+ Files.copy(fromPath, path, StandardCopyOption.REPLACE_EXISTING);
try (JarOutputStream tempJarOutputStream = new JarOutputStream(new FileOutputStream(jFile))) {
// Added the new files to the jar.
try (FileInputStream fis = new FileInputStream(path.toFile())) {
@@ -151,29 +119,25 @@ public static void beforeClass() throws IOException {
/**
* @throws java.lang.Exception
*/
- @Before
+ @Override
+ @BeforeEach
public void setUp() throws Exception {
+ super.setUp();
when(plugin.getHooks()).thenReturn(hm);
- Server server = ServerMocks.newServer();
- // Set up plugin
- Whitebox.setInternalState(BentoBox.class, "instance", plugin);
- when(plugin.getLogger()).thenReturn(Logger.getAnonymousLogger());
-
// The database type has to be created one line before the thenReturn() to work!
DatabaseType value = DatabaseType.JSON;
when(plugin.getSettings()).thenReturn(pluginSettings);
when(pluginSettings.getDatabaseType()).thenReturn(value);
// ItemsAdderHook
- PowerMockito.mockStatic(ItemsAdderHook.class, Mockito.RETURNS_MOCKS);
- when(ItemsAdderHook.isInRegistry(anyString())).thenReturn(true);
+ itemsAdderMock = Mockito.mockStatic(ItemsAdderHook.class, Mockito.RETURNS_MOCKS);
+ itemsAdderMock.when(() -> ItemsAdderHook.isInRegistry(anyString())).thenReturn(true);
// Command manager
CommandsManager cm = mock(CommandsManager.class);
when(plugin.getCommandsManager()).thenReturn(cm);
// Player
- Player p = mock(Player.class);
// Sometimes use Mockito.withSettings().verboseLogging()
when(user.isOp()).thenReturn(false);
uuid = UUID.randomUUID();
@@ -182,29 +146,17 @@ public void setUp() throws Exception {
when(user.getName()).thenReturn("tastybento");
User.setPlugin(plugin);
- // Island World Manager
- IslandWorldManager iwm = mock(IslandWorldManager.class);
- when(plugin.getIWM()).thenReturn(iwm);
-
// Player has island to begin with
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
- when(plugin.getIslands()).thenReturn(im);
// Locales
// Return the reference (USE THIS IN THE FUTURE)
when(user.getTranslation(Mockito.anyString()))
.thenAnswer((Answer) invocation -> invocation.getArgument(0, String.class));
- // Server
- PowerMockito.mockStatic(Bukkit.class);
- when(Bukkit.getServer()).thenReturn(server);
- when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
- when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class));
- when(Bukkit.getBukkitVersion()).thenReturn("");
// Util
- PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
- when(Util.inTest()).thenReturn(true);
+ mockedUtil.when(() -> Util.inTest()).thenReturn(true);
// Addon
addon = new Level();
@@ -236,37 +188,22 @@ public void setUp() throws Exception {
when(plugin.getFlagsManager()).thenReturn(fm);
when(fm.getFlags()).thenReturn(Collections.emptyList());
- // Bukkit
- when(Bukkit.getScheduler()).thenReturn(scheduler);
- ItemMeta meta = mock(ItemMeta.class);
- ItemFactory itemFactory = mock(ItemFactory.class);
- when(itemFactory.getItemMeta(any())).thenReturn(meta);
- when(Bukkit.getItemFactory()).thenReturn(itemFactory);
- UnsafeValues unsafe = mock(UnsafeValues.class);
- when(unsafe.getDataVersion()).thenReturn(777);
- when(Bukkit.getUnsafe()).thenReturn(unsafe);
- when(Bukkit.getPluginManager()).thenReturn(pim);
-
// placeholders
when(plugin.getPlaceholdersManager()).thenReturn(phm);
- // World
- when(world.getName()).thenReturn("bskyblock-world");
- // Island
- when(island.getWorld()).thenReturn(world);
- when(island.getOwner()).thenReturn(uuid);
}
/**
* @throws java.lang.Exception
*/
- @After
+ @Override
+ @AfterEach
public void tearDown() throws Exception {
- ServerMocks.unsetBukkitServer();
+ super.tearDown();
deleteAll(new File("database"));
}
- @AfterClass
+ @AfterAll
public static void cleanUp() throws Exception {
new File("addon.jar").delete();
new File("config.yml").delete();
@@ -274,17 +211,12 @@ public static void cleanUp() throws Exception {
deleteAll(new File("addons"));
}
- private static void deleteAll(File file) throws IOException {
- if (file.exists()) {
- Files.walk(file.toPath()).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
- }
- }
-
/**
* Test method for {@link world.bentobox.level.Level#allLoaded()
*/
@Test
public void testAllLoaded() {
+ mockedBukkit.when(() -> Bukkit.getWorld("acidisland_world")).thenReturn(null);
addon.allLoaded();
verify(plugin).log("[Level] Level hooking into BSkyBlock");
verify(cmd, times(4)).getAddon(); // 4 commands
diff --git a/src/test/java/world/bentobox/level/LevelsManagerTest.java b/src/test/java/world/bentobox/level/LevelsManagerTest.java
index a790604..ab96e75 100644
--- a/src/test/java/world/bentobox/level/LevelsManagerTest.java
+++ b/src/test/java/world/bentobox/level/LevelsManagerTest.java
@@ -12,11 +12,7 @@
import static org.mockito.Mockito.when;
import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
import java.util.ArrayList;
-import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -27,36 +23,24 @@
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
-import org.bukkit.inventory.ItemFactory;
-import org.bukkit.inventory.meta.ItemMeta;
-import org.bukkit.plugin.PluginManager;
-import org.bukkit.scheduler.BukkitScheduler;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
+import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
import com.google.common.collect.ImmutableSet;
-import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
-import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.DatabaseSetup;
import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.IslandWorldManager;
-import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.level.calculators.Pipeliner;
import world.bentobox.level.calculators.Results;
@@ -68,29 +52,18 @@
* @author tastybento
*
*/
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ Bukkit.class, BentoBox.class, DatabaseSetup.class, PanelBuilder.class })
-public class LevelsManagerTest {
+public class LevelsManagerTest extends CommonTestSetup {
@Mock
- private static AbstractDatabaseHandler