Field implements IField { int getNeighborFlags() { int counter = 0; for (IField neighbor : neighbors) if (neighbor.isFlagged()) counter++; return counter; } Field(); private  Field(int state); @Override void addListener(IFieldListener listener); @Override boolean isBomb(); @Override boolean isFlagged(); @Override boolean isOpen(); @Override boolean isExploded(); @Override void removeListener(final IFieldListener listener); @Override boolean isTouched(); void setFlagged(final boolean value); int getState(); static Field createFromState(int state); @Override int getNeighborBombs(); @Override int getImage(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testGetNeighborFlags() { Field[] neighbors = createFields(3); itsField.setNeighbors(neighbors); for (int index = 0; index < neighbors.length; index++) { neighbors[index].setFlagged(true); } assertEquals(neighbors.length, itsField.getNeighborFlags()); }