1616import io .f1 .backend .domain .user .entity .User ;
1717import io .f1 .backend .global .util .SecurityUtils ;
1818
19- import java .lang .reflect .Field ;
2019import lombok .extern .slf4j .Slf4j ;
2120
2221import org .junit .jupiter .api .AfterEach ;
3029import org .springframework .context .ApplicationEventPublisher ;
3130import org .springframework .security .core .context .SecurityContextHolder ;
3231
32+ import java .lang .reflect .Field ;
3333import java .time .LocalDateTime ;
3434import java .util .ArrayList ;
3535import java .util .Collections ;
@@ -45,24 +45,19 @@ class RoomServiceTests {
4545
4646 private RoomService roomService ;
4747
48- @ Mock
49- private RoomRepository roomRepository ;
50- @ Mock
51- private QuizService quizService ;
52- @ Mock
53- private TimerService timerService ;
54- @ Mock
55- private ApplicationEventPublisher eventPublisher ;
56- @ Mock
57- private MessageSender messageSender ;
48+ @ Mock private RoomRepository roomRepository ;
49+ @ Mock private QuizService quizService ;
50+ @ Mock private TimerService timerService ;
51+ @ Mock private ApplicationEventPublisher eventPublisher ;
52+ @ Mock private MessageSender messageSender ;
5853
5954 @ BeforeEach
6055 void setUp () {
6156 MockitoAnnotations .openMocks (this ); // @Mock 어노테이션이 붙은 필드들을 초기화합니다.
6257
6358 roomService =
64- new RoomService (
65- timerService , quizService , roomRepository , eventPublisher , messageSender );
59+ new RoomService (
60+ timerService , quizService , roomRepository , eventPublisher , messageSender );
6661
6762 SecurityContextHolder .clearContext ();
6863 }
@@ -95,17 +90,17 @@ void enterRoom_synchronized() throws Exception {
9590 User user = createUser (i );
9691
9792 executorService .submit (
98- () -> {
99- try {
100- SecurityUtils .setAuthentication (user );
101- roomService .enterRoom (roomValidationRequest );
102- } catch (Exception e ) {
103- e .printStackTrace ();
104- } finally {
105- SecurityContextHolder .clearContext ();
106- countDownLatch .countDown ();
107- }
108- });
93+ () -> {
94+ try {
95+ SecurityUtils .setAuthentication (user );
96+ roomService .enterRoom (roomValidationRequest );
97+ } catch (Exception e ) {
98+ e .printStackTrace ();
99+ } finally {
100+ SecurityContextHolder .clearContext ();
101+ countDownLatch .countDown ();
102+ }
103+ });
109104 }
110105 countDownLatch .await ();
111106 assertThat (room .getCurrentUserCnt ()).isEqualTo (room .getRoomSetting ().maxUserCount ());
@@ -156,32 +151,32 @@ void exitRoom_synchronized() throws Exception {
156151 String sessionId = "sessionId" + i ;
157152 User user = createUser (i );
158153 executorService .submit (
159- () -> {
160- try {
161- UserPrincipal principal =
162- new UserPrincipal (user , Collections .emptyMap ());
163- SecurityUtils .setAuthentication (user );
164- log .info ("room.getHost().getId() = {}" , room .getHost ().getId ());
165- roomService .exitRoom (roomId , sessionId , principal );
166- } catch (Exception e ) {
167- e .printStackTrace ();
168- } finally {
169- SecurityContextHolder .clearContext ();
170- countDownLatch .countDown ();
171- }
172- });
154+ () -> {
155+ try {
156+ UserPrincipal principal =
157+ new UserPrincipal (user , Collections .emptyMap ());
158+ SecurityUtils .setAuthentication (user );
159+ log .info ("room.getHost().getId() = {}" , room .getHost ().getId ());
160+ roomService .exitRoom (roomId , sessionId , principal );
161+ } catch (Exception e ) {
162+ e .printStackTrace ();
163+ } finally {
164+ SecurityContextHolder .clearContext ();
165+ countDownLatch .countDown ();
166+ }
167+ });
173168 }
174169 countDownLatch .await ();
175170 verify (roomRepository ).removeRoom (roomId );
176171 }
177172
178173 private Room createRoom (
179- Long roomId ,
180- Long playerId ,
181- Long quizId ,
182- String password ,
183- int maxUserCount ,
184- boolean locked ) {
174+ Long roomId ,
175+ Long playerId ,
176+ Long quizId ,
177+ String password ,
178+ int maxUserCount ,
179+ boolean locked ) {
185180 RoomSetting roomSetting = new RoomSetting ("방제목" , maxUserCount , locked , password );
186181 GameSetting gameSetting = new GameSetting (quizId , 10 , 60 );
187182 Player host = new Player (playerId , "nickname" );
@@ -196,11 +191,11 @@ private User createUser(int i) {
196191 LocalDateTime lastLogin = LocalDateTime .now ();
197192
198193 User user =
199- User .builder ()
200- .provider (provider )
201- .providerId (providerId )
202- .lastLogin (lastLogin )
203- .build ();
194+ User .builder ()
195+ .provider (provider )
196+ .providerId (providerId )
197+ .lastLogin (lastLogin )
198+ .build ();
204199
205200 try {
206201 Field idField = User .class .getDeclaredField ("id" );
0 commit comments