Skip to content

Commit

Permalink
improve unit test to cover exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
amanda-ariyaratne committed Oct 22, 2024
1 parent 2ec83d7 commit 5f9674d
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
Expand Down Expand Up @@ -2876,14 +2877,20 @@ public void testInitiateOIDCScopes(List<ScopeDTO> scopeClaimsList, List<External
when(mockServiceComponentHolder.getClaimMetadataManagementService()).thenReturn(claimService);
when(claimService.getExternalClaims(OIDC_DIALECT, SUPER_TENANT_DOMAIN_NAME)).thenReturn(oidcDialectClaims);
when(mockServiceComponentHolder.getOIDCScopesClaims()).thenReturn(scopeClaimsList);
ClaimMetadataException claimMetadataException = new ClaimMetadataException("error");
doThrow(claimMetadataException)
.when(claimService)
.updateExternalClaim(oidcDialectClaims.get(0), SUPER_TENANT_DOMAIN_NAME);

OAuth2Util.initiateOIDCScopes(SUPER_TENANT_ID);
verify(scopeClaimMappingDAO, times(1))
.initScopeClaimMapping(SUPER_TENANT_ID, scopeClaimsList);
verify(claimService, times(4)).updateExternalClaim(any(), anyString());
verify(log, times(1)).error(
"Error updating OIDC claim: " + oidcDialectClaims.get(0).getClaimURI(),
claimMetadataException);
clearInvocations(log);

ClaimMetadataException claimMetadataException = new ClaimMetadataException("error");
when(claimService.getExternalClaims(OIDC_DIALECT, SUPER_TENANT_DOMAIN_NAME))
.thenThrow(claimMetadataException);
OAuth2Util.initiateOIDCScopes(SUPER_TENANT_ID);
Expand Down

0 comments on commit 5f9674d

Please sign in to comment.