1- import io .reactivex .Observable ;
2-
31import org .junit .jupiter .api .BeforeEach ;
42import org .junit .jupiter .api .Disabled ;
53import org .junit .jupiter .api .DisplayName ;
64import org .junit .jupiter .api .Test ;
75
6+ import java .util .List ;
7+
88import static org .junit .jupiter .api .Assertions .assertEquals ;
99import static org .junit .jupiter .api .Assertions .assertThrows ;
1010
@@ -20,9 +20,7 @@ public void init() {
2020 @ Test
2121 @ DisplayName ("Initially 9 failures are allowed and no letters are guessed" )
2222 void initially9FailuresAreAllowedAndNoLettersAreGuessed () {
23- Output result = hangman
24- .guess ("loot" , Observable .empty ())
25- .blockingLast ();
23+ Output result = hangman .guess ("loot" , List .of ());
2624
2725 assertEquals (Status .ON_GOING , result .state );
2826 assertEquals ("____" , result .maskedWord );
@@ -33,9 +31,10 @@ void initially9FailuresAreAllowedAndNoLettersAreGuessed() {
3331 @ Test
3432 @ DisplayName ("After 10 failures the game is over" )
3533 void after10FailuresTheGameIsOver () {
36- Output result = hangman
37- .guess ("loot" , Observable .fromArray ("a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" ))
38- .blockingLast ();
34+ Output result = hangman .guess (
35+ "loot" ,
36+ List .of ("a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" )
37+ );
3938
4039 assertEquals (Status .LOSE , result .state );
4140 assertEquals ("____" , result .maskedWord );
@@ -46,9 +45,10 @@ void after10FailuresTheGameIsOver() {
4645 @ Test
4746 @ DisplayName ("Losing with several correct guesses" )
4847 void losingWithSeveralCorrectGuesses () {
49- Output result = hangman
50- .guess ("loot" , Observable .fromArray ("t" , "o" , "a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" ))
51- .blockingLast ();
48+ Output result = hangman .guess (
49+ "loot" ,
50+ List .of ("t" , "o" , "a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" )
51+ );
5252
5353 assertEquals (Status .LOSE , result .state );
5454 assertEquals ("_oot" , result .maskedWord );
@@ -59,9 +59,7 @@ void losingWithSeveralCorrectGuesses() {
5959 @ Test
6060 @ DisplayName ("Feeding a correct letter removes underscores" )
6161 void feedingCorrectLetterRemovesUnderscores () {
62- Output result = hangman
63- .guess ("loot" , Observable .fromArray ("t" ))
64- .blockingLast ();
62+ Output result = hangman .guess ("loot" , List .of ("t" ));
6563
6664 assertEquals (Status .ON_GOING , result .state );
6765 assertEquals ("___t" , result .maskedWord );
@@ -72,9 +70,7 @@ void feedingCorrectLetterRemovesUnderscores() {
7270 @ Test
7371 @ DisplayName ("Feeding a correct letter twice counts as a failure" )
7472 void feedingCorrectLetterTwiceCountAsASuccess () {
75- Output result = hangman
76- .guess ("loot" , Observable .fromArray ("t" , "t" ))
77- .blockingLast ();
73+ Output result = hangman .guess ("loot" , List .of ("t" , "t" ));
7874
7975 assertEquals (Status .ON_GOING , result .state );
8076 assertEquals ("___t" , result .maskedWord );
@@ -85,9 +81,7 @@ void feedingCorrectLetterTwiceCountAsASuccess() {
8581 @ Test
8682 @ DisplayName ("Guessing a repeated letter reveals all instances" )
8783 void guessingARepeatedLetterRevealsAllInstances () {
88- Output result = hangman
89- .guess ("loot" , Observable .fromArray ("t" , "t" , "o" ))
90- .blockingLast ();
84+ Output result = hangman .guess ("loot" , List .of ("t" , "t" , "o" ));
9185
9286 assertEquals (Status .ON_GOING , result .state );
9387 assertEquals ("_oot" , result .maskedWord );
@@ -98,9 +92,7 @@ void guessingARepeatedLetterRevealsAllInstances() {
9892 @ Test
9993 @ DisplayName ("Getting all the letters right makes for a win" )
10094 void gettingAllTheLettersRightMakesForASuccess () {
101- Output result = hangman
102- .guess ("loot" , Observable .fromArray ("t" , "t" , "o" , "l" ))
103- .blockingLast ();
95+ Output result = hangman .guess ("loot" , List .of ("t" , "t" , "o" , "l" ));
10496
10597 assertEquals (Status .WIN , result .state );
10698 assertEquals ("loot" , result .maskedWord );
@@ -111,9 +103,10 @@ void gettingAllTheLettersRightMakesForASuccess() {
111103 @ Test
112104 @ DisplayName ("Winning on the last guess is still a win" )
113105 void winningOnTheLastGuessIsStillAWin () {
114- Output result = hangman
115- .guess ("loot" , Observable .fromArray ("a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "t" , "o" , "l" ))
116- .blockingLast ();
106+ Output result = hangman .guess (
107+ "loot" ,
108+ List .of ("a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "t" , "o" , "l" )
109+ );
117110
118111 assertEquals (Status .WIN , result .state );
119112 assertEquals ("loot" , result .maskedWord );
@@ -125,10 +118,11 @@ void winningOnTheLastGuessIsStillAWin() {
125118 @ DisplayName ("Guessing after a lose is error" )
126119 void guessingAfterALoseIsError () {
127120 IllegalStateException ex = assertThrows (
128- IllegalStateException .class ,
129- () -> hangman
130- .guess ("loot" , Observable .fromArray ("a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" , "k" ))
131- .blockingLast ()
121+ IllegalStateException .class ,
122+ () -> hangman .guess (
123+ "loot" ,
124+ List .of ("a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" , "k" )
125+ )
132126 );
133127
134128 assertEquals ("cannot guess after the game is lost" , ex .getMessage ());
@@ -139,12 +133,10 @@ void guessingAfterALoseIsError() {
139133 @ DisplayName ("Guessing after a win is error" )
140134 void guessingAfterAWinIsError () {
141135 IllegalStateException ex = assertThrows (
142- IllegalStateException .class ,
143- () -> hangman
144- .guess ("loot" , Observable .fromArray ("t" , "o" , "l" , "l" ))
145- .blockingLast ()
136+ IllegalStateException .class ,
137+ () -> hangman .guess ("loot" , List .of ("t" , "o" , "l" , "l" ))
146138 );
147139
148140 assertEquals ("cannot guess after the game is won" , ex .getMessage ());
149141 }
150- }
142+ }
0 commit comments