1
+ package gdsc .konkuk .platformcore .application .member ;
2
+
3
+ import gdsc .konkuk .platformcore .application .member .exceptions .UserNotFoundException ;
4
+ import gdsc .konkuk .platformcore .domain .member .repository .MemberRepository ;
5
+ import gdsc .konkuk .platformcore .fixture .member .MemberFixture ;
6
+ import org .junit .jupiter .api .BeforeEach ;
7
+ import org .junit .jupiter .api .DisplayName ;
8
+ import org .junit .jupiter .api .Test ;
9
+ import org .junit .jupiter .api .function .Executable ;
10
+ import org .mockito .Mock ;
11
+ import org .mockito .MockitoAnnotations ;
12
+
13
+ import java .util .List ;
14
+ import java .util .Optional ;
15
+
16
+ import static org .junit .jupiter .api .Assertions .*;
17
+ import static org .mockito .ArgumentMatchers .any ;
18
+ import static org .mockito .BDDMockito .given ;
19
+
20
+
21
+ class MemberFinderTest {
22
+
23
+ private MemberFinder subject ;
24
+
25
+ @ Mock
26
+ private MemberRepository memberRepository ;
27
+
28
+ @ BeforeEach
29
+ void setUp () {
30
+ MockitoAnnotations .openMocks (this );
31
+ subject = new MemberFinder (memberRepository );
32
+ }
33
+
34
+ @ DisplayName ("fetchMemberById : 해당하는 멤버가 없으면 UserNotFoundException 발생" )
35
+ @ Test
36
+ void should_throw_UserNotFoundException_when_member_not_found () {
37
+ // given
38
+ Long memberId = 1L ;
39
+ given (memberRepository .findById (any (Long .class ))).willReturn (Optional .empty ());
40
+
41
+ // when
42
+ Executable actual = () -> subject .fetchMemberById (memberId );
43
+
44
+ // then
45
+ assertThrows (UserNotFoundException .class , actual );
46
+ }
47
+
48
+ @ DisplayName ("fetchMemberByIdsAndBatch : 실제 조회된 유저수와 요청한 유저수가 다르면 UserNotFoundException 발생" )
49
+ @ Test
50
+ void should_throw_UserNotFoundException_when_member_count_not_match () {
51
+ // given
52
+ final List <Long > memberIds = List .of (1L , 2L , 3L );
53
+ final String batch = "24-25" ;
54
+ given (memberRepository .findAllByIdsAndBatch (any (), any ())).willReturn (
55
+ List .of (
56
+ MemberFixture .builder ().batch (batch ).build ().getFixture (),
57
+ MemberFixture .builder ().batch (batch ).build ().getFixture ()));
58
+ // when
59
+ Executable actual = () -> subject .fetchMembersByIdsAndBatch (memberIds , batch );
60
+ // then
61
+ assertThrows (UserNotFoundException .class , actual );
62
+ }
63
+ }
0 commit comments