### Question:
Rook extends Figure { public Cell[] way(Cell source, Cell dest) throws ImpossibleMoveException { int differenceX = Math.abs(dest.getX() - source.getX()); int differenceY = Math.abs(dest.getY() - source.getY()); if (dest.getX() < 0 && dest.getY() < 0 && dest.getX() > 9 && dest.getY() > 9 && (differenceX != 0 || differenceY != 0)) { throw new ImpossibleMoveException("Ладья так не ходит"); } int moveForX = 0; if (differenceX != 0) { moveForX = source.getX() < dest.getX() ? 1 : -1; } int moveForY = 0; if (differenceY != 0) { moveForY = source.getY() < dest.getY() ? 1 : -1; } Cell[] way = new Cell[8]; int wayPosition; int currentX = source.getX(); int currentY = source.getY(); int movesNumber = Math.max(differenceX, differenceY); for (wayPosition = 0; wayPosition < movesNumber; wayPosition++) { currentX += moveForX; currentY += moveForY; way[wayPosition] = new Cell(currentX, currentY); } return Arrays.copyOf(way, wayPosition); } Rook(Cell position); Cell[] way(Cell source, Cell dest); Figure copy(Cell dest);  }### Answer:
@Test public void ifRookGoingFromPointFourFourToPointSixFour() throws ImpossibleMoveException { Rook testRook = new Rook(new Cell(4, 4)); Cell[] result = testRook.way(new Cell(4, 4), new Cell(6, 4)); assertThat(result, is(new Cell[]{new Cell(5, 4), new Cell(6, 4)})); }
@Test public void ifRookGoingFromPointFourFourToPointSixSix() throws ImpossibleMoveException { Rook testRook = new Rook(new Cell(4, 4)); Cell[] result = testRook.way(new Cell(4, 4), new Cell(4, 6)); assertThat(result, is(new Cell[]{new Cell(4, 5), new Cell(4, 6)})); }
@Test public void ifRookGoingFromPointFourFourToPointFourSix() throws ImpossibleMoveException { Rook testRook = new Rook(new Cell(4, 4)); Cell[] result = testRook.way(new Cell(4, 4), new Cell(2, 4)); assertThat(result, is(new Cell[]{new Cell(3, 4), new Cell(2, 4)})); }
@Test public void ifWrongWayThenReturnImeException() { Rook testRook = new Rook(new Cell(4, 4)); try { testRook.way(new Cell(4, 4), new Cell(5, 5)); } catch (ImpossibleMoveException ime) { assertThat("Ладья так не ходит", is(ime.getMessage())); } }