Skip to content

Commit

Permalink
Remove powermockito dependency (#1303)
Browse files Browse the repository at this point in the history
* merging commits

* Use FieldUtils.writeField instead of GenericGcsTest.setInternalState method

---------

Co-authored-by: Mohammad Ali Azam <mohammadali.azam@trianz.com>
  • Loading branch information
namratas-trianz and trianz-azam authored May 30, 2023
1 parent cf7d1fa commit 3d67aca
Show file tree
Hide file tree
Showing 49 changed files with 644 additions and 1,042 deletions.
22 changes: 4 additions & 18 deletions athena-cloudera-hive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,13 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.legacy.version}</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2 -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.powermock/powermock-core -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>${powermock.version}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-rds -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import org.testng.Assert;

@RunWith(PowerMockRunner.class)
@PrepareForTest(JDBCUtil.class)
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*",
"javax.management.*","org.w3c.*","javax.net.ssl.*","sun.security.*","jdk.internal.reflect.*"})
@RunWith(MockitoJUnitRunner.class)
public class HiveCompositeHandlerTest
{

Expand All @@ -48,9 +44,9 @@ public void HiveCompositeHandlerTest(){
try {
DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog1", HiveConstants.HIVE_NAME,
"hdphive2://jdbc:hive2://54.89.6.2:10000/authena;AuthMech=3;${testSecret}","testSecret");
PowerMockito.mockStatic(JDBCUtil.class);
JDBCUtil tested = PowerMockito.mock(JDBCUtil.class);
PowerMockito.when(tested.getSingleDatabaseConfigFromEnv(HiveConstants.HIVE_NAME, System.getenv())).thenReturn(databaseConnectionConfig);
Mockito.mockStatic(JDBCUtil.class);
JDBCUtil tested = Mockito.mock(JDBCUtil.class);
Mockito.when(tested.getSingleDatabaseConfigFromEnv(HiveConstants.HIVE_NAME, System.getenv())).thenReturn(databaseConnectionConfig);
new HiveCompositeHandler();
}catch(Exception e) {
ex =e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;


import java.sql.*;
import java.util.*;
Expand Down
28 changes: 5 additions & 23 deletions athena-cloudera-impala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,17 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<!--
This is purposefully using a legacy version because these tests
rely on powermock and it will break on a later version.
Eventually we should fix the test code to not rely on powermock.
-->

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.legacy.version}</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2 -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.powermock/powermock-core -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>${powermock.version}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-rds -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.testng.Assert;

@RunWith(PowerMockRunner.class)
@PrepareForTest(JDBCUtil.class)
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*",
"javax.management.*","org.w3c.*","javax.net.ssl.*","sun.security.*","jdk.internal.reflect.*"})
import org.mockito.Mockito;
@RunWith(MockitoJUnitRunner.class)
public class ImpalaCompositeHandlerTest
{
@BeforeClass
Expand All @@ -46,9 +40,10 @@ public void ImpalaCompositeHandlerTest(){
try {
DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog1", ImpalaConstants.IMPALA_NAME,
"impala://jdbc:impala://54.89.6.2:10000/authena;AuthMech=3;${testSecret}","testSecret");
PowerMockito.mockStatic(JDBCUtil.class);
JDBCUtil tested = PowerMockito.mock(JDBCUtil.class);
PowerMockito.when(tested.getSingleDatabaseConfigFromEnv(ImpalaConstants.IMPALA_NAME, System.getenv())).thenReturn(databaseConnectionConfig);
Mockito.mockStatic(JDBCUtil.class);
JDBCUtil tested = Mockito.mock(JDBCUtil.class);

Mockito.when(tested.getSingleDatabaseConfigFromEnv(ImpalaConstants.IMPALA_NAME, System.getenv())).thenReturn(databaseConnectionConfig);
new ImpalaCompositeHandler();
}catch(Exception e) {
ex =e;
Expand Down
25 changes: 4 additions & 21 deletions athena-datalakegen2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,16 @@
<version>${aws-cdk.version}</version>
<scope>test</scope>
</dependency>
<!--
This is purposefully using a legacy version because these tests
rely on powermock and it will break on a later version.
Eventually we should fix the test code to not rely on powermock.
-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.legacy.version}</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RunWith(PowerMockRunner.class)
@PrepareForTest(JDBCUtil.class)
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*",
"javax.management.*","org.w3c.*","javax.net.ssl.*","sun.security.*","jdk.internal.reflect.*"})
@RunWith(MockitoJUnitRunner.class)
public class DataLakeCompositeHandlerTest {

private DataLakeGen2CompositeHandler dataLakeGen2CompositeHandler;
Expand All @@ -50,9 +46,9 @@ public void dataLakeCompositeHandlerTest() {
try {
DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog1", DataLakeGen2Constants.NAME,
"datalakegentwo://jdbc:sqlserver://hostname;databaseName=fakedatabase;");
PowerMockito.mockStatic(JDBCUtil.class);
JDBCUtil tested = PowerMockito.mock(JDBCUtil.class);
PowerMockito.when(tested.getSingleDatabaseConfigFromEnv(DataLakeGen2Constants.NAME, System.getenv())).thenReturn(databaseConnectionConfig);
Mockito.mockStatic(JDBCUtil.class);
JDBCUtil tested = Mockito.mock(JDBCUtil.class);
Mockito.when(tested.getSingleDatabaseConfigFromEnv(DataLakeGen2Constants.NAME, System.getenv())).thenReturn(databaseConnectionConfig);
dataLakeGen2CompositeHandler = new DataLakeGen2CompositeHandler();
logger.info("dataLakeGen2CompositeHandler: {}", dataLakeGen2CompositeHandler);
} catch (Exception e){
Expand Down
33 changes: 5 additions & 28 deletions athena-db2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,42 +47,19 @@
<version>${aws-cdk.version}</version>
<scope>test</scope>
</dependency>
<!--
This is purposefully using a legacy version because these tests
rely on powermock and it will break on a later version.
Eventually we should fix the test code to not rely on powermock.
-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.legacy.version}</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-easymock -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RunWith(PowerMockRunner.class)
@PrepareForTest(JDBCUtil.class)
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*",
"javax.management.*","org.w3c.*","javax.net.ssl.*","sun.security.*","jdk.internal.reflect.*"})

@RunWith(MockitoJUnitRunner.class)
public class Db2CompositeHandlerTest
{
private Db2CompositeHandler db2CompositeHandler;
Expand All @@ -43,13 +39,12 @@ public class Db2CompositeHandlerTest
static {
System.setProperty("aws.region", "us-east-1");
}

@Test
public void Db2CompositeHandlerTest() {
DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog1", Db2Constants.NAME,
"dbtwo://jdbc:db2://hostname:50001/dummydatabase:user=dummyuser;password=dummypwd");
PowerMockito.mockStatic(JDBCUtil.class);
PowerMockito.when(JDBCUtil.getSingleDatabaseConfigFromEnv(Db2Constants.NAME, System.getenv())).thenReturn(databaseConnectionConfig);
Mockito.mockStatic(JDBCUtil.class);
Mockito.when(JDBCUtil.getSingleDatabaseConfigFromEnv(Db2Constants.NAME, System.getenv())).thenReturn(databaseConnectionConfig);
db2CompositeHandler = new Db2CompositeHandler();
logger.info("Db2CompositeHandler: {}", db2CompositeHandler);
Assert.assertTrue(db2CompositeHandler instanceof Db2CompositeHandler);
Expand Down
22 changes: 6 additions & 16 deletions athena-gcs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,7 @@
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand All @@ -111,21 +106,16 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.legacy.version}</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>${powermock.version}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>logs</artifactId>
Expand Down
Loading

0 comments on commit 3d67aca

Please sign in to comment.