Skip to content

Commit

Permalink
Remove Powermock dependencies from unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pamodaaw committed Oct 29, 2024
1 parent e3432c5 commit 4e88add
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 47 deletions.
8 changes: 4 additions & 4 deletions components/org.wso2.carbon.identity.sts.mgt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@
<artifactId>testng</artifactId>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-testng</artifactId>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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());
}
}

}
12 changes: 6 additions & 6 deletions components/org.wso2.carbon.identity.sts.passive.ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<url>http://www.wso2.com</url>

<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ui</artifactId>
Expand Down Expand Up @@ -97,12 +101,8 @@
<artifactId>testng</artifactId>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-testng</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -94,5 +94,4 @@ public String nextElement() {
passiveSTS.doPost(request, response);
assertTrue(true, "No MalformedURLException occurred.");
}

}
24 changes: 13 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,15 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<version>${powermock.version}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-testng</artifactId>
<version>${mockito-testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -450,7 +450,7 @@
</build>

<properties>
<identity.framework.version>7.0.73</identity.framework.version>
<identity.framework.version>7.5.94</identity.framework.version>
<identity.inbound.auth.sts.package.export.version>${project.version}
</identity.inbound.auth.sts.package.export.version>
<inbound.auth.openid.version>5.6.0</inbound.auth.openid.version>
Expand Down Expand Up @@ -511,11 +511,13 @@
<joda.wso2.osgi.version.range>[2.8.2,3.0.0)</joda.wso2.osgi.version.range>

<org.slf4j.verison>1.7.21</org.slf4j.verison>
<testng.version>6.9.10</testng.version>
<testng.version>7.10.1</testng.version>
<mockito.version>5.3.1</mockito.version>
<mockito-testng.version>0.5.2</mockito-testng.version>

<h2database.version>2.1.210</h2database.version>
<jacoco.version>0.7.9</jacoco.version>
<powermock.version>1.7.0</powermock.version>
<maven.surefire.plugin.version>2.18.1</maven.surefire.plugin.version>
<jacoco.version>0.8.7</jacoco.version>
<maven.surefire.plugin.version>3.2.5</maven.surefire.plugin.version>

<apache.felix.scr.ds.annotations.version>1.2.4</apache.felix.scr.ds.annotations.version>

Expand Down

0 comments on commit 4e88add

Please sign in to comment.