Greenhouses/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java

195 lines
6.8 KiB
Java
Raw Normal View History

2019-02-08 00:17:55 +01:00
package world.bentobox.greenhouses.greenhouse;
2019-10-14 20:39:50 +02:00
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
2019-10-14 20:39:50 +02:00
import static org.junit.Assert.assertTrue;
2021-01-16 18:58:25 +01:00
import static org.mockito.ArgumentMatchers.any;
2021-01-16 23:27:29 +01:00
import static org.mockito.ArgumentMatchers.anyInt;
2019-02-08 00:17:55 +01:00
import static org.mockito.Mockito.when;
import org.bukkit.Bukkit;
2019-02-08 00:17:55 +01:00
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
2019-02-08 00:17:55 +01:00
import org.bukkit.World;
2021-01-16 18:58:25 +01:00
import org.bukkit.util.Vector;
2019-02-08 00:17:55 +01:00
import org.junit.Before;
import org.junit.Test;
2019-10-14 20:39:50 +02:00
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;
2019-10-14 20:39:50 +02:00
import org.powermock.modules.junit4.PowerMockRunner;
2019-02-08 00:17:55 +01:00
import world.bentobox.greenhouses.Greenhouses;
import world.bentobox.greenhouses.Settings;
2021-01-16 18:16:09 +01:00
import world.bentobox.greenhouses.world.AsyncWorldCache;
2019-02-08 00:17:55 +01:00
/**
* @author tastybento
*
*/
2019-10-14 20:39:50 +02:00
@RunWith(PowerMockRunner.class)
@PrepareForTest({Greenhouses.class, Bukkit.class})
2019-02-08 00:17:55 +01:00
public class RoofTest {
private Roof roof;
2019-10-14 20:39:50 +02:00
@Mock
2019-02-08 00:17:55 +01:00
private Location location;
2019-10-14 20:39:50 +02:00
@Mock
private World world;
@Mock
private Greenhouses addon;
private Settings s;
2021-01-16 18:58:25 +01:00
@Mock
2021-01-16 18:16:09 +01:00
private AsyncWorldCache cache;
2019-02-08 00:17:55 +01:00
@Before
2021-08-01 08:10:07 +02:00
public void setUp() {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
when(Tag.TRAPDOORS.isTagged(Material.BIRCH_TRAPDOOR)).thenReturn(true);
s = new Settings();
when(addon.getSettings()).thenReturn(s);
2019-02-08 00:17:55 +01:00
when(world.getMaxHeight()).thenReturn(255);
2019-10-14 20:39:50 +02:00
// Block
2021-01-16 18:58:25 +01:00
when(cache.getBlockType(any())).thenReturn(Material.AIR, Material.AIR, Material.AIR, Material.AIR,
2019-10-14 20:39:50 +02:00
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.AIR,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.AIR,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.AIR,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.GLASS, Material.GLASS, Material.GLASS, Material.GLASS,
Material.AIR);
2019-02-08 00:17:55 +01:00
when(location.getWorld()).thenReturn(world);
when(location.getBlockX()).thenReturn(10);
when(location.getBlockY()).thenReturn(10);
when(location.getBlockZ()).thenReturn(10);
2019-10-14 20:39:50 +02:00
when(location.clone()).thenReturn(location);
2019-03-02 19:53:15 +01:00
2019-10-14 20:39:50 +02:00
// Test
2023-06-04 17:44:55 +02:00
roof = new Roof(cache, location, addon);
2021-01-16 18:58:25 +01:00
assertTrue(roof.findRoof(new Vector(10,10,10)));
2019-02-08 00:17:55 +01:00
}
@Test
public void testNoGlass() {
2021-01-16 18:58:25 +01:00
when(cache.getBlockType(anyInt(), anyInt(), anyInt())).thenReturn(Material.AIR);
2023-06-04 17:44:55 +02:00
roof = new Roof(cache, location, addon);
2021-01-16 18:58:25 +01:00
assertFalse(roof.findRoof(new Vector(10,10,10)));
}
2019-02-08 00:17:55 +01:00
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMinX()}.
*/
@Test
public void testGetMinX() {
2019-10-14 20:39:50 +02:00
assertEquals(-9, roof.getMinX());
2019-02-08 00:17:55 +01:00
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMaxX()}.
*/
@Test
public void testGetMaxX() {
2019-10-14 20:39:50 +02:00
assertEquals(28, roof.getMaxX());
2019-02-08 00:17:55 +01:00
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMinZ()}.
*/
@Test
public void testGetMinZ() {
2019-10-14 20:39:50 +02:00
assertEquals(-9, roof.getMinZ());
2019-02-08 00:17:55 +01:00
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMaxZ()}.
*/
@Test
public void testGetMaxZ() {
2019-10-14 20:39:50 +02:00
assertEquals(29, roof.getMaxZ());
2019-02-08 00:17:55 +01:00
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getArea()}.
*/
@Test
public void testGetArea() {
2019-10-14 20:39:50 +02:00
assertEquals(1406, roof.getArea());
2019-02-08 00:17:55 +01:00
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getHeight()}.
*/
@Test
public void testGetHeight() {
2019-10-14 20:39:50 +02:00
assertEquals(14, roof.getHeight());
2019-02-08 00:17:55 +01:00
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getLocation()}.
*/
@Test
public void testGetLocation() {
2019-10-14 20:39:50 +02:00
assertEquals(location, roof.getLocation());
2019-02-08 00:17:55 +01:00
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#toString()}.
*/
@Test
public void testToString() {
2021-01-16 18:58:25 +01:00
assertEquals("Roof [height=14, roofFound=true, minX=-9, maxX=28, minZ=-9, maxZ=29]", roof.toString());
2019-02-08 00:17:55 +01:00
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#roofBlocks(org.bukkit.Material)}.
*/
@Test
public void testWallBlocks() {
2023-06-04 17:44:55 +02:00
assertFalse(roof.roofBlocks(Material.ACACIA_BOAT));
assertTrue(roof.roofBlocks(Material.GLASS));
assertTrue(roof.roofBlocks(Material.GLOWSTONE));
assertFalse(roof.roofBlocks(Material.ACACIA_DOOR));
assertTrue(roof.roofBlocks(Material.HOPPER));
assertTrue(roof.roofBlocks(Material.PURPLE_STAINED_GLASS_PANE));
assertTrue(roof.roofBlocks(Material.BIRCH_TRAPDOOR));
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#roofBlocks(org.bukkit.Material)}.
*/
@Test
public void testWallBlocksNoGlowStoneNoPanes() {
s.setAllowGlowstone(false);
s.setAllowPanes(false);
2023-06-04 17:44:55 +02:00
assertFalse(roof.roofBlocks(Material.ACACIA_BOAT));
assertTrue(roof.roofBlocks(Material.GLASS));
assertFalse(roof.roofBlocks(Material.GLOWSTONE));
assertFalse(roof.roofBlocks(Material.ACACIA_DOOR));
assertTrue(roof.roofBlocks(Material.HOPPER));
assertFalse(roof.roofBlocks(Material.PURPLE_STAINED_GLASS_PANE));
assertTrue(roof.roofBlocks(Material.BIRCH_TRAPDOOR));
}
2019-02-08 00:17:55 +01:00
}