Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Oct 26, 2024
1 parent 68f2a0f commit 41a2484
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
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;

Expand All @@ -25,6 +25,7 @@
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;
Expand All @@ -41,6 +42,7 @@
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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -118,6 +127,10 @@ public void setUp() throws Exception {
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);
}
Expand Down Expand Up @@ -315,7 +328,7 @@ public void testRemoveIslands() {
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"));
}

Expand Down

0 comments on commit 41a2484

Please sign in to comment.