Added test classes

This commit is contained in:
tastybento 2019-10-14 11:39:50 -07:00
parent 6e13cbf999
commit d01e01618c
4 changed files with 163 additions and 118 deletions

View File

@ -51,9 +51,7 @@ public class Roof {
for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) { for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) {
if (!((x > loc.getBlockX() - radius && x < loc.getBlockX() + radius) if (!((x > loc.getBlockX() - radius && x < loc.getBlockX() + radius)
&& (z > loc.getBlockZ() - radius && z < loc.getBlockZ() + radius))) { && (z > loc.getBlockZ() - radius && z < loc.getBlockZ() + radius))) {
//player.sendBlockChange(new Location(world,x,roofY,z), Material.GLASS, (byte)(radius % 14)); Block b = world.getBlockAt(x, roofY, z);
Block b = world.getBlockAt(x,roofY,z);
//plugin.logger(3,"Checking column " + x + " " + z );
if (!Walls.isWallBlock(b.getType())) { if (!Walls.isWallBlock(b.getType())) {
// Look up // Look up
for (int y = roofY; y < world.getMaxHeight(); y++) { for (int y = roofY; y < world.getMaxHeight(); y++) {
@ -86,7 +84,7 @@ public class Roof {
maxX = loc.getBlockX(); maxX = loc.getBlockX();
minZ = loc.getBlockZ(); minZ = loc.getBlockZ();
maxZ = loc.getBlockZ(); maxZ = loc.getBlockZ();
expandCoords(loc); expandCoords(world, loc.toVector());
int minx; int minx;
int maxx; int maxx;
int minz; int minz;
@ -100,7 +98,7 @@ public class Roof {
for (int x = minx; x <= maxx; x++) { for (int x = minx; x <= maxx; x++) {
for (int z = minz; z <= maxz; z++) { for (int z = minz; z <= maxz; z++) {
// This will push out the coords if possible // This will push out the coords if possible
expandCoords(new Location(world, x, loc.getBlockY(), z)); expandCoords(world, new Vector(x, loc.getBlockY(), z));
} }
} }
// Repeat until nothing changes // Repeat until nothing changes
@ -114,13 +112,14 @@ public class Roof {
* up to 100 in any direction * up to 100 in any direction
* @param height - location to start search * @param height - location to start search
*/ */
private void expandCoords(Location height) { private void expandCoords(World world, Vector height) {
Location maxx = height.clone(); Location maxx = height.toLocation(world);
Location minx = height.clone(); Location minx = height.toLocation(world);
Location maxz = height.clone(); Location maxz = height.toLocation(world);
Location minz = height.clone(); Location minz = height.toLocation(world);
int limit = 0; int limit = 0;
while (ROOFBLOCKS.contains(maxx.getBlock().getType()) && limit < 100) { while (ROOFBLOCKS
.contains(world.getBlockAt(maxx).getType()) && limit < 100) {
limit++; limit++;
maxx.add(new Vector(1,0,0)); maxx.add(new Vector(1,0,0));
} }
@ -128,7 +127,7 @@ public class Roof {
maxX = maxx.getBlockX()-1; maxX = maxx.getBlockX()-1;
} }
while (ROOFBLOCKS.contains(minx.getBlock().getType()) && limit < 200) { while (ROOFBLOCKS.contains(world.getBlockAt(minx).getType()) && limit < 200) {
limit++; limit++;
minx.subtract(new Vector(1,0,0)); minx.subtract(new Vector(1,0,0));
} }
@ -136,7 +135,7 @@ public class Roof {
minX = minx.getBlockX() + 1; minX = minx.getBlockX() + 1;
} }
while (ROOFBLOCKS.contains(maxz.getBlock().getType()) && limit < 300) { while (ROOFBLOCKS.contains(world.getBlockAt(maxz).getType()) && limit < 300) {
limit++; limit++;
maxz.add(new Vector(0,0,1)); maxz.add(new Vector(0,0,1));
} }
@ -144,7 +143,7 @@ public class Roof {
maxZ = maxz.getBlockZ() - 1; maxZ = maxz.getBlockZ() - 1;
} }
while (ROOFBLOCKS.contains(minz.getBlock().getType()) && limit < 400) { while (ROOFBLOCKS.contains(world.getBlockAt(minz).getType()) && limit < 400) {
limit++; limit++;
minz.subtract(new Vector(0,0,1)); minz.subtract(new Vector(0,0,1));
} }
@ -152,54 +151,34 @@ public class Roof {
minZ = minz.getBlockZ() + 1; minZ = minz.getBlockZ() + 1;
} }
} }
/** /**
* @return the minX * @return the minX
*/ */
public int getMinX() { public int getMinX() {
return minX; return minX;
} }
/**
* @param minX the minX to set
*/
public void setMinX(int minX) {
this.minX = minX;
}
/** /**
* @return the maxX * @return the maxX
*/ */
public int getMaxX() { public int getMaxX() {
return maxX; return maxX;
} }
/**
* @param maxX the maxX to set
*/
public void setMaxX(int maxX) {
this.maxX = maxX;
}
/** /**
* @return the minZ * @return the minZ
*/ */
public int getMinZ() { public int getMinZ() {
return minZ; return minZ;
} }
/**
* @param minZ the minZ to set
*/
public void setMinZ(int minZ) {
this.minZ = minZ;
}
/** /**
* @return the maxZ * @return the maxZ
*/ */
public int getMaxZ() { public int getMaxZ() {
return maxZ; return maxZ;
} }
/**
* @param maxZ the maxZ to set
*/
public void setMaxZ(int maxZ) {
this.maxZ = maxZ;
}
/** /**
* @return the area * @return the area

View File

@ -14,7 +14,6 @@ import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.util.BoundingBox; import org.bukkit.util.BoundingBox;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -77,13 +76,6 @@ public class BiomeRecipeTest {
br.addReqBlocks(Material.GRASS_BLOCK, 2); br.addReqBlocks(Material.GRASS_BLOCK, 2);
} }
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
/** /**
* Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#addConvBlocks(org.bukkit.Material, org.bukkit.Material, double, org.bukkit.Material)}. * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#addConvBlocks(org.bukkit.Material, org.bukkit.Material, double, org.bukkit.Material)}.
*/ */

View File

@ -1,7 +1,9 @@
package world.bentobox.greenhouses.greenhouse; package world.bentobox.greenhouses.greenhouse;
import static org.junit.Assert.fail; import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.bukkit.Location; import org.bukkit.Location;
@ -9,163 +11,142 @@ import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
/** /**
* @author tastybento * @author tastybento
* *
*/ */
@RunWith(PowerMockRunner.class)
public class RoofTest { public class RoofTest {
private Roof roof; private Roof roof;
@Mock
private Block block; private Block block;
@Mock
private Location location; private Location location;
@Mock
private World world;
/** /**
* @throws java.lang.Exception * @throws java.lang.Exception
*/ */
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
location = mock(Location.class);
World world = mock(World.class);
when(world.getMaxHeight()).thenReturn(255); when(world.getMaxHeight()).thenReturn(255);
block = mock(Block.class); // Block
when(block.getType()).thenReturn(Material.GLASS); when(block.getType()).thenReturn(Material.AIR, Material.AIR, Material.AIR, Material.AIR, Material.AIR,
when(world.getBlockAt(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(block); 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);
when(location.getWorld()).thenReturn(world); when(location.getWorld()).thenReturn(world);
when(location.getBlockX()).thenReturn(10); when(location.getBlockX()).thenReturn(10);
when(location.getBlockY()).thenReturn(10); when(location.getBlockY()).thenReturn(10);
when(location.getBlockZ()).thenReturn(10); when(location.getBlockZ()).thenReturn(10);
when(location.getBlock()).thenReturn(block);
when(location.clone()).thenReturn(location);
} // Test
roof = new Roof(location);
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#Roof(org.bukkit.Location)}.
*/
@Ignore
@Test
public void testRoof() {
//roof = new Roof(location);
} }
/** /**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMinX()}. * Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMinX()}.
*/ */
@Ignore
@Test @Test
public void testGetMinX() { public void testGetMinX() {
fail("Not yet implemented"); // TODO assertEquals(-9, roof.getMinX());
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#setMinX(int)}.
*/
@Ignore
@Test
public void testSetMinX() {
fail("Not yet implemented"); // TODO
} }
/** /**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMaxX()}. * Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMaxX()}.
*/ */
@Ignore
@Test @Test
public void testGetMaxX() { public void testGetMaxX() {
fail("Not yet implemented"); // TODO assertEquals(28, roof.getMaxX());
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#setMaxX(int)}.
*/
@Ignore
@Test
public void testSetMaxX() {
fail("Not yet implemented"); // TODO
} }
/** /**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMinZ()}. * Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMinZ()}.
*/ */
@Ignore
@Test @Test
public void testGetMinZ() { public void testGetMinZ() {
fail("Not yet implemented"); // TODO assertEquals(-9, roof.getMinZ());
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#setMinZ(int)}.
*/
@Ignore
@Test
public void testSetMinZ() {
fail("Not yet implemented"); // TODO
} }
/** /**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMaxZ()}. * Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMaxZ()}.
*/ */
@Ignore
@Test @Test
public void testGetMaxZ() { public void testGetMaxZ() {
fail("Not yet implemented"); // TODO assertEquals(29, roof.getMaxZ());
}
/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#setMaxZ(int)}.
*/
@Ignore
@Test
public void testSetMaxZ() {
fail("Not yet implemented"); // TODO
} }
/** /**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getArea()}. * Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getArea()}.
*/ */
@Ignore
@Test @Test
public void testGetArea() { public void testGetArea() {
fail("Not yet implemented"); // TODO assertEquals(1406, roof.getArea());
} }
/** /**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#isRoofFound()}. * Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#isRoofFound()}.
*/ */
@Ignore
@Test @Test
public void testIsRoofFound() { public void testIsRoofFound() {
fail("Not yet implemented"); // TODO assertTrue(roof.isRoofFound());
} }
/** /**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getHeight()}. * Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getHeight()}.
*/ */
@Ignore
@Test @Test
public void testGetHeight() { public void testGetHeight() {
fail("Not yet implemented"); // TODO assertEquals(14, roof.getHeight());
} }
/** /**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getLocation()}. * Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getLocation()}.
*/ */
@Ignore
@Test @Test
public void testGetLocation() { public void testGetLocation() {
fail("Not yet implemented"); // TODO assertEquals(location, roof.getLocation());
} }
/** /**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#toString()}. * Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#toString()}.
*/ */
@Ignore
@Test @Test
public void testToString() { public void testToString() {
fail("Not yet implemented"); // TODO assertTrue(roof.toString().endsWith("minX=-9, maxX=28, minZ=-9, maxZ=29, height=14, roofFound=true]"));
} }
} }

View File

@ -0,0 +1,93 @@
package world.bentobox.greenhouses.listeners;
import static org.junit.Assert.fail;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @author tastybento
*
*/
public class GreenhouseEventsTest {
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#GreenhouseEvents(world.bentobox.greenhouses.Greenhouses)}.
*/
@Test
public void testGreenhouseEvents() {
fail("Not yet implemented");
}
/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerInteract(org.bukkit.event.player.PlayerInteractEvent)}.
*/
@Test
public void testOnPlayerInteract() {
fail("Not yet implemented");
}
/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onIceBreak(org.bukkit.event.block.BlockBreakEvent)}.
*/
@Test
public void testOnIceBreak() {
fail("Not yet implemented");
}
/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}.
*/
@Test
public void testOnPlayerMove() {
fail("Not yet implemented");
}
/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerTeleport(org.bukkit.event.player.PlayerTeleportEvent)}.
*/
@Test
public void testOnPlayerTeleport() {
fail("Not yet implemented");
}
/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onBlockBreak(org.bukkit.event.block.BlockBreakEvent)}.
*/
@Test
public void testOnBlockBreak() {
fail("Not yet implemented");
}
/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
*/
@Test
public void testOnPlayerBlockPlace() {
fail("Not yet implemented");
}
/**
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPistonPush(org.bukkit.event.block.BlockPistonExtendEvent)}.
*/
@Test
public void testOnPistonPush() {
fail("Not yet implemented");
}
}