コード例 #1
0
  @Test
  public void testGetSticksInputWith2()
      throws IOException, NumberFormatException, NumberIsOutsideRangeException {
    when(in.readLine()).thenReturn("2");

    assertEquals(2, sut.getStickInput());
  }
コード例 #2
0
 @Test
 public void testDisplayGameInstructions() {
   sut.displayGameInstructions();
   verify(out)
       .println(
           "The game is called 21 sticks. Your goal is to not take the last stick. You take a number of sticks, between 1 and 3, and the other player does the same. The player tha takes the last one loses.");
 }
コード例 #3
0
  @Test
  public void testGetSticksPrintsInstructions() throws IOException, NumberIsOutsideRangeException {
    try {
      sut.getStickInput();
    } catch (NumberFormatException e) {
    }

    verify(out).print("Please write the number of sticks to take, between 1 and 3: ");
  }
コード例 #4
0
 @Test(expected = NumberIsOutsideRangeException.class)
 public void testGetSticksInputWithInputSmallerThan0()
     throws IOException, NumberIsOutsideRangeException {
   when(in.readLine()).thenReturn("-1");
   sut.getStickInput();
 }
コード例 #5
0
 @Test(expected = NumberFormatException.class)
 public void testGetSticksInputWithInputThatIsNotANumberShouldThrowNumberFormatException()
     throws IOException, NumberIsOutsideRangeException {
   when(in.readLine()).thenReturn("x");
   sut.getStickInput();
 }
コード例 #6
0
 @Test
 public void testDisplayQuitMessage() {
   sut.displayQuitMessage();
   verify(out).println("You are now quitting the game. Have a good day!");
 }
コード例 #7
0
 @Test
 public void testDisplayStartMessage() {
   sut.displayStartMessage();
   verify(out).println("Welcome to the 21 sticks game!");
 }
コード例 #8
0
 @Test
 public void testReadInputReturnY() throws IOException {
   when(in.readLine()).thenReturn("y");
   assertEquals("y", sut.getInput());
 }
コード例 #9
0
 @Test
 public void testDisplaySticksLeft() {
   sut.displaySticksLeft(5);
   verify(out).println("There are 5 sticks left.");
 }
コード例 #10
0
 @Test
 public void testDispayStartInstructions() {
   sut.displayStartInstructions();
   verify(out).print("To begin the game write 'y', and to quit write 'Q': ");
 }