diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/group/SCIMGroupHandlerTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/group/SCIMGroupHandlerTest.java index 089989df0..ec8cabee0 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/group/SCIMGroupHandlerTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/group/SCIMGroupHandlerTest.java @@ -18,7 +18,6 @@ package org.wso2.carbon.identity.scim2.common.group; -import org.apache.commons.lang.StringUtils; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockedConstruction; @@ -75,7 +74,6 @@ public class SCIMGroupHandlerTest { private MockedStatic scimCommonUtils; private MockedStatic identityDatabaseUtil; private MockedStatic identityTenantUtil; - private MockedStatic stringUtils; @BeforeMethod public void setUp() { @@ -84,7 +82,6 @@ public void setUp() { scimCommonUtils = mockStatic(SCIMCommonUtils.class); identityDatabaseUtil = mockStatic(IdentityDatabaseUtil.class); identityTenantUtil = mockStatic(IdentityTenantUtil.class); - stringUtils = mockStatic(StringUtils.class); } @AfterMethod @@ -92,7 +89,6 @@ public void tearDown() throws Exception { scimCommonUtils.close(); identityDatabaseUtil.close(); identityTenantUtil.close(); - stringUtils.close(); } @Test @@ -181,13 +177,12 @@ public void testGetGroupName() throws Exception { when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection); when(connection.prepareStatement(anyString())).thenReturn(mockedPreparedStatement); - when(StringUtils.isNotEmpty(nullable(String.class))).thenReturn(true); when(SCIMCommonUtils.getPrimaryFreeGroupName(nullable(String.class))).thenReturn("directors"); when(mockedPreparedStatement.executeQuery()).thenReturn(resultSet); when(mockedGroupDAO.getGroupNameById(1, "5")).thenReturn("directors"); + when(resultSet.next()).thenReturn(true).thenReturn(false); + when(resultSet.getString(1)).thenReturn("roleName"); assertEquals(new SCIMGroupHandler(1).getGroupName("5"), "directors", "asserting for existance"); - - when(StringUtils.isNotEmpty(nullable(String.class))).thenReturn(false); assertNull(new SCIMGroupHandler(1).getGroupName("NON_EXISITNG_GROUP_NAME"), "asserting for non existance"); } diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManagerTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManagerTest.java index 707c19912..07390bdd8 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManagerTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManagerTest.java @@ -110,7 +110,14 @@ import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockConstruction; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -362,7 +369,7 @@ public Object[][] groupName() throws Exception { @Test(dataProvider = "getGroupException") public void testGetGroupWithExceptions(String roleName, String userStoreDomain) throws Exception { - AbstractUserStoreManager mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class); + AbstractUserStoreManager mockedUserStoreManager = mock(AbstractUserStoreManager.class); Field field = AbstractUserStoreManager.class.getDeclaredField("userStoreManagerHolder"); field.setAccessible(true); field.set(mockedUserStoreManager, new HashMap()); @@ -423,7 +430,7 @@ public void testListGroupsWithFilter(String filter, String roleName, String user mockedUserStoreManager = mock(AbstractUserStoreManager.class); - AbstractUserStoreManager mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class); + AbstractUserStoreManager mockedUserStoreManager = mock(AbstractUserStoreManager.class); Field field = AbstractUserStoreManager.class.getDeclaredField("userStoreManagerHolder"); field.setAccessible(true); field.set(mockedUserStoreManager, new HashMap()); @@ -1450,7 +1457,7 @@ public void testGetUserWhenSCIMisDisabled() throws Exception { scimToLocalClaimsMap.put(SCIMConstants.CommonSchemaConstants.ID_URI, USERID_LOCAL_CLAIM); when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap); - mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class); + mockedUserStoreManager = mock(AbstractUserStoreManager.class); SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager, mockClaimMetadataManagementService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); org.wso2.carbon.user.core.common.User user = mock(org.wso2.carbon.user.core.common.User.class); @@ -1485,7 +1492,7 @@ public void testDeleteUserWithInvalidUserId() throws Exception { List coreUsers = new ArrayList<>(); when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap); - AbstractUserStoreManager mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class); + AbstractUserStoreManager mockedUserStoreManager = mock(AbstractUserStoreManager.class); when(mockedUserStoreManager.getUserListWithID(anyString(), anyString(), anyString())).thenReturn(coreUsers); SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager, mockClaimMetadataManagementService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); @@ -1507,7 +1514,7 @@ public void testDeleteUserWhenSCIMisDisabled() throws Exception { coreUser.setUserStoreDomain("DomainName"); when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap); - AbstractUserStoreManager mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class); + AbstractUserStoreManager mockedUserStoreManager = mock(AbstractUserStoreManager.class); when(mockedUserStoreManager.getUserWithID(anyString(), any(), anyString())).thenReturn(coreUser); when(mockedUserStoreManager.getSecondaryUserStoreManager("DomainName")).thenReturn(mockedUserStoreManager); when(mockedUserStoreManager.isSCIMEnabled()).thenReturn(false); @@ -1530,7 +1537,7 @@ public void testDeleteUserWithUserStoreDomainMismatch() throws Exception { coreUser.setUserStoreDomain("PRIMARY"); when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap); - AbstractUserStoreManager mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class); + AbstractUserStoreManager mockedUserStoreManager = mock(AbstractUserStoreManager.class); when(mockedUserStoreManager.getUserWithID(anyString(), any(), anyString())).thenReturn(coreUser); SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager, mockClaimMetadataManagementService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); @@ -1585,7 +1592,7 @@ public void testCreateUserWhenSCIMisDisabled() throws Exception { SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager, mockClaimMetadataManagementService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); doThrow(new NotImplementedException()).when(mockedUser).setSchemas(Mockito.any(UserManager.class)); - mockedUser.setSchemas(Mockito.mock(UserManager.class)); + mockedUser.setSchemas(mock(UserManager.class)); scimUserManager.createUser(user, null); // This method is for testing of throwing CharonException, hence no assertion. } @@ -1616,7 +1623,7 @@ public void testCreateUserWithExistingUserName(String isLoginIdentifiersEnabled) when(ApplicationManagementService.getInstance()).thenReturn(applicationManagementService); when(applicationManagementService.getServiceProvider(anyString(), anyString())).thenReturn(null); - mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class); + mockedUserStoreManager = mock(AbstractUserStoreManager.class); when(mockedUserStoreManager.isExistingUserWithID(anyString())).thenReturn(true); when(mockedUserStoreManager.isExistingUser(anyString())).thenReturn(true); when(mockedUserStoreManager.getUserList(anyString(), anyString(), nullable(String.class))).thenReturn(existingUserList); @@ -1650,7 +1657,7 @@ public void testCreateUserWithConflictingLoginIdentifier() throws Exception { when(SCIMCommonUtils.convertSCIMtoLocalDialect(anyMap())).thenCallRealMethod(); when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimMappings); - mockedUserStoreManager = Mockito.mock(AbstractUserStoreManager.class); + mockedUserStoreManager = mock(AbstractUserStoreManager.class); when(mockedUserStoreManager.getUserList(anyString(), anyString(), anyString())).thenReturn(null); when(mockedUserStoreManager.getSecondaryUserStoreManager(anyString())) .thenReturn(secondaryUserStoreManager); diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/listener/SCIMUserOperationListenerTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/listener/SCIMUserOperationListenerTest.java index 5b81a1e2b..2b6a5a3d3 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/listener/SCIMUserOperationListenerTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/listener/SCIMUserOperationListenerTest.java @@ -48,7 +48,14 @@ import java.util.Map; import java.util.UUID; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull;