17
17
import org .mockito .InjectMocks ;
18
18
import org .mockito .Mock ;
19
19
import org .mockito .junit .jupiter .MockitoExtension ;
20
+ import org .springframework .mock .web .MockMultipartFile ;
20
21
import org .springframework .security .crypto .password .PasswordEncoder ;
21
22
import org .springframework .test .context .event .annotation .BeforeTestMethod ;
23
+ import org .springframework .web .multipart .MultipartFile ;
22
24
25
+ import com .ajou .hertz .common .file .service .FileService ;
23
26
import com .ajou .hertz .common .kakao .dto .response .KakaoUserInfoResponse ;
24
27
import com .ajou .hertz .common .properties .HertzProperties ;
25
28
import com .ajou .hertz .domain .user .constant .Gender ;
33
36
import com .ajou .hertz .domain .user .exception .UserPhoneDuplicationException ;
34
37
import com .ajou .hertz .domain .user .repository .UserRepository ;
35
38
import com .ajou .hertz .domain .user .service .UserCommandService ;
39
+ import com .ajou .hertz .domain .user .service .UserProfileImageCommandService ;
36
40
import com .ajou .hertz .domain .user .service .UserQueryService ;
37
41
import com .ajou .hertz .util .ReflectionUtils ;
38
42
@@ -55,6 +59,12 @@ class UserCommandServiceTest {
55
59
@ Mock
56
60
private HertzProperties hertzProperties ;
57
61
62
+ @ Mock
63
+ private FileService fileService ;
64
+
65
+ @ Mock
66
+ private UserProfileImageCommandService userProfileImageCommandService ;
67
+
58
68
@ BeforeTestMethod
59
69
public void setUp () {
60
70
given (hertzProperties .userDefaultProfileImageUrl ()).willReturn ("https://user-default-profile-image" );
@@ -172,6 +182,30 @@ static Stream<Arguments> testDataForCreateNewUserWithKakao() throws Exception {
172
182
assertThat (t ).isInstanceOf (UserKakaoUidDuplicationException .class );
173
183
}
174
184
185
+ @ Test
186
+ void 주어진_유저_ID와_이미지_URL로_유저의_프로필_이미지를_업데이트한다 () throws Exception {
187
+ // Given
188
+ Long userId = 1L ;
189
+ User user = createUser (userId , "password" , "kakaoUid" );
190
+ String newProfileImageUrl = "https://new-profile-image-url" ;
191
+
192
+ MultipartFile profileImage = new MockMultipartFile ("file" , "test.jpg" , "image/jpeg" ,
193
+ "test image content" .getBytes ());
194
+
195
+ given (userQueryService .getById (userId )).willReturn (user );
196
+ given (userProfileImageCommandService .updateProfileImage (user , profileImage )).willReturn (
197
+ newProfileImageUrl );
198
+
199
+ // When
200
+ UserDto result = sut .updateUserProfileImage (userId , profileImage );
201
+
202
+ // Then
203
+ then (userQueryService ).should ().getById (userId );
204
+ then (userProfileImageCommandService ).should ().updateProfileImage (user , profileImage );
205
+ assertThat (result .getProfileImageUrl ()).isEqualTo (newProfileImageUrl );
206
+ verifyEveryMocksShouldHaveNoMoreInteractions ();
207
+ }
208
+
175
209
@ Test
176
210
void 주어진_유저_ID와_연락_수단으로_연락_수단을_변경한다 () throws Exception {
177
211
// given
@@ -209,6 +243,8 @@ private void verifyEveryMocksShouldHaveNoMoreInteractions() {
209
243
then (userQueryService ).shouldHaveNoMoreInteractions ();
210
244
then (userRepository ).shouldHaveNoMoreInteractions ();
211
245
then (passwordEncoder ).shouldHaveNoMoreInteractions ();
246
+ then (fileService ).shouldHaveNoMoreInteractions ();
247
+ then (userProfileImageCommandService ).shouldHaveNoMoreInteractions ();
212
248
}
213
249
214
250
private static User createUser (Long id , String password , String kakaoUid , Gender gender ) throws Exception {
0 commit comments