### Question:
AbstractLayeredBoard implements ClientBoard { protected int countNear(int numLayer, int x, int y, E element) { if (pt(x, y).isOutOf(size)) { return 0; } return (int) getNear(numLayer, x, y).stream() .filter( it -> it.equals(element)) .count(); }  ClientBoard forString(String boardString); ClientBoard forString(String... layers); abstract E valueOf(char ch); int size(); static Set<Point> removeDuplicates(Collection<Point> all); @Override String toString(); boolean isOutOfField(int x, int y); List<String> getLayersString(); void setSource(JSONObject source);  }### Answer:
@Test public void shouldWork_countNear_layer1() { assertEquals(2, board.countNear(LAYER_1, 0, 0, Elements.ONE)); assertEquals(1, board.countNear(LAYER_1, 0, 0, Elements.TWO)); assertEquals(0, board.countNear(LAYER_1, 0, 0, Elements.THREE)); assertEquals(5, board.countNear(LAYER_1, 1, 1, Elements.ONE)); assertEquals(1, board.countNear(LAYER_1, 1, 1, Elements.TWO)); assertEquals(2, board.countNear(LAYER_1, 1, 1, Elements.THREE)); assertEquals(5, board.countNear(LAYER_1, 2, 2, Elements.ONE)); assertEquals(2, board.countNear(LAYER_1, 2, 2, Elements.TWO)); assertEquals(1, board.countNear(LAYER_1, 2, 2, Elements.THREE)); assertEquals(2, board.countNear(LAYER_1, 3, 3, Elements.ONE)); assertEquals(0, board.countNear(LAYER_1, 3, 3, Elements.TWO)); assertEquals(1, board.countNear(LAYER_1, 3, 3, Elements.THREE)); assertEquals(0, board.countNear(LAYER_1, -1, -1, Elements.THREE)); }
@Test public void shouldWork_countNear_layer2() { assertEquals(0, board.countNear(LAYER_2, 0, 0, Elements.ONE)); assertEquals(1, board.countNear(LAYER_2, 0, 0, Elements.FOUR)); assertEquals(2, board.countNear(LAYER_2, 0, 0, Elements.NONE)); assertEquals(0, board.countNear(LAYER_2, 1, 1, Elements.ONE)); assertEquals(1, board.countNear(LAYER_2, 1, 1, Elements.FOUR)); assertEquals(7, board.countNear(LAYER_2, 1, 1, Elements.NONE)); assertEquals(0, board.countNear(LAYER_2, 2, 1, Elements.ONE)); assertEquals(2, board.countNear(LAYER_2, 2, 1, Elements.FOUR)); assertEquals(6, board.countNear(LAYER_2, 2, 1, Elements.NONE)); assertEquals(0, board.countNear(LAYER_2, 3, 3, Elements.ONE)); assertEquals(1, board.countNear(LAYER_2, 3, 3, Elements.FOUR)); assertEquals(2, board.countNear(LAYER_2, 3, 3, Elements.NONE)); assertEquals(0, board.countNear(LAYER_2, -1, -1, Elements.THREE)); }