Skip to content

Commit

Permalink
Added test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Oct 14, 2019
1 parent 6e13cbf commit d01e016
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 118 deletions.
55 changes: 17 additions & 38 deletions src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public Roof(Location loc) {
for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) {
if (!((x > loc.getBlockX() - radius && x < loc.getBlockX() + 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);
//plugin.logger(3,"Checking column " + x + " " + z );
Block b = world.getBlockAt(x, roofY, z);
if (!Walls.isWallBlock(b.getType())) {
// Look up
for (int y = roofY; y < world.getMaxHeight(); y++) {
Expand Down Expand Up @@ -86,7 +84,7 @@ public Roof(Location loc) {
maxX = loc.getBlockX();
minZ = loc.getBlockZ();
maxZ = loc.getBlockZ();
expandCoords(loc);
expandCoords(world, loc.toVector());
int minx;
int maxx;
int minz;
Expand All @@ -100,7 +98,7 @@ public Roof(Location loc) {
for (int x = minx; x <= maxx; x++) {
for (int z = minz; z <= maxz; z++) {
// 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
Expand All @@ -114,92 +112,73 @@ public Roof(Location loc) {
* up to 100 in any direction
* @param height - location to start search
*/
private void expandCoords(Location height) {
Location maxx = height.clone();
Location minx = height.clone();
Location maxz = height.clone();
Location minz = height.clone();
private void expandCoords(World world, Vector height) {
Location maxx = height.toLocation(world);
Location minx = height.toLocation(world);
Location maxz = height.toLocation(world);
Location minz = height.toLocation(world);
int limit = 0;
while (ROOFBLOCKS.contains(maxx.getBlock().getType()) && limit < 100) {
while (ROOFBLOCKS
.contains(world.getBlockAt(maxx).getType()) && limit < 100) {
limit++;
maxx.add(new Vector(1,0,0));
}
if (maxx.getBlockX()-1 > maxX) {
maxX = maxx.getBlockX()-1;
}

while (ROOFBLOCKS.contains(minx.getBlock().getType()) && limit < 200) {
while (ROOFBLOCKS.contains(world.getBlockAt(minx).getType()) && limit < 200) {
limit++;
minx.subtract(new Vector(1,0,0));
}
if (minx.getBlockX() + 1 < minX) {
minX = minx.getBlockX() + 1;
}

while (ROOFBLOCKS.contains(maxz.getBlock().getType()) && limit < 300) {
while (ROOFBLOCKS.contains(world.getBlockAt(maxz).getType()) && limit < 300) {
limit++;
maxz.add(new Vector(0,0,1));
}
if (maxz.getBlockZ() - 1 > maxZ) {
maxZ = maxz.getBlockZ() - 1;
}

while (ROOFBLOCKS.contains(minz.getBlock().getType()) && limit < 400) {
while (ROOFBLOCKS.contains(world.getBlockAt(minz).getType()) && limit < 400) {
limit++;
minz.subtract(new Vector(0,0,1));
}
if (minz.getBlockZ() + 1 < minZ) {
minZ = minz.getBlockZ() + 1;
}
}

/**
* @return the minX
*/
public int getMinX() {
return minX;
}
/**
* @param minX the minX to set
*/
public void setMinX(int minX) {
this.minX = minX;
}

/**
* @return the maxX
*/
public int getMaxX() {
return maxX;
}
/**
* @param maxX the maxX to set
*/
public void setMaxX(int maxX) {
this.maxX = maxX;
}

/**
* @return the minZ
*/
public int getMinZ() {
return minZ;
}
/**
* @param minZ the minZ to set
*/
public void setMinZ(int minZ) {
this.minZ = minZ;
}

/**
* @return the maxZ
*/
public int getMaxZ() {
return maxZ;
}
/**
* @param maxZ the maxZ to set
*/
public void setMaxZ(int maxZ) {
this.maxZ = maxZ;
}

/**
* @return the area
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.util.BoundingBox;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -77,13 +76,6 @@ public void setUp() throws Exception {
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)}.
*/
Expand Down
125 changes: 53 additions & 72 deletions src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java
Original file line number Diff line number Diff line change
@@ -1,171 +1,152 @@
package world.bentobox.greenhouses.greenhouse;

import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.junit.Assert.assertEquals;
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 org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.junit.Before;
import org.junit.Ignore;
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
*
*/
@RunWith(PowerMockRunner.class)
public class RoofTest {

private Roof roof;
@Mock
private Block block;
@Mock
private Location location;
@Mock
private World world;

/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
location = mock(Location.class);
World world = mock(World.class);
when(world.getMaxHeight()).thenReturn(255);
block = mock(Block.class);
when(block.getType()).thenReturn(Material.GLASS);
when(world.getBlockAt(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(block);
// Block
when(block.getType()).thenReturn(Material.AIR, Material.AIR, Material.AIR, Material.AIR, 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,
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.getBlockX()).thenReturn(10);
when(location.getBlockY()).thenReturn(10);
when(location.getBlockZ()).thenReturn(10);
when(location.getBlock()).thenReturn(block);
when(location.clone()).thenReturn(location);

}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#Roof(org.bukkit.Location)}.
*/
@Ignore
@Test
public void testRoof() {
//roof = new Roof(location);
// Test
roof = new Roof(location);
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMinX()}.
*/
@Ignore
@Test
public void testGetMinX() {
fail("Not yet implemented"); // TODO
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#setMinX(int)}.
*/
@Ignore
@Test
public void testSetMinX() {
fail("Not yet implemented"); // TODO
assertEquals(-9, roof.getMinX());
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMaxX()}.
*/
@Ignore
@Test
public void testGetMaxX() {
fail("Not yet implemented"); // TODO
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#setMaxX(int)}.
*/
@Ignore
@Test
public void testSetMaxX() {
fail("Not yet implemented"); // TODO
assertEquals(28, roof.getMaxX());
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMinZ()}.
*/
@Ignore
@Test
public void testGetMinZ() {
fail("Not yet implemented"); // TODO
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#setMinZ(int)}.
*/
@Ignore
@Test
public void testSetMinZ() {
fail("Not yet implemented"); // TODO
assertEquals(-9, roof.getMinZ());
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getMaxZ()}.
*/
@Ignore
@Test
public void testGetMaxZ() {
fail("Not yet implemented"); // TODO
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#setMaxZ(int)}.
*/
@Ignore
@Test
public void testSetMaxZ() {
fail("Not yet implemented"); // TODO
assertEquals(29, roof.getMaxZ());
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getArea()}.
*/
@Ignore
@Test
public void testGetArea() {
fail("Not yet implemented"); // TODO
assertEquals(1406, roof.getArea());
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#isRoofFound()}.
*/
@Ignore
@Test
public void testIsRoofFound() {
fail("Not yet implemented"); // TODO
assertTrue(roof.isRoofFound());
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getHeight()}.
*/
@Ignore
@Test
public void testGetHeight() {
fail("Not yet implemented"); // TODO
assertEquals(14, roof.getHeight());
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#getLocation()}.
*/
@Ignore
@Test
public void testGetLocation() {
fail("Not yet implemented"); // TODO
assertEquals(location, roof.getLocation());
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#toString()}.
*/
@Ignore
@Test
public void testToString() {
fail("Not yet implemented"); // TODO
assertTrue(roof.toString().endsWith("minX=-9, maxX=28, minZ=-9, maxZ=29, height=14, roofFound=true]"));
}

}

0 comments on commit d01e016

Please sign in to comment.