Upgrade to Mockito 3.4.6
Closes gh-22838
This commit is contained in:
@@ -22,16 +22,17 @@ import java.util.Set;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.boot.cli.command.core.HelpCommand;
|
||||
import org.springframework.boot.cli.command.core.HintCommand;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
@@ -40,6 +41,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CommandRunnerTests {
|
||||
|
||||
private CommandRunner commandRunner;
|
||||
@@ -63,7 +65,6 @@ class CommandRunnerTests {
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.loader = Thread.currentThread().getContextClassLoader();
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.commandRunner = new CommandRunner("spring") {
|
||||
|
||||
@Override
|
||||
@@ -84,9 +85,9 @@ class CommandRunnerTests {
|
||||
super.printStackTrace(ex);
|
||||
}
|
||||
};
|
||||
given(this.anotherCommand.getName()).willReturn("another");
|
||||
given(this.regularCommand.getName()).willReturn("command");
|
||||
given(this.regularCommand.getDescription()).willReturn("A regular command");
|
||||
lenient().doReturn("another").when(this.anotherCommand).getName();
|
||||
lenient().doReturn("command").when(this.regularCommand).getName();
|
||||
lenient().doReturn("A regular command").when(this.regularCommand).getDescription();
|
||||
this.commandRunner.addCommand(this.regularCommand);
|
||||
this.commandRunner.addCommand(new HelpCommand(this.commandRunner));
|
||||
this.commandRunner.addCommand(new HintCommand(this.commandRunner));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,9 +19,10 @@ package org.springframework.boot.cli.command.encodepassword;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.boot.cli.command.status.ExitStatus;
|
||||
import org.springframework.boot.cli.util.MockLog;
|
||||
@@ -37,6 +38,7 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class EncodePasswordCommandTests {
|
||||
|
||||
private MockLog log;
|
||||
@@ -46,7 +48,6 @@ class EncodePasswordCommandTests {
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.log = MockLog.attach();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,12 +27,12 @@ import java.util.zip.ZipOutputStream;
|
||||
import joptsimple.OptionSet;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.boot.cli.command.status.ExitStatus;
|
||||
|
||||
@@ -45,6 +45,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Stephane Nicoll
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
|
||||
private final TestableInitCommandOptionHandler handler;
|
||||
@@ -54,11 +55,6 @@ class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
@Captor
|
||||
private ArgumentCaptor<HttpUriRequest> requestCaptor;
|
||||
|
||||
@BeforeEach
|
||||
void setupMocks() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
InitCommandTests() {
|
||||
InitializrService initializrService = new InitializrService(this.http);
|
||||
this.handler = new TestableInitCommandOptionHandler(initializrService);
|
||||
|
||||
@@ -27,8 +27,9 @@ import org.codehaus.groovy.ast.expr.ConstantExpression;
|
||||
import org.codehaus.groovy.control.SourceUnit;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesResolver;
|
||||
import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext;
|
||||
@@ -41,6 +42,7 @@ import static org.mockito.BDDMockito.given;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DependencyCustomizerTests {
|
||||
|
||||
private final ModuleNode moduleNode = new ModuleNode((SourceUnit) null);
|
||||
@@ -54,10 +56,6 @@ class DependencyCustomizerTests {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
given(this.resolver.getGroupId("spring-boot-starter-logging")).willReturn("org.springframework.boot");
|
||||
given(this.resolver.getArtifactId("spring-boot-starter-logging")).willReturn("spring-boot-starter-logging");
|
||||
given(this.resolver.getVersion("spring-boot-starter-logging")).willReturn("1.2.3");
|
||||
this.moduleNode.addClass(this.classNode);
|
||||
this.dependencyCustomizer = new DependencyCustomizer(new GroovyClassLoader(getClass().getClassLoader()),
|
||||
this.moduleNode, new DependencyResolutionContext() {
|
||||
@@ -72,6 +70,9 @@ class DependencyCustomizerTests {
|
||||
|
||||
@Test
|
||||
void basicAdd() {
|
||||
given(this.resolver.getGroupId("spring-boot-starter-logging")).willReturn("org.springframework.boot");
|
||||
given(this.resolver.getArtifactId("spring-boot-starter-logging")).willReturn("spring-boot-starter-logging");
|
||||
given(this.resolver.getVersion("spring-boot-starter-logging")).willReturn("1.2.3");
|
||||
this.dependencyCustomizer.add("spring-boot-starter-logging");
|
||||
List<AnnotationNode> grabAnnotations = this.classNode.getAnnotations(new ClassNode(Grab.class));
|
||||
assertThat(grabAnnotations).hasSize(1);
|
||||
@@ -82,6 +83,9 @@ class DependencyCustomizerTests {
|
||||
|
||||
@Test
|
||||
void nonTransitiveAdd() {
|
||||
given(this.resolver.getGroupId("spring-boot-starter-logging")).willReturn("org.springframework.boot");
|
||||
given(this.resolver.getArtifactId("spring-boot-starter-logging")).willReturn("spring-boot-starter-logging");
|
||||
given(this.resolver.getVersion("spring-boot-starter-logging")).willReturn("1.2.3");
|
||||
this.dependencyCustomizer.add("spring-boot-starter-logging", false);
|
||||
List<AnnotationNode> grabAnnotations = this.classNode.getAnnotations(new ClassNode(Grab.class));
|
||||
assertThat(grabAnnotations).hasSize(1);
|
||||
@@ -92,6 +96,9 @@ class DependencyCustomizerTests {
|
||||
|
||||
@Test
|
||||
void fullyCustomized() {
|
||||
given(this.resolver.getGroupId("spring-boot-starter-logging")).willReturn("org.springframework.boot");
|
||||
given(this.resolver.getArtifactId("spring-boot-starter-logging")).willReturn("spring-boot-starter-logging");
|
||||
given(this.resolver.getVersion("spring-boot-starter-logging")).willReturn("1.2.3");
|
||||
this.dependencyCustomizer.add("spring-boot-starter-logging", "my-classifier", "my-type", false);
|
||||
List<AnnotationNode> grabAnnotations = this.classNode.getAnnotations(new ClassNode(Grab.class));
|
||||
assertThat(grabAnnotations).hasSize(1);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,10 +18,10 @@ package org.springframework.boot.cli.compiler.dependencies;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -31,6 +31,7 @@ import static org.mockito.BDDMockito.given;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CompositeDependencyManagementTests {
|
||||
|
||||
@Mock
|
||||
@@ -39,11 +40,6 @@ class CompositeDependencyManagementTests {
|
||||
@Mock
|
||||
private DependencyManagement dependencyManagement2;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownSpringBootVersion() {
|
||||
given(this.dependencyManagement1.getSpringBootVersion()).willReturn(null);
|
||||
@@ -55,7 +51,6 @@ class CompositeDependencyManagementTests {
|
||||
@Test
|
||||
void knownSpringBootVersion() {
|
||||
given(this.dependencyManagement1.getSpringBootVersion()).willReturn("1.2.3");
|
||||
given(this.dependencyManagement2.getSpringBootVersion()).willReturn("1.2.4");
|
||||
assertThat(new CompositeDependencyManagement(this.dependencyManagement1, this.dependencyManagement2)
|
||||
.getSpringBootVersion()).isEqualTo("1.2.3");
|
||||
}
|
||||
@@ -71,7 +66,6 @@ class CompositeDependencyManagementTests {
|
||||
@Test
|
||||
void knownDependency() {
|
||||
given(this.dependencyManagement1.find("artifact")).willReturn(new Dependency("test", "artifact", "1.2.3"));
|
||||
given(this.dependencyManagement2.find("artifact")).willReturn(new Dependency("test", "artifact", "1.2.4"));
|
||||
assertThat(new CompositeDependencyManagement(this.dependencyManagement1, this.dependencyManagement2)
|
||||
.find("artifact")).isEqualTo(new Dependency("test", "artifact", "1.2.3"));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,11 +24,11 @@ import org.eclipse.aether.RepositorySystem;
|
||||
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
|
||||
import org.eclipse.aether.repository.LocalRepository;
|
||||
import org.eclipse.aether.repository.LocalRepositoryManager;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -44,6 +44,7 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class GrapeRootRepositorySystemSessionAutoConfigurationTests {
|
||||
|
||||
private DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
|
||||
@@ -51,19 +52,8 @@ class GrapeRootRepositorySystemSessionAutoConfigurationTests {
|
||||
@Mock
|
||||
private RepositorySystem repositorySystem;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noLocalRepositoryWhenNoGrapeRoot() {
|
||||
given(this.repositorySystem.newLocalRepositoryManager(eq(this.session), any(LocalRepository.class)))
|
||||
.willAnswer((invocation) -> {
|
||||
LocalRepository localRepository = invocation.getArgument(1);
|
||||
return new SimpleLocalRepositoryManagerFactory().newInstance(
|
||||
GrapeRootRepositorySystemSessionAutoConfigurationTests.this.session, localRepository);
|
||||
});
|
||||
new GrapeRootRepositorySystemSessionAutoConfiguration().apply(this.session, this.repositorySystem);
|
||||
verify(this.repositorySystem, never()).newLocalRepositoryManager(eq(this.session), any(LocalRepository.class));
|
||||
assertThat(this.session.getLocalRepository()).isNull();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,10 +27,10 @@ import org.eclipse.aether.repository.AuthenticationContext;
|
||||
import org.eclipse.aether.repository.LocalRepository;
|
||||
import org.eclipse.aether.repository.Proxy;
|
||||
import org.eclipse.aether.repository.RemoteRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
|
||||
@@ -44,16 +44,12 @@ import static org.mockito.BDDMockito.given;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
|
||||
|
||||
@Mock
|
||||
private RepositorySystem repositorySystem;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void basicSessionCustomization() {
|
||||
assertSessionCustomization("src/test/resources/maven-settings/basic");
|
||||
|
||||
Reference in New Issue
Block a user