Fixed IslandCacheTest

Also commented out CellState.RESERVED.

That was a tough one. I had to rewrite IslandGrid#getIslandAt(int, int) quite a few times before using the stream() thing. I tested it a bit - it seems it is working like a charm.
I just hope that it won't be something useless - another plumbing change that adds nothing. It shouldn't - because of the "RESERVED" thing - but, well... it's been quite a hard thing!
This commit is contained in:
Florian CUNY 2018-08-14 11:38:44 +02:00
parent 4af03ee939
commit 8fb4e58994
2 changed files with 10 additions and 15 deletions

View File

@ -59,11 +59,14 @@ public class IslandGrid {
* @return Island or null
*/
public Island getIslandAt(int x, int z) {
if (grid.contains(x, z)) {
Cell cell = grid.get(x, z);
if (cell.getState().equals(CellState.OCCUPIED)) {
return (Island) cell.getObject();
}
Table.Cell<Integer, Integer, Cell> tableCell = grid.cellSet()
.stream()
.filter(cell -> (cell.getValue().getState().equals(CellState.OCCUPIED)))
.filter(cell -> ((Island) cell.getValue().getObject()).inIslandSpace(x, z))
.findFirst().orElse(null);
if (tableCell != null) {
return (Island) tableCell.getValue().getObject();
}
return null;
}
@ -93,7 +96,7 @@ public class IslandGrid {
* @author Poslovitch
*/
private enum CellState {
RESERVED,
//RESERVED,
OCCUPIED
}
}

View File

@ -61,8 +61,6 @@ public class IslandCacheTest {
IslandsManager im = mock(IslandsManager.class);
when(plugin.getIslands()).thenReturn(im);
island = mock(Island.class);
when(island.getWorld()).thenReturn(world);
location = mock(Location.class);
@ -197,14 +195,8 @@ public class IslandCacheTest {
assertNull(ic.getIslandAt(location2));
}
/*
@Test
public void testGetIslands() {
fail("Not yet implemented"); // TODO
}
*/
@Test
public void testgetMembers() {
public void testGetMembers() {
// New cache
IslandCache ic = new IslandCache();
ic.addIsland(island);