Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove powermock from our unit tests, fixes #3960 #3964

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions assemblies/plugins/tech/aws/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
<aws-java-sdk-sns.version>1.12.651</aws-java-sdk-sns.version>
<aws-java-sdk-sqs.version>1.12.651</aws-java-sdk-sqs.version>
<redshift.jdbc.version>2.1.0.28</redshift.jdbc.version>

<!-- Test dependencies -->
<mockito.version>1.10.19</mockito.version>
<powermock.version>2.0.9</powermock.version>
</properties>


Expand Down
6 changes: 0 additions & 6 deletions assemblies/plugins/tech/google/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@
</dependency>

<!-- Google Analytics dependencies -->

<dependency>
<groupId>com.google.analytics</groupId>
<artifactId>google-analytics-data</artifactId>
<version>0.28.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
Expand Down
1 change: 0 additions & 1 deletion assemblies/plugins/transforms/json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<encoder.version>1.2</encoder.version>
<javax.servlet-api.version>3.0.1</javax.servlet-api.version>
<dependency.com.tinkerpop.blueprints.version>2.6.0</dependency.com.tinkerpop.blueprints.version>
<dependency.org.powermock.version>2.0.9</dependency.org.powermock.version>
<json-path.version>2.9.0</json-path.version>
<json-simple.version>1.1.1</json-simple.version>
<jsch.version>0.1.54</jsch.version>
Expand Down
20 changes: 10 additions & 10 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -471,16 +471,6 @@
<artifactId>java-hamcrest</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand Down Expand Up @@ -552,6 +542,16 @@
<version>2.13.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

package org.apache.hop.core.extension;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.hop.core.extension;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
Expand Down
75 changes: 38 additions & 37 deletions core/src/test/java/org/apache/hop/core/logging/LogChannelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,31 @@

package org.apache.hop.core.logging;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.when;

import org.apache.hop.core.util.Utils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;

@RunWith(PowerMockRunner.class)
@PrepareForTest({
DefaultLogLevel.class,
LoggingRegistry.class,
LogLevel.class,
HopLogStore.class,
Utils.class
})

public class LogChannelTest {

private MockedStatic<Utils> mockedUtils;

private MockedStatic<HopLogStore> mockedHopLogStore;

private MockedStatic<LoggingRegistry> mockedLoggingRegistry;

private MockedStatic<DefaultLogLevel> mockedDefaultLogLevel;

private LogChannel logChannel;
private String logChannelSubject = "pdi";
private String channelId = "1234-5678-abcd-efgh";
Expand All @@ -54,40 +52,47 @@ public class LogChannelTest {

@Before
public void setUp() throws Exception {
LogLevel logLevelStatic = PowerMockito.mock(LogLevel.class);
Whitebox.setInternalState(logLevelStatic, "name", "Basic");
Whitebox.setInternalState(logLevelStatic, "ordinal", 3);

PowerMockito.mockStatic(DefaultLogLevel.class);
when(DefaultLogLevel.getLogLevel()).thenReturn(LogLevel.BASIC);
LogLevel logLevelStatic = Mockito.mock(LogLevel.class);
mockedDefaultLogLevel.when(DefaultLogLevel::getLogLevel).thenReturn(LogLevel.BASIC);

logChFileWriterBuffer = mock(LogChannelFileWriterBuffer.class);

LoggingRegistry regInstance = mock(LoggingRegistry.class);
Mockito.when(regInstance.registerLoggingSource(logChannelSubject)).thenReturn(channelId);
Mockito.when(regInstance.getLogChannelFileWriterBuffer(channelId))
.thenReturn(logChFileWriterBuffer);
mockedLoggingRegistry.when(LoggingRegistry::getInstance).thenReturn(regInstance);

PowerMockito.mockStatic(LoggingRegistry.class);
when(LoggingRegistry.getInstance()).thenReturn(regInstance);

logLevel = PowerMockito.mock(LogLevel.class);
Whitebox.setInternalState(logLevel, "name", "Basic");
Whitebox.setInternalState(logLevel, "ordinal", 3);
logLevel = Mockito.mock(LogLevel.class);

logMsgInterface = mock(ILogMessage.class);
Mockito.when(logMsgInterface.getLevel()).thenReturn(logLevel);

logChannel = new LogChannel(logChannelSubject);
}

@BeforeEach
void setUpStaticMocks() {
mockedUtils = Mockito.mockStatic(Utils.class);
mockedHopLogStore = Mockito.mockStatic(HopLogStore.class);
mockedLoggingRegistry = Mockito.mockStatic(LoggingRegistry.class);
mockedDefaultLogLevel = Mockito.mockStatic(DefaultLogLevel.class);
}

@AfterEach
void tearDownStaticMocks() {
mockedDefaultLogLevel.closeOnDemand();
mockedLoggingRegistry.closeOnDemand();
mockedHopLogStore.closeOnDemand();
mockedUtils.closeOnDemand();
}

@Test
public void testPrintlnWithNullLogChannelFileWriterBuffer() {
when(logLevel.isVisible(any(LogLevel.class))).thenReturn(true);

LoggingBuffer loggingBuffer = mock(LoggingBuffer.class);
PowerMockito.mockStatic(HopLogStore.class);
when(HopLogStore.getAppender()).thenReturn(loggingBuffer);
mockedHopLogStore.when(HopLogStore::getAppender).thenReturn(loggingBuffer);

logChannel.println(logMsgInterface, LogLevel.BASIC);
verify(logChFileWriterBuffer, times(1)).addEvent(any(HopLoggingEvent.class));
Expand All @@ -103,17 +108,13 @@ public void testPrintlnLogNotVisible() {

@Test
public void testPrintMessageFiltered() {
LogLevel logLevelFil = PowerMockito.mock(LogLevel.class);
Whitebox.setInternalState(logLevelFil, "name", "Error");
Whitebox.setInternalState(logLevelFil, "ordinal", 1);
LogLevel logLevelFil = Mockito.mock(LogLevel.class);
when(logLevelFil.isError()).thenReturn(false);

ILogMessage logMsgInterfaceFil = mock(ILogMessage.class);
Mockito.when(logMsgInterfaceFil.getLevel()).thenReturn(logLevelFil);
Mockito.when(logMsgInterfaceFil.toString()).thenReturn("a");

PowerMockito.mockStatic(Utils.class);
when(Utils.isEmpty(anyString())).thenReturn(false);
mockedUtils.when(() -> Utils.isEmpty(anyString())).thenReturn(false);

when(logLevelFil.isVisible(any(LogLevel.class))).thenReturn(true);
logChannel.setFilter("b");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@
import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;

/**
* Note, this test must be run on separate JAVA instance, to be sure LoggingRegistry was not already
* initialized when using differed initialization or do initialize immediate in static way.
*/
@RunWith(PowerMockRunner.class)
public class LoggingRegistrySingltonTest {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
import static org.junit.Assert.assertNull;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
public class LoggingRegistryTest {
public static final String LOG_CHANEL_ID_PARENT = "parent-chanel-id";
public static final String LOG_CHANEL_ID_CHILD = "child-chanel-id";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
import static org.apache.hop.core.logging.LogLevel.BASIC;
import static org.apache.hop.core.logging.LogLevel.ERROR;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;

import java.util.function.Function;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.Logger;

@RunWith(MockitoJUnitRunner.class)
Expand Down Expand Up @@ -68,8 +68,8 @@ public void testAddLogEventNoRegisteredLogObject() {
when(message.getLevel()).thenReturn(ERROR);
listener.eventAdded(logEvent);
verify(diLogger).error(messageSub + " " + msgText);
verifyZeroInteractions(pipelineLogger);
verifyZeroInteractions(jobLogger);
verifyNoInteractions(pipelineLogger);
verifyNoInteractions(jobLogger);
}

@Test
Expand All @@ -84,8 +84,8 @@ public void testAddLogEventPipeline() {
when(message.getLevel()).thenReturn(LogLevel.ERROR);
listener.eventAdded(logEvent);
verify(pipelineLogger).error("[filename] " + msgText);
verifyZeroInteractions(diLogger);
verifyZeroInteractions(jobLogger);
verifyNoInteractions(diLogger);
verifyNoInteractions(jobLogger);
}

@Test
Expand All @@ -101,7 +101,7 @@ public void testAddLogEventJob() {
when(message.getLevel()).thenReturn(LogLevel.ERROR);
listener.eventAdded(logEvent);
verify(jobLogger).error("[filename] " + msgText);
verifyZeroInteractions(diLogger);
verifyZeroInteractions(pipelineLogger);
verifyNoInteractions(diLogger);
verifyNoInteractions(pipelineLogger);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,10 @@
import org.apache.hop.core.util.EnvUtil;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

@RunWith(PowerMockRunner.class)
public class ValueMetaAndDataTest {

private PluginRegistry pluginRegistry;
Expand Down Expand Up @@ -122,9 +117,7 @@ public void testConstructors() throws HopValueException {
}

@Test
@PrepareForTest({EnvUtil.class})
public void testLoadXml() throws HopValueException, HopPluginException, ParseException {
PowerMockito.mockStatic(EnvUtil.class);
Mockito.when(EnvUtil.getSystemProperty(Const.HOP_DEFAULT_DATE_FORMAT))
.thenReturn("yyyy-MM-dd HH:mm:ss.SSS");
ValueMetaAndData valueMetaAndData =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

package org.apache.hop.core.row.value;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyObject;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;

Expand Down Expand Up @@ -50,7 +50,7 @@ public void testSetPreparedStatementValue() throws Exception {
return ts.toString();
})
.when(ps)
.setTimestamp(anyInt(), (Timestamp) anyObject());
.setTimestamp(anyInt(), (Timestamp) any());

try {
vm.setPreparedStatementValue(mock(DatabaseMeta.class), ps, 0, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import java.util.ResourceBundle;
import java.util.UUID;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
public class GlobalMessagesTest {
/*
* Reading properties file without native2ascii. (use UTF8 characters) #620
Expand Down
Loading
Loading