Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.junit.Test;
- public class GuessTheNumberTest {
- @Test
- public void test() {
- final var oldRandomNumberGenerator = GuessTheNumber._randomNumberGenerator;
- GuessTheNumber._randomNumberGenerator = new MockRandomNumberGenerator(33);
- try {
- SystemInputOutputTester
- .whenCallingThisMethod(() -> {GuessTheNumber.main(null);})
- .assertTextOutput("Welcome to the number guessing program.")
- //
- .assertTextOutput("I am thinking of a number in the range of 1 to 100, inclusive.")
- .assertTextOutput("You need to guess this number, with a minimum number of guesses.")
- .assertTextOutput("Each time you guess, I will tell you if my number is HIGHER or LOWER than your guess.")
- //
- .assertTextOutput("What is your guess?")
- .provideLineInput("50")
- .assertTextOutput("Your guess of 50 is TOO HIGH.")
- //
- .assertTextOutput("What is your guess?")
- .provideLineInput("25")
- .assertTextOutput("Your guess of 25 is TOO LOW.")
- //
- .assertTextOutput("What is your guess?")
- .provideLineInput("37")
- .assertTextOutput("Your guess of 37 is TOO HIGH.")
- //
- .assertTextOutput("What is your guess?")
- .provideLineInput("31")
- .assertTextOutput("Your guess of 31 is TOO LOW.")
- //
- .assertTextOutput("What is your guess?")
- .provideLineInput("34")
- .assertTextOutput("Your guess of 34 is TOO HIGH.")
- //
- .assertTextOutput("What is your guess?")
- .provideLineInput("32")
- .assertTextOutput("Your guess of 32 is TOO LOW.")
- //
- .assertTextOutput("What is your guess?")
- .provideLineInput("33")
- .assertTextOutput("Your guess of 33 is CORRECT!")
- //
- .assertThatTheMethodReturnsHere();
- } finally {
- GuessTheNumber._randomNumberGenerator = oldRandomNumberGenerator;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement