Added test class for IslandChunkDeletionManager

This commit is contained in:
tastybento 2023-02-08 20:23:19 -08:00
parent a793a33758
commit 6c1bcdec05
2 changed files with 103 additions and 1 deletions

View File

@ -4,6 +4,8 @@ import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicReference;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.database.objects.IslandDeletion;
import world.bentobox.bentobox.util.DeleteIslandChunks;
@ -24,7 +26,7 @@ public class IslandChunkDeletionManager implements Runnable {
this.slowDeletion = plugin.getSettings().isSlowDeletion();
if (slowDeletion) {
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 0L, 20L);
Bukkit.getScheduler().runTaskTimer(plugin, this, 0L, 20L);
}
}

View File

@ -0,0 +1,100 @@
package world.bentobox.bentobox.managers;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.bukkit.Bukkit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
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.database.objects.IslandDeletion;
import world.bentobox.bentobox.util.DeleteIslandChunks;
/**
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({BentoBox.class, Bukkit.class, DeleteIslandChunks.class})
public class IslandChunkDeletionManagerTest {
@Mock
private BentoBox plugin;
private IslandChunkDeletionManager icdm;
@Mock
private DeleteIslandChunks dic;
@Mock
private IslandWorldManager iwm;
@Mock
private IslandDeletion id;
private Settings settings;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// IWM
when(plugin.getIWM()).thenReturn(iwm);
// Scheduler
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// DeleteIslandChunks
PowerMockito.whenNew(DeleteIslandChunks.class).withAnyArguments().thenReturn(dic);
settings = new Settings();
settings.setSlowDeletion(true);
// Settings
when(plugin.getSettings()).thenReturn(settings);
icdm = new IslandChunkDeletionManager(plugin);
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandChunkDeletionManager#IslandChunkDeletionManager(world.bentobox.bentobox.BentoBox)}.
*/
@Test
public void testIslandChunkDeletionManager() {
PowerMockito.verifyStatic(Bukkit.class, times(1));
Bukkit.getScheduler();
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandChunkDeletionManager#run()}.
*/
@Test
public void testRun() {
icdm.add(id);
icdm.run();
verify(id, times(3)).getWorld();
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandChunkDeletionManager#add(world.bentobox.bentobox.database.objects.IslandDeletion)}.
*/
@Test
public void testAdd() {
settings.setSlowDeletion(false);
icdm = new IslandChunkDeletionManager(plugin);
icdm.add(id);
verify(id, times(3)).getWorld();
}
}