11package com .objectcomputing .checkins .services .memberprofile .memberphoto ;
22
33import 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 ;
47import io .micronaut .http .HttpRequest ;
58import io .micronaut .http .HttpResponse ;
69import io .micronaut .http .HttpStatus ;
710import io .micronaut .http .client .HttpClient ;
811import io .micronaut .http .client .annotation .Client ;
9- import io .micronaut .test .annotation .MockBean ;
1012import jakarta .inject .Inject ;
1113import org .junit .jupiter .api .Test ;
12- import org .junit .jupiter .api .condition .DisabledInNativeImage ;
1314
1415import java .util .Base64 ;
1516
1617import static com .objectcomputing .checkins .services .role .RoleType .Constants .MEMBER_ROLE ;
1718import static org .junit .jupiter .api .Assertions .assertEquals ;
1819import static org .junit .jupiter .api .Assertions .assertNotNull ;
1920import 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 )
2823class 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