mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-22 02:35:21 +01:00
Fix tests
This commit is contained in:
parent
68f2a0f59f
commit
41a2484c9d
@ -4,10 +4,10 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -25,6 +25,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.junit.After;
|
||||
@ -41,6 +42,7 @@ 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.addons.Addon;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.island.IslandDeletedEvent;
|
||||
@ -80,12 +82,19 @@ public class AdminPurgeCommandTest {
|
||||
private PlayersManager pm;
|
||||
@Mock
|
||||
private @NonNull Location location;
|
||||
@Mock
|
||||
private BukkitScheduler scheduler;
|
||||
|
||||
/**
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
// Mock the method to immediately run the Runnable
|
||||
when(scheduler.runTaskLater(eq(plugin), any(Runnable.class), anyLong())).thenAnswer(invocation -> {
|
||||
Runnable task = invocation.getArgument(1);
|
||||
task.run(); // Immediately run the Runnable
|
||||
return null; // or return a mock of the Task if needed
|
||||
});
|
||||
when(Bukkit.getScheduler()).thenReturn(scheduler);
|
||||
|
||||
// Set up plugin
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
@ -118,6 +127,10 @@ public class AdminPurgeCommandTest {
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
when(pm.getName(any())).thenReturn("name");
|
||||
|
||||
Settings settings = new Settings();
|
||||
// Settings
|
||||
when(plugin.getSettings()).thenReturn(settings);
|
||||
|
||||
// Command
|
||||
apc = new AdminPurgeCommand(ac);
|
||||
}
|
||||
@ -315,7 +328,7 @@ public class AdminPurgeCommandTest {
|
||||
testExecuteUserStringListOfStringIslandsFound();
|
||||
assertTrue(apc.execute(user, "", Collections.singletonList("confirm")));
|
||||
verify(im).deleteIsland(eq(island), eq(true), eq(null));
|
||||
verify(plugin, times(4)).log(any());
|
||||
verify(plugin).log(any());
|
||||
verify(user).sendMessage(eq("commands.admin.purge.see-console-for-status"), eq("[label]"), eq("bsb"));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user