diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java index 8ed822408d60..18bbc7f35e46 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java @@ -22,9 +22,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.MockitoAnnotations; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; @@ -34,7 +33,6 @@ * * @author Mattias Severson */ -@RunWith(MockitoJUnitRunner.class) public class DiskSpaceHealthIndicatorTests { static final long THRESHOLD_BYTES = 1024; @@ -49,6 +47,7 @@ public class DiskSpaceHealthIndicatorTests { @Before public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); given(this.fileMock.exists()).willReturn(true); given(this.fileMock.canRead()).willReturn(true); this.healthIndicator = new DiskSpaceHealthIndicator( diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java index 22faa933da59..dd390199876e 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java @@ -34,10 +34,9 @@ import org.elasticsearch.cluster.routing.RoutingTable; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.MockitoAnnotations; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; @@ -48,7 +47,6 @@ * * @author Andy Wilkinson */ -@RunWith(MockitoJUnitRunner.class) public class ElasticsearchHealthIndicatorTests { @Mock @@ -66,9 +64,9 @@ public class ElasticsearchHealthIndicatorTests { @Before public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); given(this.client.admin()).willReturn(this.admin); given(this.admin.cluster()).willReturn(this.cluster); - this.indicator = new ElasticsearchHealthIndicator(this.client, this.properties); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java index 06890e2af82b..0aa4ada20216 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java @@ -16,11 +16,11 @@ package org.springframework.boot.actuate.metrics.writer; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.MockitoAnnotations; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -31,7 +31,6 @@ * * @author Dave Syer */ -@RunWith(MockitoJUnitRunner.class) public class DefaultCounterServiceTests { private final MetricWriter repository = mock(MetricWriter.class); @@ -42,6 +41,11 @@ public class DefaultCounterServiceTests { @Captor private ArgumentCaptor> captor; + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Test public void incrementWithExistingCounter() { this.service.increment("counter.foo"); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java index 27b8e1863ae4..2642cc0cd11e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java @@ -20,9 +20,8 @@ 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.MockitoAnnotations; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -48,7 +47,6 @@ * */ @SuppressWarnings("deprecation") -@RunWith(MockitoJUnitRunner.class) public class EnableAutoConfigurationImportSelectorTests { private final EnableAutoConfigurationImportSelector importSelector = new EnableAutoConfigurationImportSelector(); @@ -64,7 +62,8 @@ public class EnableAutoConfigurationImportSelectorTests { private AnnotationAttributes annotationAttributes; @Before - public void configureImportSelector() { + public void setup() { + MockitoAnnotations.initMocks(this); this.importSelector.setBeanFactory(this.beanFactory); this.importSelector.setEnvironment(this.environment); this.importSelector.setResourceLoader(new DefaultResourceLoader()); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java index e4fdb3d3a906..71fae492ffdc 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java @@ -22,9 +22,8 @@ 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.MockitoAnnotations; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -44,7 +43,6 @@ * @author Phillip Webb * @author Andy Wilkinson */ -@RunWith(MockitoJUnitRunner.class) public class ImportAutoConfigurationImportSelectorTests { private final ImportAutoConfigurationImportSelector importSelector = new ImportAutoConfigurationImportSelector(); @@ -55,7 +53,8 @@ public class ImportAutoConfigurationImportSelectorTests { private Environment environment; @Before - public void configureImportSelector() { + public void setup() { + MockitoAnnotations.initMocks(this); this.importSelector.setBeanFactory(this.beanFactory); this.importSelector.setEnvironment(this.environment); this.importSelector.setResourceLoader(new DefaultResourceLoader()); diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/CompositeDependencyManagementTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/CompositeDependencyManagementTests.java index 94cd46069772..c06c53e1e5f7 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/CompositeDependencyManagementTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/CompositeDependencyManagementTests.java @@ -18,10 +18,10 @@ import java.util.Arrays; +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.MockitoAnnotations; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; @@ -31,7 +31,6 @@ * * @author Andy Wilkinson */ -@RunWith(MockitoJUnitRunner.class) public class CompositeDependencyManagementTests { @Mock @@ -40,6 +39,11 @@ public class CompositeDependencyManagementTests { @Mock private DependencyManagement dependencyManagement2; + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Test public void unknownSpringBootVersion() { given(this.dependencyManagement1.getSpringBootVersion()).willReturn(null); diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/GrapeRootRepositorySystemSessionAutoConfigurationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/GrapeRootRepositorySystemSessionAutoConfigurationTests.java index 34bcac13ff8e..6d0680cc3434 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/GrapeRootRepositorySystemSessionAutoConfigurationTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/GrapeRootRepositorySystemSessionAutoConfigurationTests.java @@ -24,11 +24,11 @@ import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepositoryManager; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import static org.assertj.core.api.Assertions.assertThat; @@ -43,7 +43,6 @@ * * @author Andy Wilkinson */ -@RunWith(MockitoJUnitRunner.class) public class GrapeRootRepositorySystemSessionAutoConfigurationTests { private DefaultRepositorySystemSession session = MavenRepositorySystemUtils @@ -52,6 +51,11 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests { @Mock private RepositorySystem repositorySystem; + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Test public void noLocalRepositoryWhenNoGrapeRoot() { given(this.repositorySystem.newLocalRepositoryManager(eq(this.session), diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java index 536b0caa1f3a..9d768e5154dd 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java @@ -29,13 +29,13 @@ import org.eclipse.aether.repository.LocalRepositoryManager; import org.eclipse.aether.repository.Proxy; import org.eclipse.aether.repository.RemoteRepository; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import org.springframework.boot.cli.testutil.SystemProperties; @@ -50,7 +50,6 @@ * * @author Andy Wilkinson */ -@RunWith(MockitoJUnitRunner.class) public class SettingsXmlRepositorySystemSessionAutoConfigurationTests { @Rule @@ -59,6 +58,11 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests { @Mock private RepositorySystem repositorySystem; + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Test public void basicSessionCustomization() throws SettingsBuildingException { assertSessionCustomization("src/test/resources/maven-settings/basic"); diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/HttpHeaderInterceptorTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/HttpHeaderInterceptorTests.java index 982b55bc5f8e..30a8763db02e 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/HttpHeaderInterceptorTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/HttpHeaderInterceptorTests.java @@ -22,9 +22,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.MockitoAnnotations; import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; @@ -41,7 +40,6 @@ * @author Rob Winch * @since 1.3.0 */ -@RunWith(MockitoJUnitRunner.class) public class HttpHeaderInterceptorTests { @Rule @@ -66,7 +64,8 @@ public class HttpHeaderInterceptorTests { private MockHttpServletRequest httpRequest; @Before - public void setup() throws IOException { + public void setup() throws Exception { + MockitoAnnotations.initMocks(this); this.body = new byte[] {}; this.httpRequest = new MockHttpServletRequest(); this.request = new ServletServerHttpRequest(this.httpRequest); diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoContextCustomizerFactoryTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoContextCustomizerFactoryTests.java index c9a16126230c..ff3932e09fd5 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoContextCustomizerFactoryTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoContextCustomizerFactoryTests.java @@ -16,9 +16,9 @@ package org.springframework.boot.test.mock.mockito; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.MockitoAnnotations; import org.springframework.test.context.ContextCustomizer; @@ -29,11 +29,15 @@ * * @author Phillip Webb */ -@RunWith(MockitoJUnitRunner.class) public class MockitoContextCustomizerFactoryTests { private final MockitoContextCustomizerFactory factory = new MockitoContextCustomizerFactory(); + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Test public void getContextCustomizerWithoutAnnotationReturnsCustomizer() throws Exception { @@ -57,8 +61,8 @@ public void getContextCustomizerUsesMocksAsCacheKey() throws Exception { ContextCustomizer same = this.factory .createContextCustomizer(WithSameMockBeanAnnotation.class, null); assertThat(customizer).isNotNull(); - ContextCustomizer different = this.factory.createContextCustomizer( - WithDifferentMockBeanAnnotation.class, null); + ContextCustomizer different = this.factory + .createContextCustomizer(WithDifferentMockBeanAnnotation.class, null); assertThat(different).isNotNull(); assertThat(customizer.hashCode()).isEqualTo(same.hashCode()); assertThat(customizer.hashCode()).isNotEqualTo(different.hashCode()); diff --git a/spring-boot/src/test/java/org/springframework/boot/BannerTests.java b/spring-boot/src/test/java/org/springframework/boot/BannerTests.java index defaf6a79063..b8efaa65b599 100644 --- a/spring-boot/src/test/java/org/springframework/boot/BannerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/BannerTests.java @@ -19,12 +19,12 @@ import java.io.PrintStream; import org.junit.After; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.MockitoAnnotations; import org.springframework.boot.Banner.Mode; import org.springframework.boot.testutil.InternalOutputCapture; @@ -47,7 +47,6 @@ * @author Michael Stummvoll * @author Michael Simons */ -@RunWith(MockitoJUnitRunner.class) public class BannerTests { private ConfigurableApplicationContext context; @@ -65,6 +64,11 @@ public void cleanUp() { @Captor private ArgumentCaptor> sourceClassCaptor; + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Test public void testDefaultBanner() throws Exception { SpringApplication application = new SpringApplication(Config.class);