1+ package com .somemore .interestcenter .handler ;
2+
3+ import com .somemore .IntegrationTestSupport ;
4+ import com .somemore .global .common .event .ServerEventPublisher ;
5+ import com .somemore .interestcenter .event .InterestCenterCreateRecruitBoardEvent ;
6+ import com .somemore .interestcenter .usecase .InterestCenterQueryUseCase ;
7+ import com .somemore .interestcenter .usecase .RegisterInterestCenterUseCase ;
8+ import com .somemore .recruitboard .event .CreateRecruitBoardEvent ;
9+ import org .junit .jupiter .api .Test ;
10+ import org .mockito .Mockito ;
11+ import org .springframework .beans .factory .annotation .Autowired ;
12+ import org .springframework .boot .test .mock .mockito .MockBean ;
13+ import org .springframework .transaction .annotation .Transactional ;
14+
15+ import java .util .List ;
16+ import java .util .UUID ;
17+
18+ import static org .mockito .ArgumentMatchers .argThat ;
19+ import static org .mockito .Mockito .times ;
20+ import static org .mockito .Mockito .verify ;
21+ import static org .mockito .Mockito .when ;
22+
23+ @ Transactional
24+ class CreateRecruitBoardHandlerImplTest extends IntegrationTestSupport {
25+
26+ @ Autowired
27+ private CreateRecruitBoardHandlerImpl createRecruitBoardHandler ;
28+
29+ @ Autowired
30+ private RegisterInterestCenterUseCase registerInterestCenterUseCase ;
31+
32+ @ MockBean
33+ private InterestCenterQueryUseCase interestCenterQueryUseCase ;
34+
35+ @ MockBean
36+ private ServerEventPublisher serverEventPublisher ;
37+
38+ @ Test
39+ void handle_ShouldPublishEventsForVolunteers () {
40+ // given
41+ UUID centerId = UUID .randomUUID ();
42+ UUID volunteerId1 = UUID .randomUUID ();
43+ UUID volunteerId2 = UUID .randomUUID ();
44+ UUID volunteerId3 = UUID .randomUUID ();
45+ Long recruitBoardId = 123L ;
46+
47+ List <UUID > volunteerIds = List .of (volunteerId1 , volunteerId2 , volunteerId3 );
48+ when (interestCenterQueryUseCase .getVolunteerIdsByCenterId (centerId )).thenReturn (volunteerIds );
49+
50+ CreateRecruitBoardEvent createRecruitBoardEvent = CreateRecruitBoardEvent .builder ()
51+ .centerId (centerId )
52+ .recruitBoardId (recruitBoardId )
53+ .build ();
54+
55+ // when
56+ createRecruitBoardHandler .handle (createRecruitBoardEvent );
57+
58+ // then
59+ verify (serverEventPublisher , times (volunteerIds .size ())).publish (Mockito .any (InterestCenterCreateRecruitBoardEvent .class ));
60+
61+ for (UUID volunteerId : volunteerIds ) {
62+ verify (serverEventPublisher ).publish (argThat (event ->
63+ event instanceof InterestCenterCreateRecruitBoardEvent &&
64+ ((InterestCenterCreateRecruitBoardEvent ) event ).getCenterId ().equals (centerId ) &&
65+ ((InterestCenterCreateRecruitBoardEvent ) event ).getVolunteerId ().equals (volunteerId ) &&
66+ ((InterestCenterCreateRecruitBoardEvent ) event ).getRecruitBoardId ().equals (recruitBoardId )
67+ ));
68+ }
69+ }
70+ }
0 commit comments