mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-10 21:11:04 +01:00
Revert "Rewrote PanelItemTest to avoid null check errors in Bukkit class"
This reverts commit 5a193cda1c
.
This commit is contained in:
parent
5a193cda1c
commit
55e94b4c9f
@ -4,18 +4,13 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.inventory.ItemFactory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -23,6 +18,8 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
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.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||||
@ -33,35 +30,29 @@ import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({ Bukkit.class })
|
||||||
public class PanelItemTest {
|
public class PanelItemTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
private PanelItemBuilder pib;
|
private PanelItemBuilder pib;
|
||||||
private PanelItem pi;
|
private PanelItem pi;
|
||||||
@Mock
|
@Mock
|
||||||
private ClickHandler clickHandler;
|
private ClickHandler clickHandler;
|
||||||
@Mock
|
|
||||||
private Server server;
|
|
||||||
@Mock
|
|
||||||
private ItemFactory itemFac;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
World world = mock(World.class);
|
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
// Builder
|
||||||
when(server.getWorld("world")).thenReturn(world);
|
when(pib.getAmount()).thenReturn(2);
|
||||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
when(pib.getClickHandler()).thenReturn(clickHandler);
|
||||||
when(server.getItemFactory()).thenReturn(itemFac);
|
when(pib.getDescription()).thenReturn(List.of("Description", "hello"));
|
||||||
|
when(pib.getIcon()).thenReturn(new ItemStack(Material.STONE));
|
||||||
if (Bukkit.getServer() == null) {
|
when(pib.getName()).thenReturn("Name");
|
||||||
Bukkit.setServer(server);
|
when(pib.getPlayerHeadName()).thenReturn("tastybento");
|
||||||
}
|
pi = new PanelItem(pib);
|
||||||
|
|
||||||
pib = new PanelItemBuilder().amount(2).clickHandler(clickHandler).description(List.of("Description", "hello"))
|
|
||||||
.icon(new ItemStack(Material.STONE)).name("Name");
|
|
||||||
pi = pib.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,7 +96,7 @@ public class PanelItemTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testSetDescription() {
|
public void testSetDescription() {
|
||||||
assertEquals(2, pi.getDescription().size());
|
assertEquals(2, pi.getDescription().size());
|
||||||
pi.setDescription(List.of("1", "2", "3"));
|
pi.setDescription(List.of("1","2","3"));
|
||||||
assertEquals(3, pi.getDescription().size());
|
assertEquals(3, pi.getDescription().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,10 +178,6 @@ public class PanelItemTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testIsPlayerHead() {
|
public void testIsPlayerHead() {
|
||||||
// Make a head
|
|
||||||
pib = new PanelItemBuilder().amount(2).clickHandler(clickHandler).description(List.of("Description", "hello"))
|
|
||||||
.icon("tastybento").name("Name");
|
|
||||||
pi = pib.build();
|
|
||||||
assertTrue(pi.isPlayerHead());
|
assertTrue(pi.isPlayerHead());
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -200,11 +187,6 @@ public class PanelItemTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetPlayerHeadName() {
|
public void testGetPlayerHeadName() {
|
||||||
// Make a head
|
|
||||||
pib = new PanelItemBuilder().amount(2).clickHandler(clickHandler).description(List.of("Description", "hello"))
|
|
||||||
.icon("tastybento").name("Name");
|
|
||||||
pi = pib.build();
|
|
||||||
|
|
||||||
assertEquals("tastybento", pi.getPlayerHeadName());
|
assertEquals("tastybento", pi.getPlayerHeadName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user