From ee6ab31c1dd030db0d41c692f333875d3a63f0e1 Mon Sep 17 00:00:00 2001 From: sandushi Date: Fri, 9 Aug 2024 09:05:53 +0530 Subject: [PATCH] Remove powermock --- .../pom.xml | 10 +- ...DefaultSCIMUserStoreErrorResolverTest.java | 3 +- .../impl/IdentityResourceURLBuilderTest.java | 26 +-- .../common/impl/IdentitySCIMManagerTest.java | 40 ++-- .../common/impl/SCIMRoleManagerV2Test.java | 13 +- .../common/impl/SCIMUserManagerTest.java | 171 ++++++++---------- .../SCIMUserOperationListenerTest.java | 56 +++--- .../common/utils/AdminAttributeUtilTest.java | 39 ++-- .../utils/AdminAttributeUtilTestForGroup.java | 70 ++++--- .../common/utils/SCIMCommonUtilsTest.java | 61 +++---- pom.xml | 20 +- 11 files changed, 225 insertions(+), 284 deletions(-) diff --git a/components/org.wso2.carbon.identity.scim2.common/pom.xml b/components/org.wso2.carbon.identity.scim2.common/pom.xml index 6c6a15738..b30448a5d 100644 --- a/components/org.wso2.carbon.identity.scim2.common/pom.xml +++ b/components/org.wso2.carbon.identity.scim2.common/pom.xml @@ -173,12 +173,14 @@ testng - org.powermock - powermock-module-testng + org.mockito + mockito-core + test - org.powermock - powermock-api-mockito2 + org.mockito + mockito-testng + test org.jacoco diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/DefaultSCIMUserStoreErrorResolverTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/DefaultSCIMUserStoreErrorResolverTest.java index 6150cf4bd..fa52abbc4 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/DefaultSCIMUserStoreErrorResolverTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/DefaultSCIMUserStoreErrorResolverTest.java @@ -19,7 +19,6 @@ package org.wso2.carbon.identity.scim2.common.impl; import org.apache.http.HttpStatus; -import org.powermock.modules.testng.PowerMockTestCase; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreException; @@ -31,7 +30,7 @@ /** * Contains the unit test cases for DefaultSCIMUserStoreErrorResolver. */ -public class DefaultSCIMUserStoreErrorResolverTest extends PowerMockTestCase { +public class DefaultSCIMUserStoreErrorResolverTest { @Test public void testGetOrder() { diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentityResourceURLBuilderTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentityResourceURLBuilderTest.java index 811f75bfc..e7469b101 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentityResourceURLBuilderTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentityResourceURLBuilderTest.java @@ -19,8 +19,8 @@ package org.wso2.carbon.identity.scim2.common.impl; import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.testng.PowerMockTestCase; + +import org.mockito.MockedStatic; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -33,17 +33,16 @@ import java.util.HashMap; import java.util.Map; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.when; import static org.testng.Assert.assertEquals; +import static org.mockito.Mockito.mockStatic; /** * Contains the unit test cases for IdentityResourceURLBuilder. */ -@PrepareForTest({IdentityTenantUtil.class, ServiceURLBuilder.class}) -public class IdentityResourceURLBuilderTest extends PowerMockTestCase { +public class IdentityResourceURLBuilderTest { private static final Map DUMMY_ENDPOINT_URI_MAP = new HashMap() {{ put("Users", "https://localhost:9444/scim2/Users"); @@ -56,14 +55,17 @@ public class IdentityResourceURLBuilderTest extends PowerMockTestCase { @Mock ServiceURL mockServiceUrl; + private MockedStatic serviceURLBuilder; + private MockedStatic identityTenantUtil; + @BeforeMethod public void setUpMethod() { initMocks(this); - mockStatic(ServiceURLBuilder.class); - when(ServiceURLBuilder.create()).thenReturn(mockServiceURLBuilder); + serviceURLBuilder = mockStatic(ServiceURLBuilder.class); + serviceURLBuilder.when(() -> ServiceURLBuilder.create()).thenReturn(mockServiceURLBuilder); when(mockServiceURLBuilder.addPath(anyString())).thenReturn(mockServiceURLBuilder); - mockStatic(IdentityTenantUtil.class); + identityTenantUtil = mockStatic(IdentityTenantUtil.class); } @DataProvider(name = "dataProviderForBuild") @@ -82,7 +84,7 @@ public Object[][] dataProviderForBuild() { public void testBuild(boolean isTenantQualifiedUrlsEnabled, String url, String resource, boolean throwError, String expected) throws NotFoundException, URLBuilderException { - when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifiedUrlsEnabled); + identityTenantUtil.when(() -> IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifiedUrlsEnabled); when(mockServiceURLBuilder.build()).thenAnswer(invocationOnMock -> { if (throwError) { throw new URLBuilderException("Protocol of service URL is not available."); @@ -109,7 +111,7 @@ public Object[][] dataProviderForBuildThrowingNotFoundException() { public void testBuildThrowingNotFoundException(boolean isTenantQualifiedUrlsEnabled, String resource) throws URLBuilderException, NotFoundException { - when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifiedUrlsEnabled); + identityTenantUtil.when(() -> IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifiedUrlsEnabled); when(mockServiceURLBuilder.build()).thenThrow( new URLBuilderException("Protocol of service URL is not available.")); IdentityResourceURLBuilder identityResourceURLBuilder = new IdentityResourceURLBuilder(); diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentitySCIMManagerTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentitySCIMManagerTest.java index d3011bddc..8762697b0 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentitySCIMManagerTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/IdentitySCIMManagerTest.java @@ -19,13 +19,11 @@ package org.wso2.carbon.identity.scim2.common.impl; import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.testng.PowerMockTestCase; -import org.testng.IObjectFactory; +import org.mockito.MockedStatic; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.ObjectFactory; import org.testng.annotations.Test; +import org.testng.annotations.Listeners; +import org.mockito.testng.MockitoTestNGListener; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.scim2.common.internal.SCIMCommonComponentHolder; import org.wso2.carbon.identity.scim2.common.test.utils.CommonTestUtils; @@ -44,19 +42,18 @@ import java.nio.file.Paths; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.when; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.fail; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.anyInt; /** * Contains the unit test cases for IdentitySCIMManager. */ -@PrepareForTest({SCIMCommonUtils.class, PrivilegedCarbonContext.class, SCIMCommonComponentHolder.class,CharonConfiguration.class}) -@PowerMockIgnore({"javax.xml.*","org.w3c.dom.*","org.xml.sax.*"}) -public class IdentitySCIMManagerTest extends PowerMockTestCase { +@Listeners(MockitoTestNGListener.class) +public class IdentitySCIMManagerTest { @Mock RealmService realmService; @@ -76,14 +73,17 @@ public class IdentitySCIMManagerTest extends PowerMockTestCase { private SCIMConfigProcessor scimConfigProcessor; private IdentitySCIMManager identitySCIMManager; + private MockedStatic scimCommonUtils; + private MockedStatic scimCommonComponentHolder; + @BeforeMethod public void setUp() throws Exception { - mockStatic(SCIMCommonUtils.class); - when(SCIMCommonUtils.getSCIMUserURL()).thenReturn("http://scimUserUrl:9443"); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonUtils.when(() -> SCIMCommonUtils.getSCIMUserURL()).thenReturn("http://scimUserUrl:9443"); - mockStatic(SCIMCommonComponentHolder.class); - when(SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService); + scimCommonComponentHolder = mockStatic(SCIMCommonComponentHolder.class); + scimCommonComponentHolder.when(() -> SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService); scimConfigProcessor = SCIMConfigProcessor.getInstance(); String filePath = Paths @@ -91,7 +91,7 @@ public void setUp() throws Exception { scimConfigProcessor.buildConfigFromFile(filePath); identitySCIMManager = IdentitySCIMManager.getInstance(); - mockStatic(SCIMCommonComponentHolder.class); + scimCommonComponentHolder = mockStatic(SCIMCommonComponentHolder.class); when(realmService.getTenantManager()).thenReturn(mockedTenantManager); when(mockedTenantManager.getTenantId(anyString())).thenReturn(-1234); @@ -102,12 +102,6 @@ public void setUp() throws Exception { CommonTestUtils.initPrivilegedCarbonContext(); } - @ObjectFactory - public IObjectFactory getObjectFactory() { - - return new org.powermock.modules.testng.PowerMockObjectFactory(); - } - @Test public void testGetInstance() throws Exception { diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2Test.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2Test.java index 96eca05c0..ea9b147bf 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2Test.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2Test.java @@ -19,13 +19,12 @@ package org.wso2.carbon.identity.scim2.common.impl; import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.testng.PowerMockTestCase; +import org.mockito.MockedStatic; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import org.wso2.carbon.identity.core.ServiceURLBuilder; import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.role.v2.mgt.core.RoleManagementService; import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException; @@ -43,6 +42,7 @@ import java.util.List; import java.util.Map; +import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.testng.Assert.assertEquals; @@ -50,8 +50,7 @@ /** * Contains the unit test cases for SCIMRoleManagerV2. */ -@PrepareForTest({IdentityUtil.class}) -public class SCIMRoleManagerV2Test extends PowerMockTestCase { +public class SCIMRoleManagerV2Test { private static final String SAMPLE_TENANT_DOMAIN = "carbon.super"; private static final String SAMPLE_VALID_ROLE_ID = "595f5508-f286-446a-86c4-5071e07b98fc"; @@ -64,6 +63,8 @@ public class SCIMRoleManagerV2Test extends PowerMockTestCase { private SCIMRoleManagerV2 scimRoleManagerV2; + private MockedStatic identityUtil; + @BeforeClass public void setUpClass() { @@ -73,7 +74,7 @@ public void setUpClass() { @BeforeMethod public void setUpMethod() { - PowerMockito.mockStatic(IdentityUtil.class); + identityUtil = mockStatic(IdentityUtil.class); scimRoleManagerV2 = new SCIMRoleManagerV2(roleManagementService, SAMPLE_TENANT_DOMAIN); } 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 fa83a8447..3dfa12549 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 @@ -20,17 +20,11 @@ import org.apache.commons.lang.StringUtils; import org.mockito.Mock; +import org.mockito.MockedStatic; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.api.support.membermodification.MemberModifier; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.testng.PowerMockTestCase; -import org.testng.IObjectFactory; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; -import org.testng.annotations.ObjectFactory; import org.testng.annotations.Test; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.base.MultitenantConstants; @@ -107,14 +101,8 @@ 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.MockitoAnnotations.initMocks; -import static org.powermock.api.mockito.PowerMockito.doNothing; -import static org.powermock.api.mockito.PowerMockito.doReturn; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.spy; -import static org.powermock.api.mockito.PowerMockito.when; -import static org.powermock.api.mockito.PowerMockito.whenNew; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; @@ -122,13 +110,7 @@ /* * Unit tests for SCIMUserManager */ -@PrepareForTest({SCIMGroupHandler.class, IdentityUtil.class, SCIMUserSchemaExtensionBuilder.class, - SCIMAttributeSchema.class, AttributeMapper.class, ClaimMetadataHandler.class, SCIMCommonUtils.class, - IdentityTenantUtil.class, AbstractUserStoreManager.class, Group.class, UserCoreUtil.class, - ApplicationManagementService.class, RolePermissionManagementService.class, SCIMCommonComponentHolder.class, - SCIMUserManager.class, CarbonConstants.class}) -@PowerMockIgnore({"java.sql.*","javax.xml.*","org.w3c.dom.*","org.xml.sax.*"}) -public class SCIMUserManagerTest extends PowerMockTestCase { +public class SCIMUserManagerTest { private static final String USERNAME_LOCAL_CLAIM = "http://wso2.org/claims/username"; private static final String USERID_LOCAL_CLAIM = "http://wso2.org/claims/userid"; @@ -196,6 +178,14 @@ public class SCIMUserManagerTest extends PowerMockTestCase { @Mock private RolePermissionManagementService mockedRolePermissionManagementService; + private MockedStatic scimUserSchemaExtensionBuilder; + private MockedStatic identityUtil; + private MockedStatic scimCommonUtils; + private MockedStatic attributeMapper; + private MockedStatic claimMetadataHandler; + private MockedStatic carbonConstants; + private MockedStatic identityTenantUtil; + private MockedStatic userCoreUtil; @BeforeMethod public void setUp() throws Exception { @@ -265,19 +255,19 @@ public void testGetMe(Object[] cMap, HashMap required, String[] when(mockedClaimManager.getAllClaimMappings(anyString())).thenReturn((ClaimMapping[]) cMap); SCIMUserSchemaExtensionBuilder sb = spy(new SCIMUserSchemaExtensionBuilder()); - mockStatic(SCIMUserSchemaExtensionBuilder.class); - when(SCIMUserSchemaExtensionBuilder.getInstance()).thenReturn(sb); + scimUserSchemaExtensionBuilder = mockStatic(SCIMUserSchemaExtensionBuilder.class); + scimUserSchemaExtensionBuilder.when(() -> SCIMUserSchemaExtensionBuilder.getInstance()).thenReturn(sb); when(sb.getExtensionSchema()).thenReturn(mockedSCIMAttributeSchema); - mockStatic(IdentityUtil.class); - when(IdentityUtil.extractDomainFromName(anyString())).thenReturn("testPrimaryDomain"); + identityUtil = mockStatic(IdentityUtil.class); + identityUtil.when(() -> IdentityUtil.extractDomainFromName(anyString())).thenReturn("testPrimaryDomain"); - mockStatic(SCIMCommonUtils.class); - when(SCIMCommonUtils.convertLocalToSCIMDialect(anyMap(), anyMap())).thenReturn(new HashMap() {{ + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonUtils.when(() -> SCIMCommonUtils.convertLocalToSCIMDialect(anyMap(), anyMap())).thenReturn(new HashMap() {{ put(SCIMConstants.CommonSchemaConstants.ID_URI, "1f70378a-69bb-49cf-aa51-a0493c09110c"); }}); - mockedUserStoreManager = PowerMockito.mock(AbstractUserStoreManager.class); + mockedUserStoreManager = mock(AbstractUserStoreManager.class); MemberModifier.field(AbstractUserStoreManager.class, "userStoreManagerHolder") .set(mockedUserStoreManager, new HashMap()); @@ -285,8 +275,8 @@ public void testGetMe(Object[] cMap, HashMap required, String[] when(mockedUserStoreManager.getSecondaryUserStoreManager(anyString())).thenReturn(secondaryUserStoreManager); when(mockedUserStoreManager.isSCIMEnabled()).thenReturn(true); when(mockedUserStoreManager.getRoleListOfUser(anyString())).thenReturn(userRoles); - mockStatic(AttributeMapper.class); - when(AttributeMapper.constructSCIMObjectFromAttributes(any(), anyMap(), anyInt())).thenReturn(mockedUser); + attributeMapper = mockStatic(AttributeMapper.class); + attributeMapper.when(() -> AttributeMapper.constructSCIMObjectFromAttributes(any(), anyMap(), anyInt())).thenReturn(mockedUser); when(mockedUserStoreManager.getRealmConfiguration()).thenReturn(mockedRealmConfig); when(mockedRealmConfig.getEveryOneRoleName()).thenReturn("roleName"); when(mockedUserStoreManager.getTenantId()).thenReturn(1234567); @@ -294,10 +284,9 @@ public void testGetMe(Object[] cMap, HashMap required, String[] user.setUsername("testUserName"); user.setUserID(UUID.randomUUID().toString()); when(mockedUserStoreManager.getUser(anyString(), nullable(String.class))).thenReturn(user); - whenNew(GroupDAO.class).withAnyArguments().thenReturn(mockedGroupDAO); CommonTestUtils.initPrivilegedCarbonContext(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - mockStatic(ClaimMetadataHandler.class); - when(ClaimMetadataHandler.getInstance()).thenReturn(mockClaimMetadataHandler); + claimMetadataHandler = mockStatic(ClaimMetadataHandler.class); + claimMetadataHandler.when(() -> ClaimMetadataHandler.getInstance()).thenReturn(mockClaimMetadataHandler); when(mockClaimMetadataHandler.getMappingsFromOtherDialectToCarbon(anyString(), anySet(), anyString())) .thenReturn(new HashSet()); @@ -309,16 +298,15 @@ public void testGetMe(Object[] cMap, HashMap required, String[] public void testGetGroup(String groupId, String roleName, String userStoreDomain, Object expected) throws Exception { - whenNew(GroupDAO.class).withAnyArguments().thenReturn(mockedGroupDAO); when(mockedGroupDAO.getGroupNameById(anyInt(), anyString())).thenReturn(roleName); - mockStatic(IdentityUtil.class); - when(IdentityUtil.extractDomainFromName(anyString())).thenReturn(userStoreDomain); + identityUtil = mockStatic(IdentityUtil.class); + identityUtil.when(() -> IdentityUtil.extractDomainFromName(anyString())).thenReturn(userStoreDomain); when(mockedUserStoreManager.getGroup(groupId, null)). thenReturn(buildUserCoreGroupResponse(roleName, groupId, userStoreDomain)); - mockStatic(SCIMCommonUtils.class); - when(SCIMCommonUtils.getSCIMGroupURL()).thenReturn("https://localhost:9443/scim2/Groups"); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonUtils.when(() -> SCIMCommonUtils.getSCIMGroupURL()).thenReturn("https://localhost:9443/scim2/Groups"); - mockStatic(CarbonConstants.class); + carbonConstants = mockStatic(CarbonConstants.class); CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true; SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager, mockedClaimManager); @@ -347,10 +335,9 @@ public void testGetGroupWithExceptions(String roleName, String userStoreDomain) MemberModifier.field(AbstractUserStoreManager.class, "userStoreManagerHolder") .set(mockedUserStoreManager, new HashMap()); - whenNew(GroupDAO.class).withAnyArguments().thenReturn(mockedGroupDAO); when(mockedGroupDAO.getGroupNameById(anyInt(), anyString())).thenReturn(roleName); - mockStatic(IdentityUtil.class); - when(IdentityUtil.extractDomainFromName(anyString())).thenReturn(userStoreDomain); + identityUtil = mockStatic(IdentityUtil.class); + identityUtil.when(() -> IdentityUtil.extractDomainFromName(anyString())).thenReturn(userStoreDomain); SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager, mockedClaimManager); try { @@ -397,15 +384,14 @@ public void testListGroupsWithFilter(String filter, String roleName, String user Map attributes = new HashMap() {{ put(SCIMConstants.CommonSchemaConstants.ID_URI, "1"); }}; - whenNew(GroupDAO.class).withAnyArguments().thenReturn(mockedGroupDAO); when(mockedGroupDAO.getGroupNameList(anyString(), anyString(), anyInt(), anyString())) .thenReturn(list.toArray(new String[0])); - mockStatic(IdentityUtil.class); + identityUtil = mockStatic(IdentityUtil.class); when(mockedGroupDAO.isExistingGroup("testRole", 0)).thenReturn(true); when(mockedGroupDAO.getSCIMGroupAttributes(0, "testRole")).thenReturn(attributes); - when(IdentityUtil.extractDomainFromName(anyString())).thenReturn(userStoreDomain); + identityUtil.when(() -> IdentityUtil.extractDomainFromName(anyString())).thenReturn(userStoreDomain); - mockedUserStoreManager = PowerMockito.mock(AbstractUserStoreManager.class); + mockedUserStoreManager = mock(AbstractUserStoreManager.class); MemberModifier.field(AbstractUserStoreManager.class, "userStoreManagerHolder") .set(mockedUserStoreManager, new HashMap()); @@ -422,7 +408,6 @@ public void testListGroupsWithFilter(String filter, String roleName, String user anyInt(), nullable(String.class), nullable(String.class))).thenReturn(Arrays.asList(groupsArray.clone())); when(mockedUserStoreManager.getGroupByGroupName(roleName, null)). thenReturn(buildUserCoreGroupResponse(roleName, "123456789", null)); - whenNew(RealmConfiguration.class).withAnyArguments().thenReturn(mockRealmConfig); when(mockRealmConfig.getAdminRoleName()).thenReturn("admin"); when(mockRealmConfig.isPrimary()).thenReturn(false); when(mockRealmConfig.getUserStoreProperty(anyString())).thenReturn("value"); @@ -430,14 +415,14 @@ public void testListGroupsWithFilter(String filter, String roleName, String user when(mockIdentityUtil.extractDomainFromName(anyString())).thenReturn("value"); - mockStatic(CarbonConstants.class); + carbonConstants = mockStatic(CarbonConstants.class); CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true; Map scimToLocalClaimsMap = new HashMap<>(); scimToLocalClaimsMap.put("urn:ietf:params:scim:schemas:core:2.0:User:userName", "http://wso2.org/claims/username"); - mockStatic(SCIMCommonUtils.class); - when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonUtils.when(() -> SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap); SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager, mockedClaimManager); GroupsGetResponse groupsResponse = scimUserManager.listGroupsWithGET(node, 1, 1, null, null, @@ -457,13 +442,13 @@ public void testListUsersWithGET(List use "http://wso2.org/claims/username"); scimToLocalClaimMap.put("urn:ietf:params:scim:schemas:core:2.0:id", "http://wso2.org/claims/userid"); - mockStatic(SCIMCommonUtils.class); - when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimMap); - when(SCIMCommonUtils.convertLocalToSCIMDialect(anyMap(), anyMap())).thenReturn(new HashMap() {{ + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonUtils.when(() -> SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimMap); + scimCommonUtils.when(() -> SCIMCommonUtils.convertLocalToSCIMDialect(anyMap(), anyMap())).thenReturn(new HashMap() {{ put(SCIMConstants.CommonSchemaConstants.ID_URI, "1f70378a-69bb-49cf-aa51-a0493c09110c"); }}); - mockedUserStoreManager = PowerMockito.mock(AbstractUserStoreManager.class); + mockedUserStoreManager = mock(AbstractUserStoreManager.class); when(mockedUserStoreManager.getUserListWithID("http://wso2.org/claims/userid", "*", null)).thenReturn(users); when(mockedUserStoreManager.getRoleListOfUserWithID(anyString())).thenReturn(new ArrayList<>()); @@ -475,9 +460,9 @@ public void testListUsersWithGET(List use when(mockedUserStoreManager.getSecondaryUserStoreManager("SECONDARY")).thenReturn(secondaryUserStoreManager); when(secondaryUserStoreManager.isSCIMEnabled()).thenReturn(isScimEnabledForSecondary); - mockStatic(IdentityTenantUtil.class); + identityTenantUtil = mockStatic(IdentityTenantUtil.class); - when(IdentityTenantUtil.getRealmService()).thenReturn(mockRealmService); + identityTenantUtil.when(() -> IdentityTenantUtil.getRealmService()).thenReturn(mockRealmService); when(mockRealmService.getBootstrapRealmConfiguration()).thenReturn(mockedRealmConfig); HashMap requiredClaimsMap = new HashMap<>(); @@ -544,13 +529,13 @@ public void testFilteringUsersWithGET(List() {{ + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonUtils.when(() -> SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimMap); + scimCommonUtils.when(() -> SCIMCommonUtils.convertLocalToSCIMDialect(anyMap(), anyMap())).thenReturn(new HashMap() {{ put(SCIMConstants.CommonSchemaConstants.ID_URI, "1f70378a-69bb-49cf-aa51-a0493c09110c"); }}); - mockedUserStoreManager = PowerMockito.mock(AbstractUserStoreManager.class); + mockedUserStoreManager = mock(AbstractUserStoreManager.class); when(mockedUserStoreManager.getUserListWithID("http://wso2.org/claims/userid", "*", null)).thenReturn(users); when(mockedUserStoreManager.getUserListWithID("http://wso2.org/claims/givenname", "testUser", "default")) @@ -565,11 +550,11 @@ public void testFilteringUsersWithGET(List() {{ + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonUtils.when(() -> SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimMap); + scimCommonUtils.when(() -> SCIMCommonUtils.convertLocalToSCIMDialect(anyMap(), anyMap())).thenReturn(new HashMap() {{ put(SCIMConstants.CommonSchemaConstants.ID_URI, "1f70378a-69bb-49cf-aa51-a0493c09110c"); }}); - mockedUserStoreManager = PowerMockito.mock(AbstractUserStoreManager.class); + mockedUserStoreManager = mock(AbstractUserStoreManager.class); when(mockedUserStoreManager.getUserListWithID(any(Condition.class), anyString(), anyString(), eq(count), anyInt(), nullable(String.class), nullable(String.class))).thenReturn(filteredUsersWithPagination); @@ -686,8 +671,8 @@ public void testFilteringUsersWithGETWithPagination(List IdentityTenantUtil.getRealmService()).thenReturn(mockRealmService); when(mockRealmService.getBootstrapRealmConfiguration()).thenReturn(mockedRealmConfig); ClaimMapping[] claimMappings = getTestClaimMappings(); @@ -705,9 +690,9 @@ public void testFilteringUsersWithGETWithPagination(List SCIMCommonUtils.isConsiderTotalRecordsForTotalResultOfLDAPEnabled()) .thenReturn(isConsiderTotalRecordsForTotalResultOfLDAPEnabled); - when(SCIMCommonUtils.isConsiderMaxLimitForTotalResultEnabled()) + scimCommonUtils.when(() -> SCIMCommonUtils.isConsiderMaxLimitForTotalResultEnabled()) .thenReturn(isConsiderMaxLimitForTotalResultEnabled); Map supportedByDefaultProperties = new HashMap() {{ @@ -964,13 +949,12 @@ public void testListApplicationRolesWithDomainParam(Map require when(abstractUserStoreManager.getGroupByGroupName(role, null)). thenReturn(buildUserCoreGroupResponse(role, "123456789", null)); } - whenNew(GroupDAO.class).withAnyArguments().thenReturn(mockedGroupDAO); when(mockedGroupDAO.isExistingGroup(anyString(), anyInt())).thenReturn(true); when(mockedGroupDAO.getSCIMGroupAttributes(anyInt(), anyString())).thenReturn(attributes); - mockStatic(UserCoreUtil.class); - when(UserCoreUtil.isEveryoneRole("role", mockedRealmConfig)).thenReturn(false); - mockStatic(SCIMCommonUtils.class); - when(SCIMCommonUtils.getSCIMGroupURL()).thenReturn("https://localhost:9443/scim2/Groups"); + userCoreUtil = mockStatic(UserCoreUtil.class); + userCoreUtil.when(() -> UserCoreUtil.isEveryoneRole("role", mockedRealmConfig)).thenReturn(false); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonUtils.when(() -> SCIMCommonUtils.getSCIMGroupURL()).thenReturn("https://localhost:9443/scim2/Groups"); SCIMUserManager scimUserManager = new SCIMUserManager(abstractUserStoreManager, mockedClaimManager); GroupsGetResponse groupsResponse = scimUserManager @@ -1021,15 +1005,14 @@ public void testFilterApplicationRolesWithDomainParam(String filter, String[] ro when(abstractUserStoreManager.getGroupByGroupName(role, null)). thenReturn(buildUserCoreGroupResponse(role, "123456", "dummyDomain")); } - mockStatic(UserCoreUtil.class); - when(UserCoreUtil.isEveryoneRole("role", mockedRealmConfig)).thenReturn(false); - whenNew(GroupDAO.class).withAnyArguments().thenReturn(mockedGroupDAO); + userCoreUtil = mockStatic(UserCoreUtil.class); + userCoreUtil.when(() -> UserCoreUtil.isEveryoneRole("role", mockedRealmConfig)).thenReturn(false); when(mockedGroupDAO.isExistingGroup(anyString(), anyInt())).thenReturn(true); when(mockedGroupDAO.getSCIMGroupAttributes(anyInt(), anyString())).thenReturn(attributes); - mockStatic(SCIMCommonUtils.class); - when(SCIMCommonUtils.getSCIMGroupURL()).thenReturn("https://localhost:9443/scim2/Groups"); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonUtils.when(() -> SCIMCommonUtils.getSCIMGroupURL()).thenReturn("https://localhost:9443/scim2/Groups"); - mockStatic(CarbonConstants.class); + carbonConstants = mockStatic(CarbonConstants.class); CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true; SCIMUserManager scimUserManager = new SCIMUserManager(abstractUserStoreManager, mockedClaimManager); @@ -1055,12 +1038,6 @@ public Object[][] applicationDomainWithFilters() { }; } - @ObjectFactory - public IObjectFactory getObjectFactory() { - - return new org.powermock.modules.testng.PowerMockObjectFactory(); - } - @Test public void testGetEnterpriseUserSchemaWhenEnabled() throws Exception { @@ -1099,12 +1076,12 @@ public void testGetEnterpriseUserSchemaWhenEnabled() throws Exception { MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)).thenReturn(externalClaimMap); when(mockClaimMetadataManagementService.getLocalClaims(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) .thenReturn(localClaimMap); - mockStatic(SCIMCommonUtils.class); - when(SCIMCommonUtils.isEnterpriseUserExtensionEnabled()).thenReturn(true); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonUtils.when(() -> SCIMCommonUtils.isEnterpriseUserExtensionEnabled()).thenReturn(true); SCIMUserSchemaExtensionBuilder sb = spy(new SCIMUserSchemaExtensionBuilder()); - mockStatic(SCIMUserSchemaExtensionBuilder.class); - when(SCIMUserSchemaExtensionBuilder.getInstance()).thenReturn(sb); + scimUserSchemaExtensionBuilder = mockStatic(SCIMUserSchemaExtensionBuilder.class); + scimUserSchemaExtensionBuilder.when(() -> SCIMUserSchemaExtensionBuilder.getInstance()).thenReturn(sb); when(sb.getExtensionSchema()).thenReturn(mockedSCIMAttributeSchema); when(mockedSCIMAttributeSchema.getSubAttributeSchema(anyString())).thenReturn(mockedAttributeSchema); when(mockedAttributeSchema.getType()).thenReturn(SCIMDefinitions.DataType.STRING); @@ -1117,8 +1094,8 @@ public void testGetEnterpriseUserSchemaWhenEnabled() throws Exception { @Test public void testGetEnterpriseUserSchemaWhenDisabled() throws Exception { - mockStatic(SCIMCommonUtils.class); - when(SCIMCommonUtils.isEnterpriseUserExtensionEnabled()).thenReturn(false); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonUtils.when(() -> SCIMCommonUtils.isEnterpriseUserExtensionEnabled()).thenReturn(false); SCIMUserManager userManager = new SCIMUserManager(mockedUserStoreManager, mockClaimMetadataManagementService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); assertEquals(userManager.getEnterpriseUserSchema(), null); @@ -1349,7 +1326,7 @@ public void testGetUser(Boolean isGroupsVsRolesSeparationImprovementsEnabled, Ma when(user.getDomainQualifiedUsername()).thenReturn(domainQualifiedUserName); when(user.getUserID()).thenReturn((userId)); - mockedUserStoreManager = PowerMockito.mock(AbstractUserStoreManager.class); + mockedUserStoreManager = mock(AbstractUserStoreManager.class); when(mockedUserStoreManager.getUserWithID(anyString(), nullable(String[].class), anyString())).thenReturn(user); when(mockedUserStoreManager.getTenantId()).thenReturn(1234567); when(mockedUserStoreManager.getUserClaimValuesWithID(anyString(), any(), nullable(String.class))) @@ -1370,7 +1347,6 @@ public void testGetUser(Boolean isGroupsVsRolesSeparationImprovementsEnabled, Ma when(mockedRealmConfig.isPrimary()).thenReturn(true); when(mockedRealmConfig.getEveryOneRoleName()).thenReturn("Internal/everyone"); - PowerMockito.whenNew(GroupDAO.class).withAnyArguments().thenReturn(mockedGroupDAO); doNothing().when(mockedGroupDAO).addSCIMGroupAttributesToSCIMDisabledHybridRoles(anyInt(), any()); SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager, @@ -1384,7 +1360,6 @@ public void testGetUser(Boolean isGroupsVsRolesSeparationImprovementsEnabled, Ma when(IdentityUtil.getProperty(SCIMCommonConstants.ENABLE_LOGIN_IDENTIFIERS)).thenReturn(enableLoginIdentifiers); when(IdentityUtil.extractDomainFromName(anyString())).thenReturn("Internal"); - PowerMockito.whenNew(SCIMGroupHandler.class).withArguments(anyInt()).thenReturn(mockedSCIMGroupHandler); when(mockedSCIMGroupHandler.listSCIMRoles()).thenReturn(scimRoles); when(mockedSCIMGroupHandler.getGroupWithAttributes(any(Group.class), anyString())) .thenAnswer(new Answer() { 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 466dc8aba..e6d639d67 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 @@ -19,12 +19,9 @@ package org.wso2.carbon.identity.scim2.common.listener; import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.testng.PowerMockTestCase; -import org.testng.IObjectFactory; +import org.mockito.MockedStatic; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; -import org.testng.annotations.ObjectFactory; import org.testng.annotations.Test; import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants; import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService; @@ -49,22 +46,13 @@ import java.util.Map; import java.util.UUID; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.spy; -import static org.powermock.api.mockito.PowerMockito.when; -import static org.powermock.api.mockito.PowerMockito.whenNew; +import static org.mockito.Mockito.*; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; -@PrepareForTest({UserCoreUtil.class, SCIMGroupHandler.class, SCIMCommonUtils.class, IdentityUtil.class, - IdentityTenantUtil.class}) -public class SCIMUserOperationListenerTest extends PowerMockTestCase { + +public class SCIMUserOperationListenerTest { private final String CARBON_SUPER = "carbon.super"; private String userName = "testUser"; @@ -93,22 +81,21 @@ public class SCIMUserOperationListenerTest extends PowerMockTestCase { @Mock GroupDAO groupDAO; - @ObjectFactory - public IObjectFactory getObjectFactory() { - - return new org.powermock.modules.testng.PowerMockObjectFactory(); - } + private MockedStatic userCoreUtil; + private MockedStatic scimCommonUtils; + private MockedStatic identityTenantUtil; + private MockedStatic identityUtil; @BeforeMethod public void setUp() throws Exception { scimUserOperationListener = spy(new SCIMUserOperationListener()); - mockStatic(UserCoreUtil.class); - mockStatic(SCIMCommonUtils.class); - mockStatic(IdentityTenantUtil.class); + userCoreUtil = mockStatic(UserCoreUtil.class); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + identityTenantUtil = mockStatic(IdentityTenantUtil.class); SCIMCommonComponentHolder.setClaimManagementService(claimMetadataManagementService); when(userStoreManager.getTenantId()).thenReturn(-1234); - when(IdentityTenantUtil.getTenantDomain(anyInt())).thenReturn(CARBON_SUPER); + identityTenantUtil.when(() -> IdentityTenantUtil.getTenantDomain(anyInt())).thenReturn(CARBON_SUPER); } @DataProvider(name = "testGetExecutionOrderIdData") @@ -234,8 +221,8 @@ public void testDoPreSetUserClaimValues(boolean isEnabled, boolean isSCIMEnabled when(scimUserOperationListener.isEnable()).thenReturn(isEnabled); when(userStoreManager.isSCIMEnabled()).thenReturn(isSCIMEnabled); - mockStatic(IdentityUtil.class); - when(IdentityUtil.getProperty(FrameworkConstants.ENABLE_JIT_PROVISION_ENHANCE_FEATURE)).thenReturn("false"); + identityUtil = mockStatic(IdentityUtil.class); + identityUtil.when(() -> IdentityUtil.getProperty(FrameworkConstants.ENABLE_JIT_PROVISION_ENHANCE_FEATURE)).thenReturn("false"); assertTrue(scimUserOperationListener. doPreSetUserClaimValuesWithID(userId, claims, profile, userStoreManager)); @@ -426,7 +413,7 @@ public Object[][] testSCIMAttributesData() { @Test(dataProvider = "testSCIMAttributesData") public void testGetSCIMAttributes(Map claimsMap) throws Exception { - mockStatic(SCIMCommonUtils.class); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); Map scimToLocalClaimsMap = new HashMap<>(); scimToLocalClaimsMap.put(SCIMConstants.CommonSchemaConstants.ID_URI, "http://wso2.org/claims/userid"); scimToLocalClaimsMap.put(SCIMConstants.CommonSchemaConstants.CREATED_URI, "http://wso2.org/claims/created"); @@ -435,13 +422,13 @@ public void testGetSCIMAttributes(Map claimsMap) throws Exceptio scimToLocalClaimsMap.put(SCIMConstants.UserSchemaConstants.USER_NAME_URI, "http://wso2.org/claims/username"); scimToLocalClaimsMap.put(SCIMConstants.CommonSchemaConstants.RESOURCE_TYPE_URI, "http://wso2.org/claims/resourceType"); - when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap); + scimCommonUtils.when(() -> SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap); assertNotNull(scimUserOperationListener.getSCIMAttributes(userName, claimsMap)); } @Test(dataProvider = "testSCIMAttributesData") public void testPopulateSCIMAttributes(Map claimsMap) throws Exception { - mockStatic(SCIMCommonUtils.class); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); Map scimToLocalClaimsMap = new HashMap<>(); scimToLocalClaimsMap.put(SCIMConstants.CommonSchemaConstants.ID_URI, "http://wso2.org/claims/userid"); scimToLocalClaimsMap.put(SCIMConstants.CommonSchemaConstants.CREATED_URI, "http://wso2.org/claims/created"); @@ -450,16 +437,15 @@ public void testPopulateSCIMAttributes(Map claimsMap) throws Exc scimToLocalClaimsMap.put(SCIMConstants.UserSchemaConstants.USER_NAME_URI, "http://wso2.org/claims/username"); scimToLocalClaimsMap.put(SCIMConstants.CommonSchemaConstants.RESOURCE_TYPE_URI, "http://wso2.org/claims/resourceType"); - when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap); + scimCommonUtils.when(() -> SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap); assertNotNull(scimUserOperationListener.populateSCIMAttributes(userName, claimsMap)); } private void mockTestEnvironment(boolean isEnabled, boolean isSCIMEnabled, String domainName) throws Exception { when(scimUserOperationListener.isEnable()).thenReturn(isEnabled); when(userStoreManager.isSCIMEnabled()).thenReturn(isSCIMEnabled); - whenNew(GroupDAO.class).withNoArguments().thenReturn(groupDAO); - when(UserCoreUtil.getDomainName((RealmConfiguration) anyObject())).thenReturn(domainName); - when(UserCoreUtil.addDomainToName(anyString(), anyString())).thenReturn("testRoleNameWithDomain"); - when(SCIMCommonUtils.getGroupNameWithDomain(anyString())).thenReturn("testRoleNameWithDomain"); + userCoreUtil.when(() -> UserCoreUtil.getDomainName((RealmConfiguration) any())).thenReturn(domainName); + userCoreUtil.when(() -> UserCoreUtil.addDomainToName(anyString(), anyString())).thenReturn("testRoleNameWithDomain"); + scimCommonUtils.when(() ->SCIMCommonUtils.getGroupNameWithDomain(anyString())).thenReturn("testRoleNameWithDomain"); } } diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTest.java index 4ccc36dce..23d73e2c2 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTest.java @@ -20,8 +20,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.testng.PowerMockTestCase; +import org.mockito.MockedStatic; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -37,16 +36,9 @@ import java.util.Map; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.mockito.Mockito.*; -@PrepareForTest({SCIMCommonComponentHolder.class, ClaimsMgtUtil.class, IdentityTenantUtil.class, UserCoreUtil.class, - IdentityUtil.class, SCIMCommonUtils.class, AdminAttributeUtil.class}) -public class AdminAttributeUtilTest extends PowerMockTestCase { +public class AdminAttributeUtilTest { @Mock RealmService realmService; @@ -59,6 +51,11 @@ public class AdminAttributeUtilTest extends PowerMockTestCase { AdminAttributeUtil adminAttributeUtil; + private MockedStatic scimCommonComponentHolder; + private MockedStatic claimsMgtUtil; + +private MockedStatic identityTenantUtil; + @BeforeMethod public void setUp() throws Exception { adminAttributeUtil = new AdminAttributeUtil(); @@ -76,15 +73,15 @@ public Object[][] testUpdateAdminUserData() { public void testUpdateAdminUser(boolean validateSCIMID) throws Exception { String adminUsername = "admin"; - mockStatic(SCIMCommonComponentHolder.class); - mockStatic(ClaimsMgtUtil.class); - mockStatic(IdentityTenantUtil.class); - when(SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService); + scimCommonComponentHolder = mockStatic(SCIMCommonComponentHolder.class); + claimsMgtUtil = mockStatic(ClaimsMgtUtil.class); + identityTenantUtil = mockStatic(IdentityTenantUtil.class); + scimCommonComponentHolder.when(() -> SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService); when(realmService.getTenantUserRealm(anyInt())).thenReturn(userRealm); when(userRealm.getUserStoreManager()).thenReturn(userStoreManager); when(userStoreManager.isSCIMEnabled()).thenReturn(true); - when(ClaimsMgtUtil.getAdminUserNameFromTenantId(eq(realmService), anyInt())).thenReturn(adminUsername); - when(IdentityTenantUtil.getRealmService()).thenReturn(realmService); + claimsMgtUtil.when(() -> ClaimsMgtUtil.getAdminUserNameFromTenantId(eq(realmService), anyInt())).thenReturn(adminUsername); + identityTenantUtil.when(() -> IdentityTenantUtil.getRealmService()).thenReturn(realmService); when(userStoreManager.getUserClaimValue(anyString(), anyString(), anyString())).thenReturn(""); ArgumentCaptor argument = ArgumentCaptor.forClass(Map.class); @@ -94,10 +91,10 @@ public void testUpdateAdminUser(boolean validateSCIMID) throws Exception { @Test(expectedExceptions = UserStoreException.class) public void testUpdateAdminUser1() throws Exception { - mockStatic(SCIMCommonComponentHolder.class); - mockStatic(ClaimsMgtUtil.class); - mockStatic(IdentityTenantUtil.class); - when(SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService); + scimCommonComponentHolder = mockStatic(SCIMCommonComponentHolder.class); + claimsMgtUtil = mockStatic(ClaimsMgtUtil.class); + identityTenantUtil = mockStatic(IdentityTenantUtil.class); + scimCommonComponentHolder.when(() -> SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService); when(realmService.getTenantUserRealm(anyInt())).thenReturn(userRealm); when(userRealm.getUserStoreManager()).thenReturn(userStoreManager); when(userStoreManager.isSCIMEnabled()).thenThrow(new UserStoreException()); diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTestForGroup.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTestForGroup.java index 0377636ae..3c43e1689 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTestForGroup.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/AdminAttributeUtilTestForGroup.java @@ -20,8 +20,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.testng.PowerMockTestCase; +import org.mockito.MockedStatic; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -38,18 +37,12 @@ import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.util.UserCoreUtil; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.when; -import static org.powermock.api.mockito.PowerMockito.whenNew; +import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.any; + import static org.testng.Assert.assertEquals; -@PrepareForTest({SCIMCommonComponentHolder.class, ClaimsMgtUtil.class, IdentityTenantUtil.class, UserCoreUtil.class, - IdentityUtil.class, SCIMCommonUtils.class, AdminAttributeUtil.class}) -public class AdminAttributeUtilTestForGroup extends PowerMockTestCase { +public class AdminAttributeUtilTestForGroup { @Mock RealmService realmService; @@ -68,6 +61,13 @@ public class AdminAttributeUtilTestForGroup extends PowerMockTestCase { AdminAttributeUtil adminAttributeUtil; + private MockedStatic scimCommonComponentHolder; + private MockedStatic claimsMgtUtil; + private MockedStatic identityTenantUtil; + private MockedStatic userCoreUtil; + private MockedStatic identityUtil; + private MockedStatic scimCommonUtils; + @BeforeMethod public void setUp() throws Exception { adminAttributeUtil = new AdminAttributeUtil(); @@ -93,13 +93,13 @@ public Object[][] testUpdateAdminGroupData() { public void testUpdateAdminGroup(String domainName) throws Exception { String roleNameWithDomain = "TESTDOMAIN/admin"; - mockStatic(SCIMCommonComponentHolder.class); - mockStatic(ClaimsMgtUtil.class); - mockStatic(IdentityTenantUtil.class); - mockStatic(UserCoreUtil.class); - mockStatic(IdentityUtil.class); - mockStatic(SCIMCommonUtils.class); - when(SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService); + scimCommonComponentHolder = mockStatic(SCIMCommonComponentHolder.class); + claimsMgtUtil = mockStatic(ClaimsMgtUtil.class); + identityTenantUtil = mockStatic(IdentityTenantUtil.class); + userCoreUtil = mockStatic(UserCoreUtil.class); + identityUtil = mockStatic(IdentityUtil.class); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonComponentHolder.when(() -> SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService); when(realmService.getTenantUserRealm(anyInt())).thenReturn(userRealm); when(userRealm.getUserStoreManager()).thenReturn(userStoreManager); when(userStoreManager.isSCIMEnabled()).thenReturn(true); @@ -107,11 +107,10 @@ public void testUpdateAdminGroup(String domainName) throws Exception { when(userStoreManager.getRealmConfiguration()).thenReturn(realmConfiguration); when(userStoreManager.isRoleAndGroupSeparationEnabled()).thenReturn(true); when(realmConfiguration.getAdminRoleName()).thenReturn("admin"); - when(UserCoreUtil.getDomainName((RealmConfiguration) anyObject())).thenReturn(domainName); - when(IdentityUtil.getPrimaryDomainName()).thenReturn("TESTDOMAIN"); - when(UserCoreUtil.addDomainToName(anyString(), anyString())).thenReturn(roleNameWithDomain); - when(SCIMCommonUtils.getGroupNameWithDomain(anyString())).thenReturn(roleNameWithDomain); - whenNew(SCIMGroupHandler.class).withAnyArguments().thenReturn(scimGroupHandler); + userCoreUtil.when(() -> UserCoreUtil.getDomainName((RealmConfiguration) any())).thenReturn(domainName); + identityUtil.when(() -> IdentityUtil.getPrimaryDomainName()).thenReturn("TESTDOMAIN"); + userCoreUtil.when(() -> UserCoreUtil.addDomainToName(anyString(), anyString())).thenReturn(roleNameWithDomain); + scimCommonUtils.when(() -> SCIMCommonUtils.getGroupNameWithDomain(anyString())).thenReturn(roleNameWithDomain); ArgumentCaptor argument = ArgumentCaptor.forClass(String.class); CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true; @@ -125,24 +124,23 @@ public void testUpdateAdminGroup(String domainName) throws Exception { public void testUpdateAdminGroup1() throws Exception { String roleNameWithDomain = "TESTDOMAIN/admin"; - mockStatic(SCIMCommonComponentHolder.class); - mockStatic(ClaimsMgtUtil.class); - mockStatic(IdentityTenantUtil.class); - mockStatic(UserCoreUtil.class); - mockStatic(IdentityUtil.class); - mockStatic(SCIMCommonUtils.class); - when(SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService); + scimCommonComponentHolder = mockStatic(SCIMCommonComponentHolder.class); + claimsMgtUtil = mockStatic(ClaimsMgtUtil.class); + identityTenantUtil = mockStatic(IdentityTenantUtil.class); + userCoreUtil = mockStatic(UserCoreUtil.class); + identityUtil = mockStatic(IdentityUtil.class); + scimCommonUtils = mockStatic(SCIMCommonUtils.class); + scimCommonComponentHolder.when(() -> SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService); when(realmService.getTenantUserRealm(anyInt())).thenReturn(userRealm); when(userRealm.getUserStoreManager()).thenReturn(userStoreManager); when(userStoreManager.isSCIMEnabled()).thenReturn(true); when(userStoreManager.getTenantId()).thenReturn(1); when(userStoreManager.getRealmConfiguration()).thenReturn(realmConfiguration); when(realmConfiguration.getAdminRoleName()).thenReturn("admin"); - when(UserCoreUtil.getDomainName((RealmConfiguration) anyObject())).thenReturn("testDomain"); - when(IdentityUtil.getPrimaryDomainName()).thenReturn("TESTDOMAIN"); - when(UserCoreUtil.addDomainToName(anyString(), anyString())).thenReturn(roleNameWithDomain); - when(SCIMCommonUtils.getGroupNameWithDomain(anyString())).thenReturn(roleNameWithDomain); - whenNew(SCIMGroupHandler.class).withAnyArguments().thenReturn(scimGroupHandler); + userCoreUtil.when(() -> UserCoreUtil.getDomainName((RealmConfiguration) any())).thenReturn("testDomain"); + identityUtil.when(() -> IdentityUtil.getPrimaryDomainName()).thenReturn("TESTDOMAIN"); + userCoreUtil.when(() -> UserCoreUtil.addDomainToName(anyString(), anyString())).thenReturn(roleNameWithDomain); + scimCommonUtils.when(() -> SCIMCommonUtils.getGroupNameWithDomain(anyString())).thenReturn(roleNameWithDomain); when(scimGroupHandler.isGroupExisting(anyString())).thenThrow(new IdentitySCIMException("testException")); adminAttributeUtil.updateAdminGroup(1); diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/SCIMCommonUtilsTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/SCIMCommonUtilsTest.java index 21b298c53..658407d6a 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/SCIMCommonUtilsTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/utils/SCIMCommonUtilsTest.java @@ -19,14 +19,10 @@ package org.wso2.carbon.identity.scim2.common.utils; import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.testng.PowerMockTestCase; -import org.testng.IObjectFactory; +import org.mockito.MockedStatic; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; -import org.testng.annotations.ObjectFactory; import org.testng.annotations.Test; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.base.CarbonBaseConstants; @@ -41,16 +37,13 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.when; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; - -@PrepareForTest({IdentityUtil.class, UserCoreUtil.class, IdentityTenantUtil.class, ServiceURLBuilder.class}) -@PowerMockIgnore({"javax.xml.*","org.w3c.dom.*","org.xml.sax.*"}) -public class SCIMCommonUtilsTest extends PowerMockTestCase { +public class SCIMCommonUtilsTest { private static final String ID = "8a439cf6-3c6b-47d2-94bf-34d072495af3"; private static final String SCIM_URL = "https://localhost:9443/scim2"; @@ -71,28 +64,28 @@ public class SCIMCommonUtilsTest extends PowerMockTestCase { @Mock DefaultServiceURLBuilder defaultServiceURLBuilder1; - @ObjectFactory - public IObjectFactory getObjectFactory() { - return new org.powermock.modules.testng.PowerMockObjectFactory(); - } + private MockedStatic userCoreUtil; + private MockedStatic identityTenantUtil; + private MockedStatic serviceURLBuilder; + private MockedStatic identityUtil; @BeforeMethod public void setUp() throws Exception { initMocks(this); - mockStatic(IdentityUtil.class); - mockStatic(UserCoreUtil.class); - mockStatic(IdentityTenantUtil.class); - mockStatic(ServiceURLBuilder.class); - when(IdentityUtil.getServerURL(anyString(), anyBoolean(), anyBoolean())).thenReturn(SCIM_URL); - when(IdentityUtil.getPrimaryDomainName()).thenReturn(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME); - when(ServiceURLBuilder.create()).thenReturn(defaultServiceURLBuilder); + identityUtil = mockStatic(IdentityUtil.class); + userCoreUtil = mockStatic(UserCoreUtil.class); + identityTenantUtil = mockStatic(IdentityTenantUtil.class); + serviceURLBuilder = mockStatic(ServiceURLBuilder.class); + identityUtil.when(() -> IdentityUtil.getServerURL(anyString(), anyBoolean(), anyBoolean())).thenReturn(SCIM_URL); + identityUtil.when(() -> IdentityUtil.getPrimaryDomainName()).thenReturn(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME); + serviceURLBuilder.when(() -> ServiceURLBuilder.create()).thenReturn(defaultServiceURLBuilder); when(defaultServiceURLBuilder.build()).thenReturn(serviceURL); when(defaultServiceURLBuilder.addPath(SCIMCommonConstants.SCIM2_ENDPOINT)).thenReturn (defaultServiceURLBuilder1); when(defaultServiceURLBuilder1.build()).thenReturn(serviceURL1); when(serviceURL1.getAbsolutePublicURL()).thenReturn("https://localhost:9443/scim2"); when(serviceURL.getAbsolutePublicURL()).thenReturn("https://localhost:9443"); - when(IdentityTenantUtil.getTenantDomainFromContext()).thenReturn("carbon.super"); + identityTenantUtil.when(() -> IdentityTenantUtil.getTenantDomainFromContext()).thenReturn("carbon.super"); } @AfterMethod @@ -103,7 +96,7 @@ public void tearDown() throws Exception { @Test(dataProvider = "tenantURLQualifyData") public void testGetSCIMUserURL(boolean isTenantQualifyURLEnabled) throws Exception { - when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); + identityTenantUtil.when(() -> IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); String scimUserURL = SCIMCommonUtils.getSCIMUserURL(ID); assertEquals(scimUserURL, scimUserLocation + "/" + ID); } @@ -111,7 +104,7 @@ public void testGetSCIMUserURL(boolean isTenantQualifyURLEnabled) throws Excepti @Test(dataProvider = "tenantURLQualifyData") public void testGetSCIMUserURLForNullId(boolean isTenantQualifyURLEnabled) throws Exception { - when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); + identityTenantUtil.when(() -> IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); String scimUserURL = SCIMCommonUtils.getSCIMUserURL(null); assertEquals(scimUserURL, null); } @@ -119,7 +112,7 @@ public void testGetSCIMUserURLForNullId(boolean isTenantQualifyURLEnabled) throw @Test(dataProvider = "tenantURLQualifyData") public void testGetSCIMGroupURL(boolean isTenantQualifyURLEnabled) throws Exception { - when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); + identityTenantUtil.when(() -> IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); String scimGroupURL = SCIMCommonUtils.getSCIMGroupURL(ID); assertEquals(scimGroupURL, scimGroupLocation + "/" + ID); } @@ -127,7 +120,7 @@ public void testGetSCIMGroupURL(boolean isTenantQualifyURLEnabled) throws Except @Test(dataProvider = "tenantURLQualifyData") public void testGetSCIMGroupURLForNullId(boolean isTenantQualifyURLEnabled) throws Exception { - when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); + identityTenantUtil.when(() -> IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); String scimGroupURL = SCIMCommonUtils.getSCIMGroupURL(null); assertEquals(scimGroupURL, null); } @@ -135,7 +128,7 @@ public void testGetSCIMGroupURLForNullId(boolean isTenantQualifyURLEnabled) thro @Test(dataProvider = "tenantURLQualifyData") public void testGetSCIMServiceProviderConfigURL(boolean isTenantQualifyURLEnabled) throws Exception { - when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); + identityTenantUtil.when(() -> IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); String scimServiceProviderConfigURL = SCIMCommonUtils.getSCIMServiceProviderConfigURL(ID); assertEquals(scimServiceProviderConfigURL, scimServiceProviderConfig); } @@ -143,7 +136,7 @@ public void testGetSCIMServiceProviderConfigURL(boolean isTenantQualifyURLEnable @Test(dataProvider = "tenantURLQualifyData") public void testGetSCIMUserURL1(boolean isTenantQualifyURLEnabled) throws Exception { - when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); + identityTenantUtil.when(() -> IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); String scimUsersURL = SCIMCommonUtils.getSCIMUserURL(); assertEquals(scimUsersURL, scimUserLocation); } @@ -151,7 +144,7 @@ public void testGetSCIMUserURL1(boolean isTenantQualifyURLEnabled) throws Except @Test(dataProvider = "tenantURLQualifyData") public void testGetSCIMGroupURL1(boolean isTenantQualifyURLEnabled) throws Exception { - when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); + identityTenantUtil.when(() -> IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); String scimGroupsURL = SCIMCommonUtils.getSCIMGroupURL(); assertEquals(scimGroupsURL, scimGroupLocation); } @@ -159,7 +152,7 @@ public void testGetSCIMGroupURL1(boolean isTenantQualifyURLEnabled) throws Excep @Test(dataProvider = "tenantURLQualifyData") public void testGetSCIMServiceProviderConfigURL1(boolean isTenantQualifyURLEnabled) throws Exception { - when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); + identityTenantUtil.when(() -> IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); String scimServiceProviderConfigURL = SCIMCommonUtils.getSCIMServiceProviderConfigURL(); assertEquals(scimServiceProviderConfigURL, scimServiceProviderConfig); } @@ -167,7 +160,7 @@ public void testGetSCIMServiceProviderConfigURL1(boolean isTenantQualifyURLEnabl @Test(dataProvider = "tenantURLQualifyData") public void testGetSCIMResourceTypeURL(boolean isTenantQualifyURLEnabled) throws Exception { - when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); + identityTenantUtil.when(() -> IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifyURLEnabled); String scimResourceTypeURL = SCIMCommonUtils.getSCIMResourceTypeURL(); assertEquals(scimResourceTypeURL, scimResourceType); } @@ -249,7 +242,7 @@ public void testSetThreadLocalIsManagedThroughSCIMEP(Boolean value, Boolean expe public void testGetGlobalConsumerId() throws Exception { String tenantDomain = "testTenantDomain"; CommonTestUtils.initPrivilegedCarbonContext(tenantDomain); - when(IdentityTenantUtil.getTenantDomainFromContext()).thenReturn(tenantDomain); + identityTenantUtil.when(() -> IdentityTenantUtil.getTenantDomainFromContext()).thenReturn(tenantDomain); assertEquals(SCIMCommonUtils.getGlobalConsumerId(), tenantDomain); } @@ -257,7 +250,7 @@ public void testGetGlobalConsumerId() throws Exception { public void testGetUserConsumerId() throws Exception { String userConsumerId = "testConsumerId"; CommonTestUtils.initPrivilegedCarbonContext(); - when(UserCoreUtil.addTenantDomainToEntry(anyString(), anyString())).thenReturn(userConsumerId); + userCoreUtil.when(() -> UserCoreUtil.addTenantDomainToEntry(anyString(), anyString())).thenReturn(userConsumerId); assertEquals(SCIMCommonUtils.getUserConsumerId(), userConsumerId); } diff --git a/pom.xml b/pom.xml index 52d30c9ba..1d84407dd 100644 --- a/pom.xml +++ b/pom.xml @@ -230,15 +230,9 @@ test - org.powermock - powermock-module-testng - ${powermock.version} - test - - - org.powermock - powermock-api-mockito2 - ${powermock.version} + org.mockito + mockito-testng + ${mockito-testng.version} test @@ -328,12 +322,12 @@ 1.7.21 - 6.9.10 + 7.10.1 0.8.4 - 2.23.4 - 2.0.2 - 2.22.2 + 3.2.5 + 5.3.1 + 0.5.2 1.10.1