22
33import static org .assertj .core .api .Assertions .assertThat ;
44import static org .mockito .ArgumentMatchers .any ;
5+ import static org .mockito .Mockito .doReturn ;
56import static org .mockito .Mockito .verify ;
67import static org .mockito .Mockito .when ;
78import java .time .Instant ;
@@ -96,7 +97,7 @@ void shouldUpdateLastActivityDate() {
9697 // Given
9798 Date beforeLogin = testUser .getLastActivityDate ();
9899 when (loginAttemptService .checkIfUserShouldBeUnlocked (any (User .class ))).thenAnswer (invocation -> invocation .getArgument (0 ));
99- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
100+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
100101
101102 // When
102103 DSUserDetails result = loginHelperService .userLoginHelper (testUser );
@@ -122,7 +123,7 @@ void shouldCheckUserUnlockStatus() {
122123 unlockedUser .setLockedDate (null );
123124
124125 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (unlockedUser );
125- when (authorityService .getAuthoritiesFromUser (unlockedUser )). thenReturn (( Collection ) testAuthorities );
126+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (unlockedUser );
126127
127128 // When
128129 DSUserDetails result = loginHelperService .userLoginHelper (testUser );
@@ -138,7 +139,7 @@ void shouldCheckUserUnlockStatus() {
138139 void shouldCreateUserDetailsWithAuthorities () {
139140 // Given
140141 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser );
141- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
142+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
142143
143144 // When
144145 DSUserDetails result = loginHelperService .userLoginHelper (testUser );
@@ -178,7 +179,7 @@ void shouldHandleLockedUserThatRemainsLocked() {
178179 testUser .setLockedDate (lockedDate );
179180
180181 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser ); // User remains locked
181- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
182+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
182183
183184 // When
184185 DSUserDetails result = loginHelperService .userLoginHelper (testUser );
@@ -196,7 +197,7 @@ void shouldHandleDisabledUser() {
196197 // Given
197198 testUser .setEnabled (false );
198199 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser );
199- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
200+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
200201
201202 // When
202203 DSUserDetails result = loginHelperService .userLoginHelper (testUser );
@@ -217,7 +218,7 @@ void shouldPreserveUserStateDuringProcess() {
217218 // Note: imageUrl and usingMfa fields don't exist in User class
218219
219220 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser );
220- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
221+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
221222
222223 // When
223224 DSUserDetails result = loginHelperService .userLoginHelper (testUser );
@@ -253,7 +254,7 @@ void shouldAutomaticallyUnlockUserAfterDuration() {
253254 unlockedUser .setEnabled (true );
254255
255256 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (unlockedUser );
256- when (authorityService .getAuthoritiesFromUser (unlockedUser )). thenReturn (( Collection ) testAuthorities );
257+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (unlockedUser );
257258
258259 // When
259260 DSUserDetails result = loginHelperService .userLoginHelper (testUser );
@@ -271,7 +272,7 @@ void shouldTrackTimingOfLastActivityUpdate() {
271272 // Given
272273 Date testStartTime = new Date ();
273274 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser );
274- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
275+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
275276
276277 // When
277278 DSUserDetails result = loginHelperService .userLoginHelper (testUser );
@@ -359,7 +360,7 @@ void shouldCreateCompleteUserDetails() {
359360 testUser .setLastName ("User" );
360361
361362 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser );
362- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
363+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
363364
364365 // When
365366 DSUserDetails result = loginHelperService .userLoginHelper (testUser );
@@ -383,7 +384,7 @@ void shouldHandleOAuth2User() {
383384 testUser .setPassword (null ); // OAuth2 users don't have passwords
384385
385386 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser );
386- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
387+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
387388
388389 // When
389390 DSUserDetails result = loginHelperService .userLoginHelper (testUser );
@@ -407,7 +408,7 @@ void shouldHandleNullLastActivityDate() {
407408 testUser .setLastActivityDate (null );
408409
409410 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser );
410- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
411+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
411412
412413 // When
413414 DSUserDetails result = loginHelperService .userLoginHelper (testUser );
@@ -422,7 +423,7 @@ void shouldHandleNullLastActivityDate() {
422423 void shouldHandleRapidSuccessiveLogins () {
423424 // Given
424425 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser );
425- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
426+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
426427
427428 // When - Simulate rapid successive logins
428429 DSUserDetails result1 = loginHelperService .userLoginHelper (testUser );
@@ -459,7 +460,7 @@ void shouldPassOAuth2AttributesToDSUserDetails() {
459460 providerAttrs .put ("picture" , "https://example.com/photo.jpg" );
460461
461462 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser );
462- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
463+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
463464
464465 // When
465466 DSUserDetails result = loginHelperService .userLoginHelper (testUser , providerAttrs );
@@ -477,7 +478,7 @@ void shouldPassOAuth2AttributesToDSUserDetails() {
477478 void shouldFallBackWhenOAuth2AttributesNull () {
478479 // Given
479480 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser );
480- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
481+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
481482
482483 // When
483484 DSUserDetails result = loginHelperService .userLoginHelper (testUser );
@@ -503,7 +504,7 @@ void shouldPassOidcAttributesToDSUserDetails() {
503504 providerAttrs .put ("extra_claim" , "extra_value" );
504505
505506 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser );
506- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
507+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
507508
508509 // When
509510 DSUserDetails result = loginHelperService .userLoginHelper (testUser , userInfo , idToken , providerAttrs );
@@ -528,7 +529,7 @@ void shouldFallBackToIdTokenClaimsWhenOidcAttributesNull() {
528529 OidcUserInfo userInfo = new OidcUserInfo (Map .of ("sub" , "oidc-sub-123" ));
529530
530531 when (loginAttemptService .checkIfUserShouldBeUnlocked (testUser )).thenReturn (testUser );
531- when (authorityService .getAuthoritiesFromUser (testUser )). thenReturn (( Collection ) testAuthorities );
532+ doReturn ( testAuthorities ). when (authorityService ) .getAuthoritiesFromUser (testUser );
532533
533534 // When
534535 DSUserDetails result = loginHelperService .userLoginHelper (testUser , userInfo , idToken );
0 commit comments