From 4e88add9cf632bf759a6badb0c2719ea5f66692d Mon Sep 17 00:00:00 2001 From: Pamoda Wimalasiri Date: Tue, 29 Oct 2024 14:41:29 +0530 Subject: [PATCH] Remove Powermock dependencies from unit tests --- .../org.wso2.carbon.identity.sts.mgt/pom.xml | 8 ++-- .../sts/mgt/IdentityBaseUtilTest.java | 38 +++++++------------ .../pom.xml | 12 +++--- .../sts/passive/ui/PassiveSTSTest.java | 3 +- pom.xml | 24 ++++++------ 5 files changed, 38 insertions(+), 47 deletions(-) diff --git a/components/org.wso2.carbon.identity.sts.mgt/pom.xml b/components/org.wso2.carbon.identity.sts.mgt/pom.xml index 29b7362c..35ae889c 100644 --- a/components/org.wso2.carbon.identity.sts.mgt/pom.xml +++ b/components/org.wso2.carbon.identity.sts.mgt/pom.xml @@ -87,12 +87,12 @@ testng - org.powermock - powermock-module-testng + org.mockito + mockito-testng - org.powermock - powermock-api-mockito + org.mockito + mockito-core diff --git a/components/org.wso2.carbon.identity.sts.mgt/src/test/java/org/wso2/carbon/identity/sts/mgt/IdentityBaseUtilTest.java b/components/org.wso2.carbon.identity.sts.mgt/src/test/java/org/wso2/carbon/identity/sts/mgt/IdentityBaseUtilTest.java index a1f56662..eaea28b5 100644 --- a/components/org.wso2.carbon.identity.sts.mgt/src/test/java/org/wso2/carbon/identity/sts/mgt/IdentityBaseUtilTest.java +++ b/components/org.wso2.carbon.identity.sts.mgt/src/test/java/org/wso2/carbon/identity/sts/mgt/IdentityBaseUtilTest.java @@ -16,45 +16,35 @@ package org.wso2.carbon.identity.sts.mgt; import org.apache.neethi.Policy; -import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.testng.IObjectFactory; -import org.testng.annotations.ObjectFactory; +import org.mockito.MockedStatic; import org.testng.annotations.Test; import org.wso2.carbon.base.ServerConfiguration; import org.wso2.carbon.identity.sts.mgt.base.IdentityBaseUtil; -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.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; import static org.testng.Assert.assertNotNull; /** * Test class for IdentityBaseUtil test cases */ -@PrepareForTest({ServerConfiguration.class}) public class IdentityBaseUtilTest { - @Mock - private ServerConfiguration mockServerConfig; - @Test public void testGetDefaultRampartConfig() throws Exception { - //mock ServerConfiguration - mockStatic(ServerConfiguration.class); - when(ServerConfiguration.getInstance()).thenReturn(mockServerConfig); - when(mockServerConfig.getFirstProperty(anyString())).thenReturn("mockedValue"); - - Policy policy = IdentityBaseUtil.getDefaultRampartConfig(); - assertNotNull(policy); - assertNotNull(policy.getFirstPolicyComponent()); - } + // Mock ServerConfiguration + try (MockedStatic serverConfiguration = mockStatic(ServerConfiguration.class)) { - @ObjectFactory - public IObjectFactory getObjectFactory() { + ServerConfiguration mockServerConfiguration = mock(ServerConfiguration.class); + serverConfiguration.when(ServerConfiguration::getInstance).thenReturn(mockServerConfiguration); + when(mockServerConfiguration.getFirstProperty(anyString())).thenReturn("mockedValue"); - return new org.powermock.modules.testng.PowerMockObjectFactory(); + Policy policy = IdentityBaseUtil.getDefaultRampartConfig(); + assertNotNull(policy); + assertNotNull(policy.getFirstPolicyComponent()); + } } - } diff --git a/components/org.wso2.carbon.identity.sts.passive.ui/pom.xml b/components/org.wso2.carbon.identity.sts.passive.ui/pom.xml index 4ea47467..5570f2f0 100644 --- a/components/org.wso2.carbon.identity.sts.passive.ui/pom.xml +++ b/components/org.wso2.carbon.identity.sts.passive.ui/pom.xml @@ -33,6 +33,10 @@ http://www.wso2.com + + org.mockito + mockito-core + org.wso2.carbon org.wso2.carbon.ui @@ -97,12 +101,8 @@ testng - org.powermock - powermock-module-testng - - - org.powermock - powermock-api-mockito + org.mockito + mockito-testng org.wso2.carbon.identity.framework diff --git a/components/org.wso2.carbon.identity.sts.passive.ui/src/test/java/org/wso2/carbon/identity/sts/passive/ui/PassiveSTSTest.java b/components/org.wso2.carbon.identity.sts.passive.ui/src/test/java/org/wso2/carbon/identity/sts/passive/ui/PassiveSTSTest.java index 65ca78a3..e4d31a4f 100644 --- a/components/org.wso2.carbon.identity.sts.passive.ui/src/test/java/org/wso2/carbon/identity/sts/passive/ui/PassiveSTSTest.java +++ b/components/org.wso2.carbon.identity.sts.passive.ui/src/test/java/org/wso2/carbon/identity/sts/passive/ui/PassiveSTSTest.java @@ -35,7 +35,7 @@ import java.util.Map; import java.util.Set; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; import static org.testng.Assert.assertTrue; @@ -94,5 +94,4 @@ public String nextElement() { passiveSTS.doPost(request, response); assertTrue(true, "No MalformedURLException occurred."); } - } diff --git a/pom.xml b/pom.xml index 7b7b1bec..0589c0ca 100644 --- a/pom.xml +++ b/pom.xml @@ -309,15 +309,15 @@ test - org.powermock - powermock-module-testng - ${powermock.version} + org.mockito + mockito-testng + ${mockito-testng.version} test - org.powermock - powermock-api-mockito - ${powermock.version} + org.mockito + mockito-core + ${mockito.version} test @@ -450,7 +450,7 @@ - 7.0.73 + 7.5.94 ${project.version} 5.6.0 @@ -511,11 +511,13 @@ [2.8.2,3.0.0) 1.7.21 - 6.9.10 + 7.10.1 + 5.3.1 + 0.5.2 + 2.1.210 - 0.7.9 - 1.7.0 - 2.18.1 + 0.8.7 + 3.2.5 1.2.4