NIFI-6360 Updated Mockito to 2.28.2, PowerMock to 2.0.2

Fixed test failures in nifi-couchbase-processors, BinaryDocument matcher replaced with ByteArrayDocument
Fixed test failures in nifi-riemann-processors, anyInt() matcher replaced with anyLong() matcher, calling method passes a long, not int
Removed unnecessary method mocks from nifi-toolkit-tls tests, TlsCertificateAuthorityServiceHandlerTest and TlsCertificateSigningRequestPerformerTest, since those were flagged by Mockito as unnecessary (they're unused)
Removed explicit mockito dependency version in nifi-gcp-processors pom to inherit version from nifi's pom.xml
Updated ArgumentMatchers in Kafka 0.10, 0.11, 1.0, and 2.0 processor tests, since in Mockito 2.x, the "any" matchers no longer allow nulls
Updated ArgumentMatchers in nifi-jolt-transform-json-ui, since in Mockito 2.x, the "any" matchers no longer allow nulls
Removed unnecessary method mocks from MetricsReportingTaskTest
Updated TestStandardRemoteGroupPort to return Long instead of Integer for test flowfile.size() invocations
Updated AbstractCassandraProcessor to include keyspaceProperty.getValue() in null check
Updated SimpleProcessLogger and TestSimpleProcessLogger, vararg matching does not work the same in Java 8 and 11
Updated TestStandardProcessScheduler to allow null values during mock invocations, Mockito 2.x no longer allows nulls in those matchers
Updated TestPutHiveStreaming to allow null values during mock invocations, Mockito 2.x no longer allows nulls in those matchers
Updated FetchParquetTest to allow null values during mock invocations, Mockito 2.x no longer allows nulls in those matchers
Updated ControllerSearchServiceTest to allow null values during mock invocations, Mockito 2.x no longer allows nulls in those matchers
Removed usage of Whitebox from GetAzureEventHubTest due to Mockito 2.x, replaced with FieldUtils
Removed usage of Whitebox from StandardOidcIdentityProviderTest due to Mockito 2.x, replaced with FieldUtils
Updated apache-rat-plugin configuration in root POM to make use of useIdeaDefaultExcludes which makes the rat plugin exclude IntelliJ artifacts
Updated several modules to use mockito-core instead of mockito-all (discontinued in Mockito 2.x)
Updated nifi-site-to-site-reporting-task tests to be compatible with Mockito 2.x
Ignored TestPutJMS tests; the tests need to be refactored to work with Mockito 2.x, but the processor is deprecated.  Refactor may be done in a separate PR.
Adjusted several mock interaction iterations to 0 for TestPublishKafkaRecord_* tests.  Mockito 2.x flagged several interactions as unused and were adjusted to 0 interactions.
Updated PowerMock and Mockito dependencies to exclude transitive dependency on bytebuddy, added explicit dependency on bytebuddy 1.9.10 so that PowerMock and Mockito use the same version.  Bytebuddy 1.9.3 (used by PowerMock 2.0.2) did not allow for the mocking of final/private classes, bytebuddy 1.9.10 (used by Mockito 2.28.2) does.
Updated TestSiteToSiteProvenanceReportingTask use of InvocationOnMock.getArgument to use objects for the resulting object rather than primitives
Removed unnecessary stubs from evtx tests, Mockito 2.x defaults to strict mocks
Fixed classloader issue with tests in nifi-windows-event-log-processors module that use JNAJUnitRunner when Mockito mocked JNA classes (Kernel32)
Addressed Mockito-related deprecation warnings
Import cleanup

This closes #3533

Signed-off-by: Mike Thomsen <mikerthomsen@gmail.com>
This commit is contained in:
Jeff Storck 2019-06-06 16:53:04 -04:00 committed by Mike Thomsen
parent c7768c909a
commit 1d560e2b02
192 changed files with 1511 additions and 1530 deletions

View File

@ -40,7 +40,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
@ -204,7 +204,7 @@ public class TestPeerSelector {
doReturn(bootstrapNode).when(peerStatusProvider).getBootstrapPeerDescription();
doAnswer(invocation -> {
final PeerDescription peerFetchStatusesFrom = invocation.getArgumentAt(0, PeerDescription.class);
final PeerDescription peerFetchStatusesFrom = invocation.getArgument(0);
if (peerStatuses.stream().filter(ps -> ps.getPeerDescription().equals(peerFetchStatusesFrom)).collect(Collectors.toSet()).size() > 0) {
// If the remote peer is running, then return available peer statuses.
return peerStatuses;

View File

@ -36,8 +36,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
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.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@ -92,8 +92,8 @@ public class TestSiteInfoProvider {
// SiteInfoProvider uses SiteToSIteRestApiClient to get ControllerDTO.
doAnswer(invocation -> {
final SSLContext sslContext = invocation.getArgumentAt(0, SSLContext.class);
final HttpProxy httpProxy = invocation.getArgumentAt(1, HttpProxy.class);
final SSLContext sslContext = invocation.getArgument(0);
final HttpProxy httpProxy = invocation.getArgument(1);
assertEquals(expectedSslConText, sslContext);
assertEquals(expectedHttpProxy, httpProxy);

View File

@ -29,8 +29,8 @@ import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendWithIn
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendZeroFlowFile;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.readContents;
import static org.junit.Assert.assertEquals;
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.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;

View File

@ -57,7 +57,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -27,7 +27,7 @@ import org.apache.nifi.reporting.ReportingInitializationContext;
import org.apache.nifi.util.MockPropertyValue;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import javax.ws.rs.client.Client;
@ -91,7 +91,7 @@ public class TestAmbariReportingTask {
Mockito.when(client.target(metricsUrl)).thenReturn(target);
Mockito.when(target.request()).thenReturn(builder);
Mockito.when(builder.post(Matchers.any(Entity.class))).thenReturn(response);
Mockito.when(builder.post(ArgumentMatchers.any(Entity.class))).thenReturn(response);
// mock the ReportingInitializationContext for initialize(...)
final ComponentLog logger = Mockito.mock(ComponentLog.class);

View File

@ -52,7 +52,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -31,7 +31,7 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME;
import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.matches;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.Mockito.when;
public class TestHBaseTable {

View File

@ -31,7 +31,7 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME;
import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.matches;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.Mockito.when;
public class TestHDFSPath {

View File

@ -37,8 +37,8 @@ import static org.apache.nifi.atlas.provenance.analyzer.DatabaseAnalyzerUtil.ATT
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.matches;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.Mockito.when;
public class TestHive2JDBC {

View File

@ -31,8 +31,8 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME;
import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.matches;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.Mockito.when;
public class TestKafkaTopic {

View File

@ -40,7 +40,7 @@ import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_OUTPUT_PORT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.matches;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.Mockito.when;
/**

View File

@ -39,7 +39,7 @@ import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_OUTPUT_PORT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.matches;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.Mockito.when;
/**

View File

@ -32,7 +32,7 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
import static org.apache.nifi.atlas.provenance.analyzer.DatabaseAnalyzerUtil.ATTR_OUTPUT_TABLES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.matches;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.Mockito.when;
public class TestPutHiveStreaming {

View File

@ -36,7 +36,7 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.matches;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.Mockito.when;
public class TestUnknownDataSet {

View File

@ -86,10 +86,10 @@ import static org.apache.nifi.provenance.ProvenanceEventType.JOIN;
import static org.apache.nifi.provenance.ProvenanceEventType.RECEIVE;
import static org.apache.nifi.provenance.ProvenanceEventType.REMOTE_INVOCATION;
import static org.apache.nifi.provenance.ProvenanceEventType.SEND;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -31,7 +31,7 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import com.amazonaws.AmazonClientException;
@ -45,12 +45,7 @@ import com.amazonaws.services.dynamodbv2.model.BatchWriteItemResult;
import com.amazonaws.services.dynamodbv2.model.DeleteRequest;
import com.amazonaws.services.dynamodbv2.model.WriteRequest;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.Before;
import org.junit.Test;
public class DeleteDynamoDBTest extends AbstractDynamoDBTest{
public class DeleteDynamoDBTest extends AbstractDynamoDBTest {
protected DeleteDynamoDB deleteDynamoDB;
protected BatchWriteItemResult result = new BatchWriteItemResult();
@ -81,7 +76,7 @@ public class DeleteDynamoDBTest extends AbstractDynamoDBTest{
// Inject a mock DynamoDB to create the exception condition
final DynamoDB mockDynamoDb = Mockito.mock(DynamoDB.class);
// When writing, mock thrown service exception from AWS
Mockito.when(mockDynamoDb.batchWriteItem(Matchers.<TableWriteItems>anyVararg())).thenThrow(getSampleAwsServiceException());
Mockito.when(mockDynamoDb.batchWriteItem(ArgumentMatchers.<TableWriteItems>any())).thenThrow(getSampleAwsServiceException());
deleteDynamoDB = new DeleteDynamoDB() {
@Override

View File

@ -33,7 +33,7 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import com.amazonaws.AmazonClientException;
@ -404,7 +404,7 @@ public class GetDynamoDBTest extends AbstractDynamoDBTest {
// Inject a mock DynamoDB to create the exception condition
final DynamoDB mockDynamoDb = Mockito.mock(DynamoDB.class);
// When writing, mock thrown service exception from AWS
Mockito.when(mockDynamoDb.batchGetItem(Matchers.<TableKeysAndAttributes>anyVararg())).thenThrow(getSampleAwsServiceException());
Mockito.when(mockDynamoDb.batchGetItem(ArgumentMatchers.<TableKeysAndAttributes>any())).thenThrow(getSampleAwsServiceException());
getDynamoDB = new GetDynamoDB() {
@Override

View File

@ -31,7 +31,7 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import com.amazonaws.AmazonClientException;
@ -76,7 +76,7 @@ public class PutDynamoDBTest extends AbstractDynamoDBTest {
// Inject a mock DynamoDB to create the exception condition
final DynamoDB mockDynamoDb = Mockito.mock(DynamoDB.class);
// When writing, mock thrown service exception from AWS
Mockito.when(mockDynamoDb.batchWriteItem(Matchers.<TableWriteItems>anyVararg())).thenThrow(getSampleAwsServiceException());
Mockito.when(mockDynamoDb.batchWriteItem(ArgumentMatchers.<TableWriteItems>any())).thenThrow(getSampleAwsServiceException());
putDynamoDB = new PutDynamoDB() {
@Override

View File

@ -314,6 +314,6 @@ public class TestTagS3Object {
private void mockGetExistingTags(Tag... currentTag) {
List<Tag> currentTags = new ArrayList<>(Arrays.asList(currentTag));
Mockito.when(mockS3Client.getObjectTagging(Mockito.anyObject())).thenReturn(new GetObjectTaggingResult(currentTags));
Mockito.when(mockS3Client.getObjectTagging(Mockito.any())).thenReturn(new GetObjectTaggingResult(currentTags));
}
}

View File

@ -16,8 +16,8 @@
*/
package org.apache.nifi.processors.aws.wag;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.times;
import com.amazonaws.ClientConfiguration;
@ -91,14 +91,11 @@ public class TestInvokeAmazonGatewayApiMock {
// check
Mockito.verify(mockSdkClient, times(1))
.execute(argThat(new RequestMatcher<HttpUriRequest>(x -> {
return x.getMethod().equals("GET") && x.getFirstHeader("x-api-key").getValue()
.equals("abcd") && x
.getFirstHeader("Authorization").getValue().startsWith("AWS4") && x.getURI()
.toString()
.equals(
"https://foobar.execute-api.us-east-1.amazonaws.com/TEST");
})), any(HttpContext.class));
.execute(argThat(argument -> argument.getMethod().equals("GET")
&& argument.getFirstHeader("x-api-key").getValue().equals("abcd")
&& argument.getFirstHeader("Authorization").getValue().startsWith("AWS4")
&& argument.getURI().toString().equals("https://foobar.execute-api.us-east-1.amazonaws.com/TEST")),
any(HttpContext.class));
runner.assertTransferCount(InvokeAWSGatewayApi.REL_SUCCESS_REQ, 0);
runner.assertTransferCount(InvokeAWSGatewayApi.REL_RESPONSE, 1);
@ -141,15 +138,13 @@ public class TestInvokeAmazonGatewayApiMock {
runner.run(1);
Mockito.verify(mockSdkClient, times(1))
.execute(argThat(new RequestMatcher<HttpUriRequest>(x -> {
return x.getMethod().equals("GET") && x.getFirstHeader("x-api-key").getValue()
.equals("abcd") && x
.getFirstHeader("Authorization").getValue().startsWith("AWS4") && x
.getFirstHeader("dynamicHeader").getValue().equals("yes!") && x
.getFirstHeader("Foo").getValue().equals("Bar") && x.getURI().toString()
.equals(
"https://foobar.execute-api.us-east-1.amazonaws.com/TEST");
})), any(HttpContext.class));
.execute(argThat(argument -> argument.getMethod().equals("GET")
&& argument.getFirstHeader("x-api-key").getValue().equals("abcd")
&& argument.getFirstHeader("Authorization").getValue().startsWith("AWS4")
&& argument.getFirstHeader("dynamicHeader").getValue().equals("yes!")
&& argument.getFirstHeader("Foo").getValue().equals("Bar")
&& argument.getURI().toString().equals("https://foobar.execute-api.us-east-1.amazonaws.com/TEST")),
any(HttpContext.class));
// check
runner.assertTransferCount(InvokeAWSGatewayApi.REL_SUCCESS_REQ, 1);
runner.assertTransferCount(InvokeAWSGatewayApi.REL_RESPONSE, 1);
@ -194,15 +189,13 @@ public class TestInvokeAmazonGatewayApiMock {
runner.run(1);
Mockito.verify(mockSdkClient, times(1))
.execute(argThat(new RequestMatcher<HttpUriRequest>(x -> {
return x.getMethod().equals("GET") && x.getFirstHeader("x-api-key").getValue()
.equals("abcd") && x
.getFirstHeader("Authorization").getValue().startsWith("AWS4") && x
.getFirstHeader("dynamicHeader").getValue().equals("yes!") && x
.getFirstHeader("Foo").getValue().equals("Bar") && x.getURI().toString()
.equals(
"https://foobar.execute-api.us-east-1.amazonaws.com/TEST?dogs=cats&apples=oranges");
})), any(HttpContext.class));
.execute(argThat(argument -> argument.getMethod().equals("GET")
&& argument.getFirstHeader("x-api-key").getValue().equals("abcd")
&& argument.getFirstHeader("Authorization").getValue().startsWith("AWS4")
&& argument.getFirstHeader("dynamicHeader").getValue().equals("yes!")
&& argument.getFirstHeader("Foo").getValue().equals("Bar")
&& argument.getURI().toString().equals("https://foobar.execute-api.us-east-1.amazonaws.com/TEST?dogs=cats&apples=oranges")),
any(HttpContext.class));
// check
runner.assertTransferCount(InvokeAWSGatewayApi.REL_SUCCESS_REQ, 1);
runner.assertTransferCount(InvokeAWSGatewayApi.REL_RESPONSE, 1);

View File

@ -23,6 +23,7 @@ import com.microsoft.azure.servicebus.ServiceBusException;
import com.microsoft.azure.servicebus.amqp.AmqpConstants;
import java.io.IOException;
import java.lang.reflect.Field;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
@ -31,6 +32,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.concurrent.ExecutionException;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.exception.ProcessException;
import org.apache.nifi.util.MockFlowFile;
@ -38,7 +40,6 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.Before;
import org.junit.Test;
import org.mockito.internal.util.reflection.Whitebox;
public class GetAzureEventHubTest {
@ -187,7 +188,12 @@ public class GetAzureEventHubTest {
properties.put(AmqpConstants.ENQUEUED_TIME_UTC_ANNOTATION_NAME, ENQUEUED_TIME_VALUE);
SystemProperties systemProperties = new SystemProperties(properties);
Whitebox.setInternalState(eventData, "systemProperties", systemProperties);
Field systemPropertiesField = FieldUtils.getDeclaredField(EventData.class, "systemProperties", true);
try {
systemPropertiesField.set(eventData, systemProperties);
} catch (IllegalAccessException e) {
throw new ProcessException("Could not set systemProperties on EventData", e);
}
}
receivedEvents.add(eventData);
}

View File

@ -57,8 +57,8 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyMap;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -181,11 +181,11 @@ public class TestConsumeAzureEventHub {
final RecordSetWriter writer = mock(RecordSetWriter.class);
final AtomicReference<OutputStream> outRef = new AtomicReference<>();
when(writerFactory.createWriter(any(), any(), any())).thenAnswer(invocation -> {
outRef.set(invocation.getArgumentAt(2, OutputStream.class));
outRef.set(invocation.getArgument(2));
return writer;
});
when(writer.write(any(Record.class))).thenAnswer(invocation -> {
final String value = (String) invocation.getArgumentAt(0, Record.class).getValue("value");
final String value = (String) invocation.<Record>getArgument(0).getValue("value");
if (throwErrorWith != null && throwErrorWith.equals(value)) {
throw new IOException("Simulating record write failure.");
}

View File

@ -293,7 +293,8 @@ public abstract class AbstractCassandraProcessor extends AbstractProcessor {
PropertyValue keyspaceProperty = context.getProperty(KEYSPACE).evaluateAttributeExpressions();
final Session newSession;
if (keyspaceProperty != null) {
// For Java 11, the getValue() call was added so the test could pass
if (keyspaceProperty != null && keyspaceProperty.getValue() != null) {
newSession = newCluster.connect(keyspaceProperty.getValue());
} else {
newSession = newCluster.connect();

View File

@ -35,9 +35,9 @@ import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -43,9 +43,9 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

View File

@ -40,9 +40,9 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

View File

@ -19,9 +19,9 @@ package org.apache.nifi.processors.cassandra;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -67,7 +67,7 @@ import java.util.regex.Pattern
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue
import static org.mockito.Matchers.anyString
import static org.mockito.ArgumentMatchers.anyString
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.when

View File

@ -34,8 +34,8 @@ import java.util.Map;
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.BUCKET_NAME;
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.COUCHBASE_CLUSTER_SERVICE;
import static org.junit.Assert.assertEquals;
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.when;

View File

@ -58,7 +58,7 @@ import static org.apache.nifi.processors.couchbase.CouchbaseAttributes.Exception
import static org.apache.nifi.processors.couchbase.GetCouchbaseKey.PUT_VALUE_TO_ATTRIBUTE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -26,9 +26,9 @@ import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.RE
import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.REL_SUCCESS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@ -39,7 +39,7 @@ import java.util.HashMap;
import java.util.Map;
import com.couchbase.client.deps.io.netty.buffer.Unpooled;
import com.couchbase.client.java.document.BinaryDocument;
import com.couchbase.client.java.document.ByteArrayDocument;
import org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException;
import org.apache.nifi.couchbase.CouchbaseClusterControllerService;
import org.apache.nifi.couchbase.DocumentType;
@ -134,8 +134,8 @@ public class TestPutCouchbaseKey {
byte[] inFileDataBytes = inFileData.getBytes(StandardCharsets.UTF_8);
Bucket bucket = mock(Bucket.class);
when(bucket.upsert(any(BinaryDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.NONE)))
.thenReturn(BinaryDocument.create(docId, expiry, Unpooled.copiedBuffer(inFileData.getBytes(StandardCharsets.UTF_8)), cas));
when(bucket.upsert(any(ByteArrayDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.NONE)))
.thenReturn(ByteArrayDocument.create(docId, expiry, Unpooled.copiedBuffer(inFileData.getBytes(StandardCharsets.UTF_8)).array(), cas));
setupMockBucket(bucket);
testRunner.enqueue(inFileDataBytes);
@ -144,7 +144,7 @@ public class TestPutCouchbaseKey {
testRunner.setProperty(DOCUMENT_TYPE, DocumentType.Binary.name());
testRunner.run();
verify(bucket, times(1)).upsert(any(BinaryDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.NONE));
verify(bucket, times(1)).upsert(any(ByteArrayDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.NONE));
testRunner.assertAllFlowFilesTransferred(REL_SUCCESS);
testRunner.assertTransferCount(REL_SUCCESS, 1);

View File

@ -77,7 +77,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

View File

@ -43,7 +43,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.verify;

View File

@ -37,7 +37,7 @@ import scala.runtime.BoxedUnit;
import java.util.List;
import java.util.Map;
import static org.mockito.Matchers.anyObject;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -112,7 +112,7 @@ public class MockDruidTranquilityController extends DruidTranquilityController {
return null;
}
};
when(t.send(anyObject())).thenReturn(future);
when(t.send(any())).thenReturn(future);
when(t.status()).thenReturn(new Status() {
});
cf = mock(CuratorFramework.class);

View File

@ -56,7 +56,7 @@ import java.util.concurrent.ExecutionException;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

View File

@ -17,7 +17,7 @@
package org.apache.nifi.processors.elasticsearch;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

View File

@ -146,7 +146,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

View File

@ -19,7 +19,7 @@ package org.apache.nifi.processors.elasticsearch;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -19,7 +19,7 @@ package org.apache.nifi.processors.elasticsearch;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

View File

@ -18,7 +18,7 @@ package org.apache.nifi.processors.elasticsearch;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -53,7 +53,7 @@ import java.util.function.Consumer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -19,7 +19,7 @@ package org.apache.nifi.processors.elasticsearch;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -18,7 +18,7 @@ package org.apache.nifi.processors.elasticsearch;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -18,7 +18,7 @@ package org.apache.nifi.processors.elasticsearch;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -73,20 +73,61 @@
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.5</version>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.5</version>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito-common</artifactId>
<version>1.6.5</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
<exclusions>
<!-- bytebuddy excluded, will be listed as an explicit dependency of the same version as the transitive
dependency -->
<exclusion>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</exclusion>
<exclusion>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>2.0.2</version>
<scope>test</scope>
<exclusions>
<!-- bytebuddy excluded due to the transitive dependency version (1.9.3) not being able to mock
final/private classes -->
<exclusion>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</exclusion>
<exclusion>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- included explicitly for use with mockito-core and powermock-core -->
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.9.10</version>
</dependency>
<dependency>
<!-- included explicitly for use with mockito-core and powermock-core -->
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>1.9.10</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>

View File

@ -60,7 +60,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -26,13 +26,13 @@ import org.apache.nifi.processor.io.OutputStreamCallback;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.ByteArrayOutputStream;
import static org.junit.Assert.assertArrayEquals;
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;

View File

@ -35,7 +35,7 @@ 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.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

View File

@ -26,11 +26,11 @@ import org.apache.nifi.processor.Relationship;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

View File

@ -37,7 +37,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

View File

@ -21,7 +21,7 @@ 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 javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

View File

@ -24,7 +24,7 @@ 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 java.io.IOException;
import java.util.Date;

View File

@ -22,7 +22,7 @@ import org.apache.nifi.processors.evtx.parser.TestBinaryReaderBuilder;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.IOException;

View File

@ -88,8 +88,6 @@ public class OpenStartElementNodeTest extends BxmlNodeWithTokenTestBase {
testBinaryReaderBuilder.put((byte) BxmlNode.CLOSE_EMPTY_ELEMENT_TOKEN);
BinaryReader binaryReader = testBinaryReaderBuilder.build();
NameStringNode nameStringNode = mock(NameStringNode.class);
when(nameStringNode.getString()).thenReturn(tagName);
when(chunkHeader.addNameStringNode(stringOffset, binaryReader)).thenAnswer(invocation -> new NameStringNode(binaryReader, chunkHeader));
openStartElementNode = new OpenStartElementNode(binaryReader, chunkHeader, parent);

View File

@ -83,7 +83,6 @@ public class TemplateInstanceNodeTest extends BxmlNodeWithTokenTestBase {
BinaryReader binaryReader = testBinaryReaderBuilder.build();
TemplateNode templateNode = mock(TemplateNode.class);
when(templateNode.getTemplateId()).thenReturn(UnsignedInteger.valueOf(templateId));
when(templateNode.hasEndOfStream()).thenReturn(true).thenReturn(false);
when(chunkHeader.addTemplateNode(5, binaryReader)).thenAnswer(invocation -> {
binaryReader.skip(templateLength);
return templateNode;

View File

@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -22,7 +22,7 @@ import org.mockito.ArgumentMatcher;
/**
* ArgumentMatcher for SchemaIdentifier.
*/
public class SchemaIdentifierMatcher extends ArgumentMatcher<SchemaIdentifier> {
public class SchemaIdentifierMatcher implements ArgumentMatcher<SchemaIdentifier> {
private final SchemaIdentifier expectedIdentifier;
@ -31,12 +31,10 @@ public class SchemaIdentifierMatcher extends ArgumentMatcher<SchemaIdentifier> {
}
@Override
public boolean matches(final Object argument) {
if (argument == null || !(argument instanceof SchemaIdentifier)) {
public boolean matches(SchemaIdentifier argument) {
if (argument == null) {
return false;
}
final SchemaIdentifier other = (SchemaIdentifier) argument;
return other.equals(expectedIdentifier);
return argument.equals(expectedIdentifier);
}
}

View File

@ -27,7 +27,7 @@ import java.io.IOException;
import java.util.Collections;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.when;
public class TestConfluentSchemaRegistryStrategy extends AbstractSchemaAccessStrategyTest {

View File

@ -26,7 +26,7 @@ import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.when;
public class TestHortonworksAttributeSchemaReferenceStrategy extends AbstractSchemaAccessStrategyTest {

View File

@ -27,7 +27,7 @@ import java.io.IOException;
import java.util.Collections;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.when;
public class TestHortonworksEncodedSchemaReferenceStrategy extends AbstractSchemaAccessStrategyTest {

View File

@ -45,8 +45,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -47,7 +47,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -41,8 +41,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -25,7 +25,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -30,7 +30,7 @@ import static org.apache.nifi.authorization.CompositeUserGroupProvider.PROP_USER
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -30,7 +30,7 @@ import java.util.stream.Stream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

View File

@ -26,11 +26,10 @@ import org.apache.nifi.authorization.user.NiFiUser;
import org.apache.nifi.authorization.user.StandardNiFiUser.Builder;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@ -54,7 +53,7 @@ public class DataAuthorizableTest {
testAuthorizer = mock(Authorizer.class);
when(testAuthorizer.authorize(any(AuthorizationRequest.class))).then(invocation -> {
final AuthorizationRequest request = invocation.getArgumentAt(0, AuthorizationRequest.class);
final AuthorizationRequest request = invocation.getArgument(0);
if (IDENTITY_1.equals(request.getIdentity())) {
return AuthorizationResult.approved();
@ -99,12 +98,7 @@ public class DataAuthorizableTest {
final NiFiUser user = new Builder().identity(IDENTITY_1).build();
testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null);
verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return IDENTITY_1.equals(((AuthorizationRequest) o).getIdentity());
}
}));
verify(testAuthorizer, times(1)).authorize(argThat(o -> IDENTITY_1.equals(o.getIdentity())));
}
@Test
@ -113,12 +107,7 @@ public class DataAuthorizableTest {
final AuthorizationResult result = testDataAuthorizable.checkAuthorization(testAuthorizer, RequestAction.READ, user, null);
assertEquals(Result.Approved, result.getResult());
verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return IDENTITY_1.equals(((AuthorizationRequest) o).getIdentity());
}
}));
verify(testAuthorizer, times(1)).authorize(argThat(o -> IDENTITY_1.equals(o.getIdentity())));
}
@Test
@ -149,12 +138,7 @@ public class DataAuthorizableTest {
}
private void verifyAuthorizeForUser(final String identity) {
verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return identity.equals(((AuthorizationRequest) o).getIdentity());
}
}));
verify(testAuthorizer, times(1)).authorize(argThat(o -> identity.equals(o.getIdentity())));
}
}

View File

@ -26,11 +26,10 @@ import org.apache.nifi.authorization.user.NiFiUser;
import org.apache.nifi.authorization.user.StandardNiFiUser.Builder;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@ -52,7 +51,7 @@ public class ProvenanceDataAuthorizableTest {
testAuthorizer = mock(Authorizer.class);
when(testAuthorizer.authorize(any(AuthorizationRequest.class))).then(invocation -> {
final AuthorizationRequest request = invocation.getArgumentAt(0, AuthorizationRequest.class);
final AuthorizationRequest request = invocation.getArgument(0);
if (IDENTITY_1.equals(request.getIdentity())) {
return AuthorizationResult.approved();
@ -93,12 +92,7 @@ public class ProvenanceDataAuthorizableTest {
final NiFiUser user = new Builder().identity(IDENTITY_1).build();
testProvenanceDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null);
verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return IDENTITY_1.equals(((AuthorizationRequest) o).getIdentity());
}
}));
verify(testAuthorizer, times(1)).authorize(argThat(o -> IDENTITY_1.equals(o.getIdentity())));
}
@Test
@ -107,11 +101,6 @@ public class ProvenanceDataAuthorizableTest {
final AuthorizationResult result = testProvenanceDataAuthorizable.checkAuthorization(testAuthorizer, RequestAction.READ, user, null);
assertEquals(Result.Approved, result.getResult());
verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return IDENTITY_1.equals(((AuthorizationRequest) o).getIdentity());
}
}));
verify(testAuthorizer, times(1)).authorize(argThat(o -> IDENTITY_1.equals(o.getIdentity())));
}
}

View File

@ -22,7 +22,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -91,7 +91,7 @@ public class TestPopularVoteFlowElection {
Mockito.when(fingerprintFactory.createFingerprint(Mockito.any(byte[].class))).thenAnswer(new Answer<String>() {
@Override
public String answer(final InvocationOnMock invocation) throws Throwable {
final byte[] flow = invocation.getArgumentAt(0, byte[].class);
final byte[] flow = invocation.getArgument(0);
final String xml = new String(flow);
// Return the ID of the root group as the fingerprint.
@ -217,7 +217,7 @@ public class TestPopularVoteFlowElection {
final NiFiProperties nifiProperties = mock(NiFiProperties.class);
when(nifiProperties.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_ALGORITHM)).thenReturn("PBEWITHMD5AND256BITAES-CBC-OPENSSL");
when(nifiProperties.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_PROVIDER)).thenReturn("BC");
when(nifiProperties.getProperty(anyString(), anyString())).then(invocation -> invocation.getArgumentAt(1, String.class));
when(nifiProperties.getProperty(anyString(), anyString())).then(invocation -> invocation.getArgument(1));
return nifiProperties;
}

View File

@ -286,7 +286,7 @@ public class TestThreadPoolRequestReplicator {
when(coordinator.getConnectionStatus(Mockito.any(NodeIdentifier.class))).thenAnswer(new Answer<NodeConnectionStatus>() {
@Override
public NodeConnectionStatus answer(InvocationOnMock invocation) throws Throwable {
return new NodeConnectionStatus(invocation.getArgumentAt(0, NodeIdentifier.class), NodeConnectionState.CONNECTED);
return new NodeConnectionStatus(invocation.getArgument(0), NodeConnectionState.CONNECTED);
}
});

View File

@ -61,8 +61,8 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
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.when;
public class TestNodeClusterCoordinator {
@ -181,7 +181,7 @@ public class TestNodeClusterCoordinator {
when(senderListener.requestReconnection(any(ReconnectionRequestMessage.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
final ReconnectionRequestMessage msg = invocation.getArgumentAt(0, ReconnectionRequestMessage.class);
final ReconnectionRequestMessage msg = invocation.getArgument(0);
requestRef.set(msg);
return null;
}

View File

@ -44,8 +44,8 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyCollection;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
public class TestFileSystemSwapManager {

View File

@ -94,8 +94,8 @@ import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyCollection;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -150,7 +150,7 @@ public class LoadBalancedQueueIT {
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocation) {
clusterEventListeners.add(invocation.getArgumentAt(0, ClusterTopologyEventListener.class));
clusterEventListeners.add(invocation.getArgument(0));
return null;
}
}).when(clusterCoordinator).registerEventListener(any(ClusterTopologyEventListener.class));
@ -1029,7 +1029,7 @@ public class LoadBalancedQueueIT {
};
}
final ContentClaim contentClaim = invocation.getArgumentAt(0, ContentClaim.class);
final ContentClaim contentClaim = invocation.getArgument(0);
final ByteArrayOutputStream baos = new ByteArrayOutputStream() {
@Override
public void close() throws IOException {
@ -1287,7 +1287,7 @@ public class LoadBalancedQueueIT {
private FlowFileRepository createFlowFileRepository(final List<RepositoryRecord> repoRecords) throws IOException {
final FlowFileRepository flowFileRepo = mock(FlowFileRepository.class);
doAnswer(invocation -> {
final Collection records = invocation.getArgumentAt(0, Collection.class);
final Collection records = invocation.getArgument(0);
repoRecords.addAll(records);
return null;
}).when(flowFileRepo).updateRepository(anyCollection());
@ -1310,7 +1310,7 @@ public class LoadBalancedQueueIT {
Mockito.doAnswer(new Answer<OutputStream>() {
@Override
public OutputStream answer(final InvocationOnMock invocation) {
final ContentClaim contentClaim = invocation.getArgumentAt(0, ContentClaim.class);
final ContentClaim contentClaim = invocation.getArgument(0);
final ByteArrayOutputStream baos = new ByteArrayOutputStream() {
@Override
@ -1328,7 +1328,7 @@ public class LoadBalancedQueueIT {
Mockito.doAnswer(new Answer<InputStream>() {
@Override
public InputStream answer(final InvocationOnMock invocation) {
final ContentClaim contentClaim = invocation.getArgumentAt(0, ContentClaim.class);
final ContentClaim contentClaim = invocation.getArgument(0);
if (contentClaim == null) {
return new ByteArrayInputStream(new byte[0]);
}

View File

@ -115,7 +115,7 @@ public class TestSocketLoadBalancedFlowFileQueue {
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
clusterTopologyEventListener = invocation.getArgumentAt(0, ClusterTopologyEventListener.class);
clusterTopologyEventListener = invocation.getArgument(0);
return null;
}
}).when(clusterCoordinator).registerEventListener(Mockito.any(ClusterTopologyEventListener.class));

View File

@ -47,7 +47,6 @@ import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@ -73,8 +72,8 @@ import static org.apache.nifi.controller.queue.clustered.protocol.LoadBalancePro
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyCollection;
import static org.mockito.Matchers.anyList;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
@ -120,7 +119,7 @@ public class TestStandardLoadBalanceProtocol {
Mockito.doAnswer(new Answer<OutputStream>() {
@Override
public OutputStream answer(final InvocationOnMock invocation) throws Throwable {
final ContentClaim contentClaim = invocation.getArgumentAt(0, ContentClaim.class);
final ContentClaim contentClaim = invocation.getArgument(0);
final ByteArrayOutputStream baos = new ByteArrayOutputStream() {
@Override
@ -146,7 +145,7 @@ public class TestStandardLoadBalanceProtocol {
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
flowFileQueuePutRecords.addAll(invocation.getArgumentAt(0, Collection.class));
flowFileQueuePutRecords.addAll(invocation.getArgument(0));
return null;
}
}).when(flowFileQueue).putAll(anyCollection());
@ -154,7 +153,7 @@ public class TestStandardLoadBalanceProtocol {
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
flowFileQueueReceiveRecords.addAll(invocation.getArgumentAt(0, Collection.class));
flowFileQueueReceiveRecords.addAll(invocation.getArgument(0));
return null;
}
}).when(flowFileQueue).receiveFromPeer(anyCollection());
@ -162,7 +161,7 @@ public class TestStandardLoadBalanceProtocol {
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
flowFileRepoUpdateRecords.addAll(invocation.getArgumentAt(0, Collection.class));
flowFileRepoUpdateRecords.addAll(invocation.getArgument(0));
return null;
}
}).when(flowFileRepo).updateRepository(anyCollection());
@ -170,7 +169,7 @@ public class TestStandardLoadBalanceProtocol {
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
provRepoUpdateRecords.addAll(invocation.getArgumentAt(0, Collection.class));
provRepoUpdateRecords.addAll(invocation.getArgument(0));
return null;
}
}).when(provenanceRepo).registerEvents(anyCollection());

View File

@ -95,8 +95,8 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.notNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.notNull;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@ -255,14 +255,14 @@ public class TestStandardProcessSession {
Mockito.doAnswer(new Answer<FlowFile>() {
@Override
public FlowFile answer(InvocationOnMock invocation) throws Throwable {
return localFlowFileQueue.poll(invocation.getArgumentAt(0, Set.class));
return localFlowFileQueue.poll(invocation.getArgument(0));
}
}).when(connection).poll(any(Set.class));
Mockito.doAnswer(new Answer<List<FlowFileRecord>>() {
@Override
public List<FlowFileRecord> answer(InvocationOnMock invocation) throws Throwable {
return localFlowFileQueue.poll(invocation.getArgumentAt(0, FlowFileFilter.class), invocation.getArgumentAt(1, Set.class));
return localFlowFileQueue.poll(invocation.getArgument(0), invocation.getArgument(1));
}
}).when(connection).poll(any(FlowFileFilter.class), any(Set.class));
@ -1392,7 +1392,7 @@ public class TestStandardProcessSession {
@Override
public List<FlowFileRecord> answer(InvocationOnMock invocation) throws Throwable {
if (iterations++ == 0) {
final Set<FlowFileRecord> expired = invocation.getArgumentAt(1, Set.class);
final Set<FlowFileRecord> expired = invocation.getArgument(1);
expired.add(flowFileRecord);
}

View File

@ -38,7 +38,7 @@ import org.apache.nifi.util.NiFiProperties;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
public class TestVolatileContentRepository {
@ -85,10 +85,10 @@ public class TestVolatileContentRepository {
contentRepo.setBackupRepository(mockRepo);
final ResourceClaim resourceClaim = claimManager.newResourceClaim("container", "section", "1000", true, false);
final ContentClaim contentClaim = new StandardContentClaim(resourceClaim, 0L);
Mockito.when(mockRepo.create(Matchers.anyBoolean())).thenReturn(contentClaim);
Mockito.when(mockRepo.create(ArgumentMatchers.anyBoolean())).thenReturn(contentClaim);
final ByteArrayOutputStream overflowStream = new ByteArrayOutputStream();
Mockito.when(mockRepo.write(Matchers.any(ContentClaim.class))).thenReturn(overflowStream);
Mockito.when(mockRepo.write(ArgumentMatchers.any(ContentClaim.class))).thenReturn(overflowStream);
out.write(10);
assertEquals(1024 * 1024 * 10 + 1, overflowStream.size());

View File

@ -73,7 +73,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;

View File

@ -77,6 +77,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.AdditionalMatchers;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@ -104,10 +105,11 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anySet;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anySet;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;
@ -166,7 +168,7 @@ public class TestStandardProcessScheduler {
Mockito.doAnswer(new Answer<ProcessorNode>() {
@Override
public ProcessorNode answer(InvocationOnMock invocation) {
final String id = invocation.getArgumentAt(0, String.class);
final String id = invocation.getArgument(0);
return processorMap.get(id);
}
}).when(flowManager).getProcessorNode(Mockito.anyString());
@ -174,7 +176,7 @@ public class TestStandardProcessScheduler {
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
final ProcessorNode procNode = invocation.getArgumentAt(0, ProcessorNode.class);
final ProcessorNode procNode = invocation.getArgument(0);
processorMap.putIfAbsent(procNode.getIdentifier(), procNode);
return null;
}
@ -190,9 +192,9 @@ public class TestStandardProcessScheduler {
doAnswer(new Answer<ControllerServiceNode>() {
@Override
public ControllerServiceNode answer(final InvocationOnMock invocation) throws Throwable {
final String type = invocation.getArgumentAt(0, String.class);
final String id = invocation.getArgumentAt(1, String.class);
final BundleCoordinate bundleCoordinate = invocation.getArgumentAt(2, BundleCoordinate.class);
final String type = invocation.getArgument(0);
final String id = invocation.getArgument(1);
final BundleCoordinate bundleCoordinate = invocation.getArgument(2);
final ControllerServiceNode serviceNode = new ExtensionBuilder()
.identifier(id)
@ -211,7 +213,7 @@ public class TestStandardProcessScheduler {
serviceProvider.onControllerServiceAdded(serviceNode);
return serviceNode;
}
}).when(flowManager).createControllerService(anyString(), anyString(), any(BundleCoordinate.class), anySet(), anyBoolean(), anyBoolean());
}).when(flowManager).createControllerService(anyString(), anyString(), any(BundleCoordinate.class), AdditionalMatchers.or(anySet(), isNull()), anyBoolean(), anyBoolean());
}
@After

View File

@ -131,7 +131,7 @@ public class TestStandardControllerServiceProvider {
Mockito.doAnswer(new Answer<ProcessorNode>() {
@Override
public ProcessorNode answer(InvocationOnMock invocation) throws Throwable {
final String id = invocation.getArgumentAt(0, String.class);
final String id = invocation.getArgument(0);
return processorMap.get(id);
}
}).when(flowManager).getProcessorNode(Mockito.anyString());
@ -139,7 +139,7 @@ public class TestStandardControllerServiceProvider {
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
final ProcessorNode procNode = invocation.getArgumentAt(0, ProcessorNode.class);
final ProcessorNode procNode = invocation.getArgument(0);
processorMap.putIfAbsent(procNode.getIdentifier(), procNode);
return null;
}

View File

@ -16,10 +16,9 @@
*/
package org.apache.nifi.processor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@ -31,8 +30,6 @@ import org.apache.nifi.logging.LogLevel;
import org.apache.nifi.reporting.ReportingTask;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
import org.mockito.internal.matchers.VarargMatcher;
import org.slf4j.Logger;
public class TestSimpleProcessLogger {
@ -71,51 +68,36 @@ public class TestSimpleProcessLogger {
@Test
public void validateDelegateLoggerReceivesThrowableToStringOnError() {
componentLog.error("Hello {}", e);
verify(logger, times(1)).error(anyString(), argThat(new MyVarargMatcher()));
verify(logger, times(1)).error(anyString(), eq(task), eq(e.toString()), eq(e));
}
@Test
public void validateDelegateLoggerReceivesThrowableToStringOnInfo() {
componentLog.info("Hello {}", e);
verify(logger, times(1)).info(anyString(), argThat(new MyVarargMatcher()));
verify(logger, times(1)).info(anyString(), eq(e));
}
@Test
public void validateDelegateLoggerReceivesThrowableToStringOnTrace() {
componentLog.trace("Hello {}", e);
verify(logger, times(1)).trace(anyString(), argThat(new MyVarargMatcher()));
verify(logger, times(1)).trace(anyString(), eq(task), eq(e.toString()), eq(e));
}
@Test
public void validateDelegateLoggerReceivesThrowableToStringOnWarn() {
componentLog.warn("Hello {}", e);
verify(logger, times(1)).warn(anyString(), argThat(new MyVarargMatcher()));
verify(logger, times(1)).warn(anyString(), eq(task), eq(e.toString()), eq(e));
}
@Test
public void validateDelegateLoggerReceivesThrowableToStringOnLogWithLevel() {
componentLog.log(LogLevel.WARN, "Hello {}", e);
verify(logger, times(1)).warn(anyString(), argThat(new MyVarargMatcher()));
verify(logger, times(1)).warn(anyString(), eq(task), eq(e.toString()), eq(e));
componentLog.log(LogLevel.ERROR, "Hello {}", e);
verify(logger, times(1)).error(anyString(), argThat(new MyVarargMatcher()));
verify(logger, times(1)).error(anyString(), eq(task), eq(e.toString()), eq(e));
componentLog.log(LogLevel.INFO, "Hello {}", e);
verify(logger, times(1)).info(anyString(), argThat(new MyVarargMatcher()));
verify(logger, times(1)).info(anyString(), eq(e));
componentLog.log(LogLevel.TRACE, "Hello {}", e);
verify(logger, times(1)).trace(anyString(), argThat(new MyVarargMatcher()));
}
/**
*
*/
private class MyVarargMatcher extends ArgumentMatcher<Object[]>implements VarargMatcher {
private static final long serialVersionUID = 1L;
@Override
public boolean matches(Object argument) {
Object[] args = (Object[]) argument;
assertEquals(task, args[0]);
assertEquals(e.toString(), args[1]);
return true;
}
verify(logger, times(1)).trace(anyString(), eq(task), eq(e.toString()), eq(e));
}
}

View File

@ -28,7 +28,7 @@ import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@ -62,7 +62,7 @@ public class TestSocketRemoteSiteListener {
final ServerProtocol serverProtocol = mock(ServerProtocol.class);
doAnswer(invocation -> {
final NodeInformation self = invocation.getArgumentAt(2, NodeInformation.class);
final NodeInformation self = invocation.getArgument(2);
// Listener should inform about itself properly:
assertEquals(remoteInputHost, self.getSiteToSiteHostname());
assertEquals(remoteSocketPort, self.getSiteToSitePort().intValue());

View File

@ -31,8 +31,8 @@ import org.junit.Test;
import java.util.LinkedHashSet;
import java.util.Set;
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.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@ -45,7 +45,7 @@ public class TestStandardPublicPort {
final Authorizer authorizer = mock(Authorizer.class);
doAnswer(invocation -> {
final AuthorizationRequest request = invocation.getArgumentAt(0, AuthorizationRequest.class);
final AuthorizationRequest request = invocation.getArgument(0);
if ("node1@nifi.test".equals(request.getIdentity())) {
return AuthorizationResult.approved();
} else if ("NODE1@NIFI.TEST".equals(request.getIdentity())) {

View File

@ -59,8 +59,8 @@ import java.util.stream.IntStream;
import org.apache.nifi.util.NiFiProperties;
import static org.junit.Assert.assertEquals;
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.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@ -360,7 +360,8 @@ public class TestStandardRemoteGroupPort {
final MockFlowFile flowFile = spy(processSession.createFlowFile(bytes));
when(flowFile.getSize()).then(invocation -> {
Thread.sleep(1); // For testSendBatchByDuration
return bytes.length;
// Array.length returns int, but flowFile.getSize() must return a long
return Integer.valueOf(bytes.length).longValue();
});
sessionState.getFlowFileQueue().offer(flowFile);
flowFiles.add(flowFile);

View File

@ -71,8 +71,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
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.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -18,7 +18,7 @@
package org.apache.nifi.web.server;
import static org.apache.nifi.security.util.KeyStoreUtils.SUN_PROVIDER_NAME;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

View File

@ -48,8 +48,8 @@ import static org.apache.nifi.web.api.dto.DtoFactory.SENSITIVE_VALUE_MASK;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
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.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -101,7 +101,7 @@ public class TestRemoteProcessGroupAuditor {
final AuditService auditService = mock(AuditService.class);
final AtomicReference<Collection<Action>> addedActions = new AtomicReference<>();
doAnswer(invocation -> {
Collection<Action> actions = invocation.getArgumentAt(0, Collection.class);
Collection<Action> actions = invocation.getArgument(0);
addedActions.set(actions);
return null;
}).when(auditService).addActions(any());
@ -450,7 +450,7 @@ public class TestRemoteProcessGroupAuditor {
final AuditService auditService = mock(AuditService.class);
final AtomicReference<Collection<Action>> addedActions = new AtomicReference<>();
doAnswer(invocation -> {
Collection<Action> actions = invocation.getArgumentAt(0, Collection.class);
Collection<Action> actions = invocation.getArgument(0);
addedActions.set(actions);
return null;
}).when(auditService).addActions(any());

View File

@ -30,7 +30,7 @@ import org.apache.nifi.web.dao.ProcessorDAO;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -44,7 +44,6 @@ import org.apache.nifi.web.controller.ControllerFacade;
import org.apache.nifi.web.security.token.NiFiAuthenticationToken;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
@ -56,8 +55,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@ -85,7 +84,7 @@ public class StandardNiFiServiceFacadeTest {
// audit service
final AuditService auditService = mock(AuditService.class);
when(auditService.getAction(anyInt())).then(invocation -> {
final Integer actionId = invocation.getArgumentAt(0, Integer.class);
final Integer actionId = invocation.getArgument(0);
FlowChangeAction action = null;
if (ACTION_ID_1.equals(actionId)) {
@ -106,7 +105,7 @@ public class StandardNiFiServiceFacadeTest {
// authorizable lookup
final AuthorizableLookup authorizableLookup = mock(AuthorizableLookup.class);
when(authorizableLookup.getProcessor(Mockito.anyString())).then(getProcessorInvocation -> {
final String processorId = getProcessorInvocation.getArgumentAt(0, String.class);
final String processorId = getProcessorInvocation.getArgument(0);
// processor-2 is no longer part of the flow
if (processorId.equals(PROCESSOR_ID_2)) {
@ -139,7 +138,7 @@ public class StandardNiFiServiceFacadeTest {
// authorizer
authorizer = mock(Authorizer.class);
when(authorizer.authorize(any(AuthorizationRequest.class))).then(invocation -> {
final AuthorizationRequest request = invocation.getArgumentAt(0, AuthorizationRequest.class);
final AuthorizationRequest request = invocation.getArgument(0);
AuthorizationResult result = AuthorizationResult.denied();
if (request.getResource().getIdentifier().endsWith(PROCESSOR_ID_1)) {
@ -201,18 +200,8 @@ public class StandardNiFiServiceFacadeTest {
assertTrue(entity.getCanRead());
// resource exists and is approved, no need to check the controller
verify(authorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return ((AuthorizationRequest) o).getResource().getIdentifier().endsWith(PROCESSOR_ID_1);
}
}));
verify(authorizer, times(0)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return ((AuthorizationRequest) o).getResource().equals(ResourceFactory.getControllerResource());
}
}));
verify(authorizer, times(1)).authorize(argThat(o -> o.getResource().getIdentifier().endsWith(PROCESSOR_ID_1)));
verify(authorizer, times(0)).authorize(argThat(o -> o.getResource().equals(ResourceFactory.getControllerResource())));
}
@Test(expected = AccessDeniedException.class)
@ -227,18 +216,8 @@ public class StandardNiFiServiceFacadeTest {
fail();
} finally {
// resource exists, but should trigger access denied and will not check the controller
verify(authorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return ((AuthorizationRequest) o).getResource().getIdentifier().endsWith(PROCESSOR_ID_1);
}
}));
verify(authorizer, times(0)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return ((AuthorizationRequest) o).getResource().equals(ResourceFactory.getControllerResource());
}
}));
verify(authorizer, times(1)).authorize(argThat(o -> o.getResource().getIdentifier().endsWith(PROCESSOR_ID_1)));
verify(authorizer, times(0)).authorize(argThat(o -> o.getResource().equals(ResourceFactory.getControllerResource())));
}
}
@ -256,18 +235,8 @@ public class StandardNiFiServiceFacadeTest {
assertTrue(entity.getCanRead());
// component does not exists, so only checks against the controller
verify(authorizer, times(0)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return ((AuthorizationRequest) o).getResource().getIdentifier().endsWith(PROCESSOR_ID_2);
}
}));
verify(authorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() {
@Override
public boolean matches(Object o) {
return ((AuthorizationRequest) o).getResource().equals(ResourceFactory.getControllerResource());
}
}));
verify(authorizer, times(0)).authorize(argThat(o -> o.getResource().getIdentifier().endsWith(PROCESSOR_ID_2)));
verify(authorizer, times(1)).authorize(argThat(o -> o.getResource().equals(ResourceFactory.getControllerResource())));
}
@Test

View File

@ -51,8 +51,8 @@ import static org.apache.nifi.web.api.ApplicationResource.PROXY_PORT_HTTP_HEADER
import static org.apache.nifi.web.api.ApplicationResource.PROXY_SCHEME_HTTP_HEADER;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
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.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;

View File

@ -41,7 +41,7 @@ import java.util.stream.IntStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -28,7 +28,7 @@ import java.net.URI;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -30,14 +30,16 @@ import org.apache.nifi.registry.variable.MutableVariableRegistry;
import org.apache.nifi.web.api.dto.search.SearchResultsDTO;
import org.junit.Before;
import org.junit.Test;
import org.mockito.AdditionalMatchers;
import org.mockito.Mockito;
import java.util.HashSet;
import java.util.Optional;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
public class ControllerSearchServiceTest {
@ -350,7 +352,8 @@ public class ControllerSearchServiceTest {
final Processor processor1 = mock(Processor.class);
final ProcessorNode processorNode1 = mock(StandardProcessorNode.class);
Mockito.doReturn(authorizedToRead).when(processorNode1).isAuthorized(any(Authorizer.class), eq(RequestAction.READ), any(NiFiUser.class));
Mockito.doReturn(authorizedToRead).when(processorNode1).isAuthorized(AdditionalMatchers.or(any(Authorizer.class), isNull()), eq(RequestAction.READ),
AdditionalMatchers.or(any(NiFiUser.class), isNull()));
Mockito.doReturn(variableRegistry).when(processorNode1).getVariableRegistry();
Mockito.doReturn(processor1).when(processorNode1).getProcessor();
// set processor node's attributes
@ -389,7 +392,8 @@ public class ControllerSearchServiceTest {
Mockito.doReturn(variableRegistry).when(processGroup).getVariableRegistry();
Mockito.doReturn(parent == null).when(processGroup).isRootGroup();
// override process group's access rights
Mockito.doReturn(authorizedToRead).when(processGroup).isAuthorized(any(Authorizer.class), eq(RequestAction.READ), any(NiFiUser.class));
Mockito.doReturn(authorizedToRead).when(processGroup).isAuthorized(AdditionalMatchers.or(any(Authorizer.class), isNull()), eq(RequestAction.READ),
AdditionalMatchers.or(any(NiFiUser.class), isNull()));
return processGroup;
}

View File

@ -32,8 +32,8 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
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.when;

View File

@ -50,8 +50,8 @@ import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -29,7 +29,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -1,80 +1,82 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.web.security.oidc;
import com.nimbusds.oauth2.sdk.Scope;
import org.apache.nifi.util.NiFiProperties;
import org.junit.Test;
import org.mockito.internal.util.reflection.Whitebox;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class StandardOidcIdentityProviderTest {
@Test
public void testValidateScopes() {
final String additionalScope_profile = "profile";
final String additionalScope_abc = "abc";
final StandardOidcIdentityProvider provider = createOidcProviderWithAdditionalScopes(additionalScope_profile,
additionalScope_abc);
Scope scope = provider.getScope();
// two additional scopes are set, two (openid, email) are hard-coded
assertEquals(scope.toArray().length, 4);
assertTrue(scope.contains("openid"));
assertTrue(scope.contains("email"));
assertTrue(scope.contains(additionalScope_profile));
assertTrue(scope.contains(additionalScope_abc));
}
@Test
public void testNoDuplicatedScopes() {
final String additionalScopeDuplicate = "abc";
final StandardOidcIdentityProvider provider = createOidcProviderWithAdditionalScopes(additionalScopeDuplicate,
"def", additionalScopeDuplicate);
Scope scope = provider.getScope();
// three additional scopes are set but one is duplicated and mustn't be returned; note that there is
// another one inserted in between the duplicated; two (openid, email) are hard-coded
assertEquals(scope.toArray().length, 4);
}
private StandardOidcIdentityProvider createOidcProviderWithAdditionalScopes(String... additionalScopes) {
final StandardOidcIdentityProvider provider = mock(StandardOidcIdentityProvider.class);
NiFiProperties properties = createNiFiPropertiesMockWithAdditionalScopes(Arrays.asList(additionalScopes));
Whitebox.setInternalState(provider, "properties", properties);
when(provider.isOidcEnabled()).thenReturn(true);
when(provider.getScope()).thenCallRealMethod();
return provider;
}
private NiFiProperties createNiFiPropertiesMockWithAdditionalScopes(List<String> additionalScopes) {
NiFiProperties properties = mock(NiFiProperties.class);
when(properties.getOidcAdditionalScopes()).thenReturn(additionalScopes);
return properties;
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.web.security.oidc;
import com.nimbusds.oauth2.sdk.Scope;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.nifi.util.NiFiProperties;
import org.junit.Test;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class StandardOidcIdentityProviderTest {
@Test
public void testValidateScopes() throws IllegalAccessException {
final String additionalScope_profile = "profile";
final String additionalScope_abc = "abc";
final StandardOidcIdentityProvider provider = createOidcProviderWithAdditionalScopes(additionalScope_profile,
additionalScope_abc);
Scope scope = provider.getScope();
// two additional scopes are set, two (openid, email) are hard-coded
assertEquals(scope.toArray().length, 4);
assertTrue(scope.contains("openid"));
assertTrue(scope.contains("email"));
assertTrue(scope.contains(additionalScope_profile));
assertTrue(scope.contains(additionalScope_abc));
}
@Test
public void testNoDuplicatedScopes() throws IllegalAccessException {
final String additionalScopeDuplicate = "abc";
final StandardOidcIdentityProvider provider = createOidcProviderWithAdditionalScopes(additionalScopeDuplicate,
"def", additionalScopeDuplicate);
Scope scope = provider.getScope();
// three additional scopes are set but one is duplicated and mustn't be returned; note that there is
// another one inserted in between the duplicated; two (openid, email) are hard-coded
assertEquals(scope.toArray().length, 4);
}
private StandardOidcIdentityProvider createOidcProviderWithAdditionalScopes(String... additionalScopes) throws IllegalAccessException {
final StandardOidcIdentityProvider provider = mock(StandardOidcIdentityProvider.class);
NiFiProperties properties = createNiFiPropertiesMockWithAdditionalScopes(Arrays.asList(additionalScopes));
Field propertiesField = FieldUtils.getDeclaredField(StandardOidcIdentityProvider.class, "properties", true);
propertiesField.set(provider, properties);
when(provider.isOidcEnabled()).thenReturn(true);
when(provider.getScope()).thenCallRealMethod();
return provider;
}
private NiFiProperties createNiFiPropertiesMockWithAdditionalScopes(List<String> additionalScopes) {
NiFiProperties properties = mock(NiFiProperties.class);
when(properties.getOidcAdditionalScopes()).thenReturn(additionalScopes);
return properties;
}
}

View File

@ -26,7 +26,7 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;

Some files were not shown because too many files have changed in this diff Show More