Skip to content

Commit

Permalink
Fix tests to run with latest BentoBox
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jun 1, 2024
1 parent d37f9dd commit 7a241f8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
18 changes: 16 additions & 2 deletions src/test/java/world/bentobox/level/LevelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -19,6 +21,7 @@
import java.util.Comparator;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.logging.Logger;
Expand All @@ -30,7 +33,9 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.eclipse.jdt.annotation.NonNull;
import org.junit.After;
Expand All @@ -47,6 +52,8 @@
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;

import com.github.puregero.multilib.MultiLib;

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.addons.AddonDescription;
Expand All @@ -72,7 +79,7 @@
*/
@SuppressWarnings("deprecation")
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class })
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, MultiLib.class })
public class LevelTest {

private static File jFile;
Expand Down Expand Up @@ -144,8 +151,15 @@ public static void beforeClass() throws IOException {
/**
* @throws java.lang.Exception
*/
@Before
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
// Mock MultiLib
PowerMockito.mockStatic(MultiLib.class);
// Mock the behavior of the onString method
PowerMockito.doNothing().when(MultiLib.class);
MultiLib.onString(any(Plugin.class), anyString(), (Consumer<String>) any(Consumer.class));

// Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
when(plugin.getLogger()).thenReturn(Logger.getAnonymousLogger());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -138,7 +138,7 @@ public void setUp() throws Exception {
when(im.getIsland(any(World.class), any(User.class))).thenReturn(island);
when(im.getIslandAt(any(Location.class))).thenReturn(Optional.of(island));
when(im.getIslandById(anyString())).thenAnswer((Answer<Optional<Island>>) invocation -> Optional.of(islands.get(invocation.getArgument(0, String.class))));
when(im.getIslands(any(), any(UUID.class))).thenReturn(new HashSet<>(islands.values()));
when(im.getIslands(any(), any(UUID.class))).thenReturn(new ArrayList<>(islands.values()));
when(addon.getIslands()).thenReturn(im);

// Levels Manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static org.mockito.Mockito.when;

import java.util.Collections;
import java.util.Set;
import java.util.List;
import java.util.UUID;

import org.bukkit.Bukkit;
Expand Down Expand Up @@ -120,8 +120,8 @@ public void setUp() {
when(island.getOwner()).thenReturn(uuid);
// Island Manager
when(plugin.getIslands()).thenReturn(im);
when(im.getIslands(any(), any(User.class))).thenReturn(Set.of(island));
when(im.getIslands(any(), any(UUID.class))).thenReturn(Set.of(island));
when(im.getIslands(any(), any(User.class))).thenReturn(List.of(island));
when(im.getIslands(any(), any(UUID.class))).thenReturn(List.of(island));

// Bukkit
PowerMockito.mockStatic(Bukkit.class);
Expand Down

0 comments on commit 7a241f8

Please sign in to comment.