Advertisement
JeffGrigg

Untitled

May 10th, 2023
2,668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.41 KB | None | 0 0
  1. import org.junit.Test;
  2.  
  3. public class GuessTheNumberTest {
  4.  
  5.     @Test
  6.     public void test() {
  7.         final var oldRandomNumberGenerator = GuessTheNumber._randomNumberGenerator;
  8.         GuessTheNumber._randomNumberGenerator = new MockRandomNumberGenerator(33);
  9.         try {
  10.             SystemInputOutputTester
  11.                     .whenCallingThisMethod(() -> {GuessTheNumber.main(null);})
  12.                     .assertTextOutput("Welcome to the number guessing program.")
  13.                     //
  14.                     .assertTextOutput("I am thinking of a number in the range of 1 to 100, inclusive.")
  15.                     .assertTextOutput("You need to guess this number, with a minimum number of guesses.")
  16.                     .assertTextOutput("Each time you guess, I will tell you if my number is HIGHER or LOWER than your guess.")
  17.                     //
  18.                     .assertTextOutput("What is your guess?")
  19.                     .provideLineInput("50")
  20.                     .assertTextOutput("Your guess of 50 is TOO HIGH.")
  21.                     //
  22.                     .assertTextOutput("What is your guess?")
  23.                     .provideLineInput("25")
  24.                     .assertTextOutput("Your guess of 25 is TOO LOW.")
  25.                     //
  26.                     .assertTextOutput("What is your guess?")
  27.                     .provideLineInput("37")
  28.                     .assertTextOutput("Your guess of 37 is TOO HIGH.")
  29.                     //
  30.                     .assertTextOutput("What is your guess?")
  31.                     .provideLineInput("31")
  32.                     .assertTextOutput("Your guess of 31 is TOO LOW.")
  33.                     //
  34.                     .assertTextOutput("What is your guess?")
  35.                     .provideLineInput("34")
  36.                     .assertTextOutput("Your guess of 34 is TOO HIGH.")
  37.                     //
  38.                     .assertTextOutput("What is your guess?")
  39.                     .provideLineInput("32")
  40.                     .assertTextOutput("Your guess of 32 is TOO LOW.")
  41.                     //
  42.                     .assertTextOutput("What is your guess?")
  43.                     .provideLineInput("33")
  44.                     .assertTextOutput("Your guess of 33 is CORRECT!")
  45.                     //
  46.                     .assertThatTheMethodReturnsHere();
  47.         } finally {
  48.             GuessTheNumber._randomNumberGenerator = oldRandomNumberGenerator;
  49.         }
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement