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

160 lines
5.1 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.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
2019-02-08 00:17:55 +01:00
import static org.mockito.Mockito.when;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
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.powermock.modules.junit4.PowerMockRunner;
2019-02-08 00:17:55 +01:00
/**
* @author tastybento
*
*/
2019-10-14 20:39:50 +02:00
@RunWith(PowerMockRunner.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 Block block;
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;
2019-02-08 00:17:55 +01:00
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
when(world.getMaxHeight()).thenReturn(255);
2019-10-14 20:39:50 +02:00
// Block
when(block.getType()).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);
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
when(world.getBlockAt(any(Location.class))).thenReturn(block);
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.getBlock()).thenReturn(block);
when(location.clone()).thenReturn(location);
2019-03-02 19:53:15 +01:00
2019-10-14 20:39:50 +02:00
// Test
roof = new Roof(location);
2019-02-08 00:17:55 +01:00
}
@Test
public void testNoGlass() {
when(block.getType()).thenReturn(Material.AIR);
roof = new Roof(location);
}
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#isRoofFound()}.
*/
@Test
public void testIsRoofFound() {
2019-10-14 20:39:50 +02:00
assertTrue(roof.isRoofFound());
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() {
2019-10-14 20:39:50 +02:00
assertTrue(roof.toString().endsWith("minX=-9, maxX=28, minZ=-9, maxZ=29, height=14, roofFound=true]"));
2019-02-08 00:17:55 +01:00
}
}