### Question:
HexagonGridBuilder extends AbstractGridBuilder { @Override public boolean isValidNeighbor(Neighbor neighbor) { switch (neighbor) { case LEFT: case RIGHT: return orientation == Orientation.ANGLED; case LOWER: case UPPER: return orientation == Orientation.FLAT; case LOWER_LEFT: case LOWER_RIGHT: case UPPER_LEFT: case UPPER_RIGHT: return true; default: throw new IllegalArgumentException("Invalid value for neighbor"); } } HexagonGridBuilder(ReferencedEnvelope gridBounds, double sideLen, Orientation orientation); @Override boolean isValidNeighbor(Neighbor neighbor); @Override Hexagon createNeighbor(GridElement el, Neighbor neighbor); @Override GridElement getFirstElement(); @Override GridElement getNextXElement(GridElement el); @Override GridElement getNextYElement(GridElement el); @Override boolean isValidDenseVertexSpacing(double v);  }### Answer:
@Test public void validNeighborPosition() { class Case { Orientation o; Neighbor n; boolean valid; public Case(Orientation o, Neighbor n, boolean valid) { this.o = o; this.n = n; this.valid = valid; } } Case[] cases = { new Case(Orientation.ANGLED, Neighbor.LEFT, true), new Case(Orientation.ANGLED, Neighbor.LOWER, false), new Case(Orientation.ANGLED, Neighbor.LOWER_LEFT, true), new Case(Orientation.ANGLED, Neighbor.LOWER_RIGHT, true), new Case(Orientation.ANGLED, Neighbor.RIGHT, true), new Case(Orientation.ANGLED, Neighbor.UPPER, false), new Case(Orientation.ANGLED, Neighbor.UPPER_LEFT, true), new Case(Orientation.ANGLED, Neighbor.UPPER_RIGHT, true), new Case(Orientation.FLAT, Neighbor.LEFT, false), new Case(Orientation.FLAT, Neighbor.LOWER, true), new Case(Orientation.FLAT, Neighbor.LOWER_LEFT, true), new Case(Orientation.FLAT, Neighbor.LOWER_RIGHT, true), new Case(Orientation.FLAT, Neighbor.RIGHT, false), new Case(Orientation.FLAT, Neighbor.UPPER, true), new Case(Orientation.FLAT, Neighbor.UPPER_LEFT, true), new Case(Orientation.FLAT, Neighbor.UPPER_RIGHT, true), }; for (Case c : cases) { if (c.o == Orientation.ANGLED) { assertEquals("Failed for case: " + c.o + " " + c.n, c.valid, angledBuilder.isValidNeighbor(c.n)); } else { assertEquals("Failed for case: " + c.o + " " + c.n, c.valid, flatBuilder.isValidNeighbor(c.n)); } } }