Skip to content

Commit

Permalink
Revert "Rewrote PanelItemTest to avoid null check errors in Bukkit cl…
Browse files Browse the repository at this point in the history
…ass"

This reverts commit 5a193cd.
  • Loading branch information
tastybento committed Dec 10, 2023
1 parent 5a193cd commit 55e94b4
Showing 1 changed file with 14 additions and 32 deletions.
46 changes: 14 additions & 32 deletions src/test/java/world/bentobox/bentobox/api/panels/PanelItemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.List;
import java.util.Optional;
import java.util.logging.Logger;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemStack;
import org.junit.After;
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 world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
Expand All @@ -33,35 +30,29 @@
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Bukkit.class })
public class PanelItemTest {

@Mock
private PanelItemBuilder pib;
private PanelItem pi;
@Mock
private ClickHandler clickHandler;
@Mock
private Server server;
@Mock
private ItemFactory itemFac;

/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
World world = mock(World.class);
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
when(server.getWorld("world")).thenReturn(world);
when(server.getVersion()).thenReturn("BSB_Mocking");
when(server.getItemFactory()).thenReturn(itemFac);

if (Bukkit.getServer() == null) {
Bukkit.setServer(server);
}

pib = new PanelItemBuilder().amount(2).clickHandler(clickHandler).description(List.of("Description", "hello"))
.icon(new ItemStack(Material.STONE)).name("Name");
pi = pib.build();
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// Builder
when(pib.getAmount()).thenReturn(2);
when(pib.getClickHandler()).thenReturn(clickHandler);
when(pib.getDescription()).thenReturn(List.of("Description", "hello"));
when(pib.getIcon()).thenReturn(new ItemStack(Material.STONE));
when(pib.getName()).thenReturn("Name");
when(pib.getPlayerHeadName()).thenReturn("tastybento");
pi = new PanelItem(pib);
}

/**
Expand Down Expand Up @@ -105,7 +96,7 @@ public void testGetDescription() {
@Test
public void testSetDescription() {
assertEquals(2, pi.getDescription().size());
pi.setDescription(List.of("1", "2", "3"));
pi.setDescription(List.of("1","2","3"));
assertEquals(3, pi.getDescription().size());
}

Expand Down Expand Up @@ -187,10 +178,6 @@ public void testSetGlow() {
*/
@Test
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());

}
Expand All @@ -200,11 +187,6 @@ public void testIsPlayerHead() {
*/
@Test
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());
}

Expand Down

0 comments on commit 55e94b4

Please sign in to comment.