1414import org .junit .jupiter .api .AfterAll ;
1515import org .junit .jupiter .api .BeforeAll ;
1616import org .junit .jupiter .api .Test ;
17- import org .junit .jupiter .api .condition .DisabledInNativeImage ;
18- import org .mockito .Mock ;
19- import org .mockito .MockitoAnnotations ;
2017
2118import java .util .HashMap ;
2219import java .util .List ;
2320import java .util .Map ;
2421
25- import static com .objectcomputing .checkins .services .memberprofile .MemberProfileTestUtil .mkMemberProfile ;
2622import static org .junit .jupiter .api .Assertions .assertEquals ;
2723import static org .junit .jupiter .api .Assertions .assertNotNull ;
28- import static org .mockito .Mockito .when ;
2924
30- // Disabled in nativeTest, as we get an exception from Mockito
31- // => java.lang.NoClassDefFoundError: Could not initialize class org.mockito.internal.configuration.plugins.Plugins
32- @ DisabledInNativeImage
3325class CurrentUserControllerTest extends TestContainersSuite implements MemberProfileFixture , RoleFixture {
3426
3527 private static final Map <String , Object > userAttributes = new HashMap <>();
36- private static final String firstName = "some.first.name" ;
37- private static final String lastName = "some.last.name" ;
38- private static final String userEmail = "some.email.address" ;
3928 private static final String imageUrl = "some.picture.url" ;
4029
41- @ Mock
42- CurrentUserServices currentUserServices ;
43-
4430 @ Inject
4531 CurrentUserController currentUserController ;
4632
47- private AutoCloseable mockFinalizer ;
48-
49- @ BeforeAll
50- void setupMocks () {
51- mockFinalizer = MockitoAnnotations .openMocks (this );
52- }
53-
54- @ AfterAll
55- void close () throws Exception {
56- mockFinalizer .close ();
57- }
58-
5933 @ Test
6034 void testCurrentUserReturnsUnauthorizedWhenAuthenticationFails () {
6135 HttpResponse <CurrentUserDTO > response = currentUserController .currentUser (null );
@@ -64,12 +38,14 @@ void testCurrentUserReturnsUnauthorizedWhenAuthenticationFails() {
6438
6539 @ Test
6640 void testCurrentUserReturnsValidDTO () {
41+ final MemberProfile expected = createADefaultMemberProfile ();
6742 Authentication auth = new Authentication () {
6843 @ NonNull
6944 @ Override
7045 public Map <String , Object > getAttributes () {
71- userAttributes .put ("name" , firstName + ' ' + lastName );
72- userAttributes .put ("email" , userEmail );
46+ userAttributes .put ("name" , expected .getFirstName () + ' ' +
47+ expected .getLastName ());
48+ userAttributes .put ("email" , expected .getWorkEmail ());
7349 userAttributes .put ("picture" , imageUrl );
7450 return userAttributes ;
7551 }
@@ -80,21 +56,14 @@ public String getName() {
8056 }
8157 };
8258
83- MemberProfile expected = mkMemberProfile ();
84- expected .setWorkEmail (userEmail );
85- expected .setFirstName (firstName );
86- expected .setLastName (lastName );
87-
88- when (currentUserServices .findOrSaveUser (firstName , lastName , userEmail )).thenReturn (expected );
89-
9059 HttpResponse <CurrentUserDTO > actual = currentUserController .currentUser (auth );
9160
9261 assertEquals (HttpStatus .OK , actual .getStatus ());
9362 CurrentUserDTO currentUserDTO = actual .body ();
9463 assertNotNull (currentUserDTO );
95- assertEquals (userEmail , currentUserDTO .getMemberProfile ().getWorkEmail ());
96- assertEquals (firstName , currentUserDTO .getFirstName ());
97- assertEquals (lastName , currentUserDTO .getLastName ());
64+ assertEquals (expected . getWorkEmail () , currentUserDTO .getMemberProfile ().getWorkEmail ());
65+ assertEquals (expected . getFirstName () , currentUserDTO .getFirstName ());
66+ assertEquals (expected . getLastName () , currentUserDTO .getLastName ());
9867 assertEquals (imageUrl , currentUserDTO .getImageUrl ());
9968 assertNotNull (actual .getHeaders ().get ("location" ));
10069 }
0 commit comments