Removed static and server calling from test class.

This commit is contained in:
tastybento 2019-03-11 19:00:05 -07:00
parent 2935f41173
commit a2631b88a6

View File

@ -35,7 +35,6 @@ import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mockito; import org.mockito.Mockito;
@ -63,15 +62,15 @@ import world.bentobox.bentobox.util.Util;
* *
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest( {BentoBox.class, Flags.class, Util.class} ) @PrepareForTest( {Bukkit.class, BentoBox.class, Flags.class, Util.class} )
public class ChestDamageListenerTest { public class ChestDamageListenerTest {
private static Location location; private Location location;
private static BentoBox plugin; private BentoBox plugin;
private static World world; private World world;
@BeforeClass @Before
public static void setUpClass() { public void setUpClass() {
// Set up plugin // Set up plugin
plugin = mock(BentoBox.class); plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin); Whitebox.setInternalState(BentoBox.class, "instance", plugin);
@ -88,7 +87,9 @@ public class ChestDamageListenerTest {
ItemFactory itemFactory = mock(ItemFactory.class); ItemFactory itemFactory = mock(ItemFactory.class);
when(server.getItemFactory()).thenReturn(itemFactory); when(server.getItemFactory()).thenReturn(itemFactory);
Bukkit.setServer(server); // Bukkit
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getServer()).thenReturn(server);
SkullMeta skullMeta = mock(SkullMeta.class); SkullMeta skullMeta = mock(SkullMeta.class);
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta); when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
@ -155,12 +156,11 @@ public class ChestDamageListenerTest {
Optional<Island> optional = Optional.of(island); Optional<Island> optional = Optional.of(island);
when(im.getProtectedIslandAt(Mockito.any())).thenReturn(optional); when(im.getProtectedIslandAt(Mockito.any())).thenReturn(optional);
} // Util
@Before
public void setUp() {
PowerMockito.mockStatic(Util.class); PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class)); when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
} }
/** /**