NIFI-11325 Upgraded Mockito from 3.12.4 to 4.11.0

- Replaced deprecated Matchers references with ArgumentMatchers
- Removed unnecessary Mockito versions for Registry
- Refactored test configuration to Java for mocking

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #7071.
This commit is contained in:
exceptionfactory 2023-03-22 11:16:17 -05:00 committed by Pierre Villard
parent af3737e670
commit 8154fcce49
No known key found for this signature in database
GPG Key ID: F92A93B30C07C6D5
7 changed files with 31 additions and 57 deletions

View File

@ -59,7 +59,7 @@ import java.util.stream.IntStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

View File

@ -18,6 +18,7 @@ package org.apache.nifi.web.controller;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.nifi.authorization.Authorizer;
import org.apache.nifi.authorization.user.NiFiUser;
import org.apache.nifi.connectable.Connection;
import org.apache.nifi.connectable.Funnel;
@ -34,6 +35,7 @@ import org.apache.nifi.parameter.Parameter;
import org.apache.nifi.parameter.ParameterContext;
import org.apache.nifi.parameter.ParameterContextManager;
import org.apache.nifi.parameter.ParameterDescriptor;
import org.apache.nifi.registry.VariableRegistry;
import org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO;
import org.apache.nifi.web.api.dto.search.SearchResultGroupDTO;
import org.apache.nifi.web.api.dto.search.SearchResultsDTO;
@ -44,6 +46,9 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ -60,7 +65,7 @@ import java.util.function.Function;
import static org.apache.nifi.web.controller.ComponentMockUtil.getRootProcessGroup;
@ExtendWith(SpringExtension.class)
@ContextConfiguration(locations = {"classpath:nifi-web-api-test-context.xml", "classpath:nifi-web-api-context.xml"})
@ContextConfiguration(classes = {AbstractControllerSearchIntegrationTest.WebConfiguration.class})
public abstract class AbstractControllerSearchIntegrationTest {
protected static final String ROOT_PROCESSOR_GROUP_ID = "3b9a7e60-0172-1000-5f1e-10cbc0c4d5f1";
protected static final String ROOT_PROCESSOR_GROUP_NAME = "NiFi Flow";
@ -362,4 +367,24 @@ public abstract class AbstractControllerSearchIntegrationTest {
return stringJoiner.toString();
}
}
@ImportResource({"classpath:nifi-web-api-context.xml"})
@Configuration
public static class WebConfiguration {
@Bean
public FlowController flowController() {
return Mockito.mock(FlowController.class);
}
@Bean
public Authorizer authorizer() {
return Mockito.mock(Authorizer.class);
}
@Bean
public VariableRegistry variableRegistry() {
return Mockito.mock(VariableRegistry.class);
}
}
}

View File

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<beans default-lazy-init="true"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="flowController" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.apache.nifi.controller.FlowController" />
</bean>
<bean id="authorizer" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.apache.nifi.authorization.Authorizer" />
</bean>
<bean id="variableRegistry" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.apache.nifi.registry.VariableRegistry" />
</bean>
</beans>

View File

@ -65,8 +65,8 @@ import static org.apache.nifi.processors.hadoop.ListHDFS.FILTER_FULL_PATH_VALUE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
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.atLeast;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;

View File

@ -44,7 +44,7 @@ import java.util.LinkedList;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
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

@ -177,25 +177,6 @@
<scope>runtime</scope>
<type>zip</type>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.28.2</version>
<scope>test</scope>
</dependency>
<!-- force mockito-core to a newer version -->
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.12.14</version>
</dependency>
<!-- force mockito-core to a newer version -->
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>1.12.14</version>
</dependency>
<!-- exclude all transitive groovy deps so that spock uses whatever is directly declared -->
<dependency>
<groupId>org.spockframework</groupId>

View File

@ -139,7 +139,7 @@
<jersey.bom.version>2.36</jersey.bom.version>
<log4j2.version>2.20.0</log4j2.version>
<logback.version>1.3.5</logback.version>
<mockito.version>3.12.4</mockito.version>
<mockito.version>4.11.0</mockito.version>
<netty.3.version>3.10.6.Final</netty.3.version>
<snakeyaml.version>1.33</snakeyaml.version>
<netty.4.version>4.1.90.Final</netty.4.version>