Skip to content

Commit daced47

Browse files
committed
Removed mockito from the MemberPhotoControllerTest.
1 parent 9b59314 commit daced47

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

server/src/test/java/com/objectcomputing/checkins/services/GooglePhotoAccessorImplReplacement.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public void setUserPhoto(String email, UserPhoto photo) {
2828
photos.put(email, photo);
2929
}
3030

31+
public void setPhotoData(String email, byte[] photoData) {
32+
UserPhoto photo = new UserPhoto();
33+
photo.setPhotoData(new String(photoData));
34+
photos.put(email, photo);
35+
}
36+
3137
@Override
3238
public byte[] getPhotoData(String workEmail) {
3339
UserPhoto photo = photos.get(workEmail);
Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,41 @@
11
package com.objectcomputing.checkins.services.memberprofile.memberphoto;
22

33
import com.objectcomputing.checkins.services.TestContainersSuite;
4+
import com.objectcomputing.checkins.services.GooglePhotoAccessorImplReplacement;
5+
import io.micronaut.core.util.StringUtils;
6+
import io.micronaut.context.annotation.Property;
47
import io.micronaut.http.HttpRequest;
58
import io.micronaut.http.HttpResponse;
69
import io.micronaut.http.HttpStatus;
710
import io.micronaut.http.client.HttpClient;
811
import io.micronaut.http.client.annotation.Client;
9-
import io.micronaut.test.annotation.MockBean;
1012
import jakarta.inject.Inject;
1113
import org.junit.jupiter.api.Test;
12-
import org.junit.jupiter.api.condition.DisabledInNativeImage;
1314

1415
import java.util.Base64;
1516

1617
import static com.objectcomputing.checkins.services.role.RoleType.Constants.MEMBER_ROLE;
1718
import static org.junit.jupiter.api.Assertions.assertEquals;
1819
import static org.junit.jupiter.api.Assertions.assertNotNull;
1920
import static org.junit.jupiter.api.Assertions.assertTrue;
20-
import static org.mockito.Mockito.mock;
21-
import static org.mockito.Mockito.times;
22-
import static org.mockito.Mockito.verify;
23-
import static org.mockito.Mockito.when;
2421

25-
// Disabled in nativeTest, as we get an exception from Mockito
26-
// => Message: Could not initialize class org.mockito.Mockito
27-
@DisabledInNativeImage
22+
@Property(name = "replace.googlephotoaccessorimpl", value = StringUtils.TRUE)
2823
class MemberPhotoControllerTest extends TestContainersSuite {
2924

3025
@Inject
3126
@Client("/services/member-profiles/member-photos")
3227
private HttpClient client;
3328

3429
@Inject
35-
GooglePhotoAccessor googlePhotoAccessor;
30+
GooglePhotoAccessorImplReplacement googlePhotoAccessor;
3631

3732
@Test
3833
void testGetForValidInput() {
3934

4035
String testEmail = "[email protected]";
41-
byte[] testData = Base64.getUrlEncoder().encode("test.photo.data".getBytes());
42-
43-
when(googlePhotoAccessor.getPhotoData(testEmail)).thenReturn(testData);
36+
String testPhotoData = "test.photo.data";
37+
byte[] testData = Base64.getUrlEncoder().encode(testPhotoData.getBytes());
38+
googlePhotoAccessor.setPhotoData(testEmail, testData);
4439

4540
final HttpRequest<?> request = HttpRequest.GET(String.format("/%s", testEmail)).basicAuth(MEMBER_ROLE, MEMBER_ROLE);
4641
final HttpResponse<byte[]> response = client.toBlocking().exchange(request, byte[].class);
@@ -51,14 +46,6 @@ void testGetForValidInput() {
5146
assertEquals(HttpStatus.OK, response.getStatus());
5247
assertTrue(response.getBody().isPresent());
5348
byte[] result = response.getBody().get();
54-
assertEquals(new String(testData), new String(result));
55-
56-
// Only called once due to the cache
57-
verify(googlePhotoAccessor, times(1)).getPhotoData(testEmail);
58-
}
59-
60-
@MockBean(GooglePhotoAccessorImpl.class)
61-
public GooglePhotoAccessor googlePhotoAccessor() {
62-
return mock(GooglePhotoAccessor.class);
49+
assertEquals(new String(testPhotoData), new String(result));
6350
}
6451
}

0 commit comments

Comments
 (0)