@Test public void shouldSaveCommandAndActAfterTick() { shouldBoardWith(new Sapper(2, 2), new Mine(3, 2)); board.getJoystick().right(); assertBoard("☼☼☼☼☼\n" + "☼***☼\n" + "☼*☺*☼\n" + "☼***☼\n" + "☼☼☼☼☼\n"); board.tick(); assertBoard("☼☼☼☼☼\n" + "☼ 11☼\n" + "☼ 1Ѡ☼\n" + "☼ 11☼\n" + "☼☼☼☼☼\n"); assertTrue(board.isGameOver()); }
@Test public void shouldDie_whenSapperAtBombs() { shouldBoardWith(new Sapper(2, 2), new Mine(3, 2)); moveRight(); assertBoard("☼☼☼☼☼\n" + "☼ 11☼\n" + "☼ 1Ѡ☼\n" + "☼ 11☼\n" + "☼☼☼☼☼\n"); assertTrue(board.isGameOver()); }
@Test public void shouldPrintAllBombs_whenSapperAtBombs() { shouldBoardWith( new Sapper(2, 2), new Mine(3, 3), new Mine(3, 2), new Mine(3, 1), new Mine(2, 1), new Mine(2, 3)); unbombUp(); unbombDown(); unbombLeft(); moveRight(); assertBoard("☼☼☼☼☼\n" + "☼ x☻☼\n" + "☼‼3Ѡ☼\n" + "☼ x☻☼\n" + "☼☼☼☼☼\n"); assertTrue(board.isGameOver()); }
private void moveRight() { board.getJoystick().right(); board.tick(); }
private void moveDown() { board.getJoystick().down(); board.tick(); }
private void shouldBoardWith(Sapper sapper, Mine... mines) { listener = mock(EventListener.class); board = new MockBoard(sapper, mines); board.newGame(); }
private void assertBoard(String expected) { assertEquals(expected, new Printer(board.getSize(), new MinesweeperPrinter(board)).toString()); }
private void unbombLeft() { board.getJoystick().act(); moveLeft(); }
private void unbombDown() { board.getJoystick().act(); moveDown(); }
private void unbombRight() { board.getJoystick().act(); moveRight(); }
private void moveLeft() { board.getJoystick().left(); board.tick(); }
private void unbombUp() { board.getJoystick().act(); moveUp(); }
private void assertStillNotWin() { assertFalse(board.isWin()); }
private void moveUp() { board.getJoystick().up(); board.tick(); }
private void assertWin() { assertTrue(board.isWin()); }