44import static org .junit .jupiter .api .Assertions .*;
55import static org .mockito .ArgumentMatchers .any ;
66import static org .mockito .BDDMockito .given ;
7- import static org .mockito .Mockito .atLeastOnce ;
87import static org .mockito .Mockito .mock ;
98import static org .mockito .Mockito .never ;
10- import static org .mockito .Mockito .only ;
119import static org .mockito .Mockito .times ;
1210import static org .mockito .Mockito .verify ;
1311
2220import io .f1 .backend .domain .question .entity .Question ;
2321import io .f1 .backend .domain .user .dto .UserPrincipal ;
2422import io .f1 .backend .domain .user .entity .User ;
25- import java .lang .reflect .Field ;
26- import java .time .Instant ;
27- import java .time .LocalDateTime ;
28- import java .util .Collections ;
29- import java .util .concurrent .CountDownLatch ;
30- import java .util .concurrent .ExecutorService ;
31- import java .util .concurrent .Executors ;
32- import java .util .concurrent .TimeUnit ;
23+
3324import lombok .extern .slf4j .Slf4j ;
25+
3426import org .junit .jupiter .api .BeforeEach ;
3527import org .junit .jupiter .api .DisplayName ;
3628import org .junit .jupiter .api .Test ;
4234import org .springframework .context .ApplicationEventPublisher ;
4335import org .springframework .security .core .context .SecurityContextHolder ;
4436
37+ import java .lang .reflect .Field ;
38+ import java .time .Instant ;
39+ import java .time .LocalDateTime ;
40+ import java .util .Collections ;
41+ import java .util .concurrent .CountDownLatch ;
42+ import java .util .concurrent .ExecutorService ;
43+ import java .util .concurrent .Executors ;
44+
4545@ Slf4j
4646@ ExtendWith (MockitoExtension .class )
4747class ChatServiceTests {
@@ -61,7 +61,6 @@ void setUp() {
6161 SecurityContextHolder .clearContext ();
6262 }
6363
64-
6564 @ Test
6665 @ DisplayName ("정답이 아닐 때 이벤트가 발행되지 않는다." )
6766 void noEventWhenIncorrect () throws Exception {
@@ -111,7 +110,6 @@ void EventPublishedWhenCorrect() throws Exception {
111110
112111 // then
113112 verify (eventPublisher , times (1 )).publishEvent (any (GameCorrectAnswerEvent .class ));
114-
115113 }
116114
117115 @ Test
@@ -146,22 +144,24 @@ void onlyOneCorrectPlayerWhenConcurrentCorrectAnswers() throws Exception {
146144
147145 for (int i = 0 ; i < userCount ; i ++) {
148146 final int idx = i ;
149- executor .submit (() -> {
150- try {
151- User user = createUser (idx );
152- UserPrincipal principal = new UserPrincipal (user , Collections .emptyMap ());
153- chatService .chat (roomId , principal , msg );
154- } finally {
155- countDownLatch .countDown ();
156- }
157- });
147+ executor .submit (
148+ () -> {
149+ try {
150+ User user = createUser (idx );
151+ UserPrincipal principal =
152+ new UserPrincipal (user , Collections .emptyMap ());
153+ chatService .chat (roomId , principal , msg );
154+ } finally {
155+ countDownLatch .countDown ();
156+ }
157+ });
158158 }
159159
160160 countDownLatch .await ();
161161
162-
163162 // then: 이벤트는 단 1번만 발행돼야 함
164- ArgumentCaptor <GameCorrectAnswerEvent > captor = ArgumentCaptor .forClass (GameCorrectAnswerEvent .class );
163+ ArgumentCaptor <GameCorrectAnswerEvent > captor =
164+ ArgumentCaptor .forClass (GameCorrectAnswerEvent .class );
165165 verify (eventPublisher , times (1 )).publishEvent (captor .capture ());
166166
167167 GameCorrectAnswerEvent event = captor .getValue ();
@@ -173,31 +173,31 @@ void onlyOneCorrectPlayerWhenConcurrentCorrectAnswers() throws Exception {
173173 }
174174
175175 private Room createRoom (
176- Long roomId ,
177- Long playerId ,
178- Long quizId ,
179- String password ,
180- int maxUserCount ,
181- boolean locked ) {
176+ Long roomId ,
177+ Long playerId ,
178+ Long quizId ,
179+ String password ,
180+ int maxUserCount ,
181+ boolean locked ) {
182182 RoomSetting roomSetting = new RoomSetting ("방제목" , maxUserCount , locked , password );
183183 GameSetting gameSetting = new GameSetting (quizId , 10 , 60 );
184184 Player host = new Player (playerId , "nickname" );
185185
186186 return new Room (roomId , roomSetting , gameSetting , host );
187187 }
188-
188+
189189 private User createUser (int i ) {
190190 Long userId = i + 1L ;
191191 String provider = "provider +" + i ;
192192 String providerId = "providerId" + i ;
193193 LocalDateTime lastLogin = LocalDateTime .now ();
194194
195195 User user =
196- User .builder ()
197- .provider (provider )
198- .providerId (providerId )
199- .lastLogin (lastLogin )
200- .build ();
196+ User .builder ()
197+ .provider (provider )
198+ .providerId (providerId )
199+ .lastLogin (lastLogin )
200+ .build ();
201201
202202 try {
203203 Field idField = User .class .getDeclaredField ("id" );
@@ -209,5 +209,4 @@ private User createUser(int i) {
209209
210210 return user ;
211211 }
212-
213- }
212+ }
0 commit comments