1+ package org .tuna .zoopzoop .backend .domain .space .membership .service ;
2+
3+ import org .junit .jupiter .api .DisplayName ;
4+ import org .junit .jupiter .api .Test ;
5+ import org .junit .jupiter .api .extension .ExtendWith ;
6+ import org .mockito .InjectMocks ;
7+ import org .mockito .Mock ;
8+ import org .mockito .junit .jupiter .MockitoExtension ;
9+ import org .springframework .boot .test .context .SpringBootTest ;
10+ import org .springframework .test .context .ActiveProfiles ;
11+ import org .springframework .transaction .annotation .Transactional ;
12+ import org .tuna .zoopzoop .backend .domain .SSE .service .EmitterService ;
13+
14+ import static org .mockito .Mockito .times ;
15+ import static org .mockito .Mockito .verify ;
16+
17+ @ ActiveProfiles ("test" )
18+ @ SpringBootTest
19+ @ Transactional
20+ @ ExtendWith (MockitoExtension .class )
21+ class NotificationServiceTest {
22+ @ Mock
23+ private EmitterService emitterService ;
24+
25+ @ InjectMocks
26+ private NotificationService notificationService ;
27+
28+ @ Test
29+ @ DisplayName ("초대 알림 전송 시 EmitterService의 sendNotification이 올바르게 호출됨" )
30+ void sendSpaceInvitation_CallsEmitterService () {
31+ // given (준비)
32+ Long memberId = 1L ;
33+ String testData = "test data" ;
34+
35+ // when (실행)
36+ notificationService .sendSpaceInvitation (memberId , testData );
37+
38+ // then (검증)
39+ // EmitterService의 sendNotification 메소드가
40+ // memberId, "space-invitation", testData 파라미터로
41+ // 1번 호출되었는지 검증
42+ verify (emitterService , times (1 )).sendNotification (memberId , "space-invitation" , testData );
43+ }
44+
45+ }
0 commit comments