1919import org .junit .jupiter .api .Test ;
2020import org .mockito .InjectMocks ;
2121import org .mockito .Mock ;
22- import org .testfx .util .WaitForAsyncUtils ;
2322import reactor .core .publisher .Flux ;
2423
2524import java .util .Map ;
@@ -61,11 +60,7 @@ public void setUp() throws Exception {
6160 playerInfo = PlayerInfoBuilder .create ()
6261 .defaultValues ()
6362 .game (null )
64- .leaderboardRatings (LeaderboardRatingMapBuilder .create ()
65- .put (leaderboard .technicalName (),
66- Instancio .create (
67- LeaderboardRating .class ))
68- .get ())
63+ .leaderboardRatings (generateRandomLeaderboardRatingMap (leaderboard ))
6964 .get ();
7065 player = new SimpleObjectProperty <>(playerInfo );
7166 instance .playerProperty ().bind (player );
@@ -91,6 +86,12 @@ public void setUp() throws Exception {
9186 });
9287 }
9388
89+ private Map <String , LeaderboardRating > generateRandomLeaderboardRatingMap (Leaderboard leaderboard ) {
90+ return LeaderboardRatingMapBuilder .create ()
91+ .put (leaderboard .technicalName (), Instancio .create (LeaderboardRating .class ))
92+ .get ();
93+ }
94+
9495 @ Test
9596 public void testCheckGameInfoForIdlePlayer () {
9697 assertTrue (instance .userImageView .isVisible ());
@@ -126,15 +127,11 @@ public void testCheckGameInfoPlayerNoGameThenJoinsGame() {
126127 }
127128
128129 @ Test
129- public void testSetChatUserLeavesGame () {
130- runOnFxThreadAndWait (() -> instance .playerProperty ().setValue (playerInfo ));
131- playerInfo .setGame (GameInfoBuilder .create ().defaultValues ().get ());
132- WaitForAsyncUtils .waitForFxEvents ();
133-
130+ public void testCheckGameInfoIfPlayerLeavesGame () {
131+ runOnFxThreadAndWait (() -> playerInfo .setGame (GameInfoBuilder .create ().defaultValues ().get ()));
134132 assertTrue (instance .gameDetailWrapper .isVisible ());
135133
136- playerInfo .setGame (null );
137-
134+ runOnFxThreadAndWait (() -> playerInfo .setGame (null ));
138135 assertFalse (instance .gameDetailWrapper .isVisible ());
139136 }
140137
@@ -146,7 +143,7 @@ public void testRatingChange() {
146143 }
147144
148145 @ Test
149- public void testSetChatUserWithNoPlayer () {
146+ public void testCheckGameInfoIfPlayerIsNull () {
150147 runOnFxThreadAndWait (() -> player .setValue (null ));
151148
152149 assertFalse (instance .userImageView .isVisible ());
@@ -160,7 +157,7 @@ public void testSetChatUserWithNoPlayer() {
160157 }
161158
162159 @ Test
163- public void testSetChatUserWithNoPlayerThenGetsPlayer () {
160+ public void testCheckGameInfoWhenPlayerIsNullThenNewPlayerAppears () {
164161 runOnFxThreadAndWait (() -> player .setValue (null ));
165162
166163 assertFalse (instance .userImageView .isVisible ());
@@ -172,11 +169,11 @@ public void testSetChatUserWithNoPlayerThenGetsPlayer() {
172169 assertFalse (instance .unlockedAchievements .isVisible ());
173170 assertFalse (instance .unlockedAchievementsLabel .isVisible ());
174171
175- playerInfo . setLeaderboardRatings ( LeaderboardRatingMapBuilder .create ()
176- .put ( leaderboard . technicalName (),
177- Instancio . create ( LeaderboardRating . class ))
178- . get ());
179- runOnFxThreadAndWait (() -> player . setValue ( playerInfo ));
172+ runOnFxThreadAndWait (() -> player . setValue ( PlayerInfoBuilder .create ()
173+ .defaultValues ()
174+ . leaderboardRatings (
175+ generateRandomLeaderboardRatingMap ( leaderboard ))
176+ . get () ));
180177
181178 assertTrue (instance .userImageView .isVisible ());
182179 assertTrue (instance .country .isVisible ());
0 commit comments