Commit 99c6194e authored by Phillip Webb's avatar Phillip Webb

Don't use MockitoJUnitRunner

Replace `@RunWith(MockitoJUnitRunner.class)` with direct Mockito
initialization since the running doesn't support parallel test
execution.
parent 77f6b4c9
...@@ -22,9 +22,8 @@ import org.junit.Before; ...@@ -22,9 +22,8 @@ import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.MockitoAnnotations;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
...@@ -34,7 +33,6 @@ import static org.mockito.BDDMockito.given; ...@@ -34,7 +33,6 @@ import static org.mockito.BDDMockito.given;
* *
* @author Mattias Severson * @author Mattias Severson
*/ */
@RunWith(MockitoJUnitRunner.class)
public class DiskSpaceHealthIndicatorTests { public class DiskSpaceHealthIndicatorTests {
static final long THRESHOLD_BYTES = 1024; static final long THRESHOLD_BYTES = 1024;
...@@ -49,6 +47,7 @@ public class DiskSpaceHealthIndicatorTests { ...@@ -49,6 +47,7 @@ public class DiskSpaceHealthIndicatorTests {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
given(this.fileMock.exists()).willReturn(true); given(this.fileMock.exists()).willReturn(true);
given(this.fileMock.canRead()).willReturn(true); given(this.fileMock.canRead()).willReturn(true);
this.healthIndicator = new DiskSpaceHealthIndicator( this.healthIndicator = new DiskSpaceHealthIndicator(
......
...@@ -34,10 +34,9 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; ...@@ -34,10 +34,9 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.RoutingTable;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.MockitoAnnotations;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
...@@ -48,7 +47,6 @@ import static org.mockito.Matchers.any; ...@@ -48,7 +47,6 @@ import static org.mockito.Matchers.any;
* *
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(MockitoJUnitRunner.class)
public class ElasticsearchHealthIndicatorTests { public class ElasticsearchHealthIndicatorTests {
@Mock @Mock
...@@ -66,9 +64,9 @@ public class ElasticsearchHealthIndicatorTests { ...@@ -66,9 +64,9 @@ public class ElasticsearchHealthIndicatorTests {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
given(this.client.admin()).willReturn(this.admin); given(this.client.admin()).willReturn(this.admin);
given(this.admin.cluster()).willReturn(this.cluster); given(this.admin.cluster()).willReturn(this.cluster);
this.indicator = new ElasticsearchHealthIndicator(this.client, this.properties); this.indicator = new ElasticsearchHealthIndicator(this.client, this.properties);
} }
......
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
package org.springframework.boot.actuate.metrics.writer; package org.springframework.boot.actuate.metrics.writer;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Captor; import org.mockito.Captor;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.MockitoAnnotations;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -31,7 +31,6 @@ import static org.mockito.Mockito.verify; ...@@ -31,7 +31,6 @@ import static org.mockito.Mockito.verify;
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(MockitoJUnitRunner.class)
public class DefaultCounterServiceTests { public class DefaultCounterServiceTests {
private final MetricWriter repository = mock(MetricWriter.class); private final MetricWriter repository = mock(MetricWriter.class);
...@@ -42,6 +41,11 @@ public class DefaultCounterServiceTests { ...@@ -42,6 +41,11 @@ public class DefaultCounterServiceTests {
@Captor @Captor
private ArgumentCaptor<Delta<Number>> captor; private ArgumentCaptor<Delta<Number>> captor;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test @Test
public void incrementWithExistingCounter() { public void incrementWithExistingCounter() {
this.service.increment("counter.foo"); this.service.increment("counter.foo");
......
...@@ -20,9 +20,8 @@ import java.util.List; ...@@ -20,9 +20,8 @@ import java.util.List;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock; 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.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
...@@ -48,7 +47,6 @@ import static org.mockito.BDDMockito.given; ...@@ -48,7 +47,6 @@ import static org.mockito.BDDMockito.given;
* *
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@RunWith(MockitoJUnitRunner.class)
public class EnableAutoConfigurationImportSelectorTests { public class EnableAutoConfigurationImportSelectorTests {
private final EnableAutoConfigurationImportSelector importSelector = new EnableAutoConfigurationImportSelector(); private final EnableAutoConfigurationImportSelector importSelector = new EnableAutoConfigurationImportSelector();
...@@ -64,7 +62,8 @@ public class EnableAutoConfigurationImportSelectorTests { ...@@ -64,7 +62,8 @@ public class EnableAutoConfigurationImportSelectorTests {
private AnnotationAttributes annotationAttributes; private AnnotationAttributes annotationAttributes;
@Before @Before
public void configureImportSelector() { public void setup() {
MockitoAnnotations.initMocks(this);
this.importSelector.setBeanFactory(this.beanFactory); this.importSelector.setBeanFactory(this.beanFactory);
this.importSelector.setEnvironment(this.environment); this.importSelector.setEnvironment(this.environment);
this.importSelector.setResourceLoader(new DefaultResourceLoader()); this.importSelector.setResourceLoader(new DefaultResourceLoader());
......
...@@ -22,9 +22,8 @@ import java.lang.annotation.RetentionPolicy; ...@@ -22,9 +22,8 @@ import java.lang.annotation.RetentionPolicy;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock; 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.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
...@@ -44,7 +43,6 @@ import static org.mockito.Mockito.verifyZeroInteractions; ...@@ -44,7 +43,6 @@ import static org.mockito.Mockito.verifyZeroInteractions;
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(MockitoJUnitRunner.class)
public class ImportAutoConfigurationImportSelectorTests { public class ImportAutoConfigurationImportSelectorTests {
private final ImportAutoConfigurationImportSelector importSelector = new ImportAutoConfigurationImportSelector(); private final ImportAutoConfigurationImportSelector importSelector = new ImportAutoConfigurationImportSelector();
...@@ -55,7 +53,8 @@ public class ImportAutoConfigurationImportSelectorTests { ...@@ -55,7 +53,8 @@ public class ImportAutoConfigurationImportSelectorTests {
private Environment environment; private Environment environment;
@Before @Before
public void configureImportSelector() { public void setup() {
MockitoAnnotations.initMocks(this);
this.importSelector.setBeanFactory(this.beanFactory); this.importSelector.setBeanFactory(this.beanFactory);
this.importSelector.setEnvironment(this.environment); this.importSelector.setEnvironment(this.environment);
this.importSelector.setResourceLoader(new DefaultResourceLoader()); this.importSelector.setResourceLoader(new DefaultResourceLoader());
......
...@@ -18,10 +18,10 @@ package org.springframework.boot.cli.compiler.dependencies; ...@@ -18,10 +18,10 @@ package org.springframework.boot.cli.compiler.dependencies;
import java.util.Arrays; import java.util.Arrays;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.MockitoAnnotations;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
...@@ -31,7 +31,6 @@ import static org.mockito.BDDMockito.given; ...@@ -31,7 +31,6 @@ import static org.mockito.BDDMockito.given;
* *
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(MockitoJUnitRunner.class)
public class CompositeDependencyManagementTests { public class CompositeDependencyManagementTests {
@Mock @Mock
...@@ -40,6 +39,11 @@ public class CompositeDependencyManagementTests { ...@@ -40,6 +39,11 @@ public class CompositeDependencyManagementTests {
@Mock @Mock
private DependencyManagement dependencyManagement2; private DependencyManagement dependencyManagement2;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test @Test
public void unknownSpringBootVersion() { public void unknownSpringBootVersion() {
given(this.dependencyManagement1.getSpringBootVersion()).willReturn(null); given(this.dependencyManagement1.getSpringBootVersion()).willReturn(null);
......
...@@ -24,11 +24,11 @@ import org.eclipse.aether.RepositorySystem; ...@@ -24,11 +24,11 @@ import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.LocalRepositoryManager; import org.eclipse.aether.repository.LocalRepositoryManager;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -43,7 +43,6 @@ import static org.mockito.Mockito.verify; ...@@ -43,7 +43,6 @@ import static org.mockito.Mockito.verify;
* *
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(MockitoJUnitRunner.class)
public class GrapeRootRepositorySystemSessionAutoConfigurationTests { public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
private DefaultRepositorySystemSession session = MavenRepositorySystemUtils private DefaultRepositorySystemSession session = MavenRepositorySystemUtils
...@@ -52,6 +51,11 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests { ...@@ -52,6 +51,11 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
@Mock @Mock
private RepositorySystem repositorySystem; private RepositorySystem repositorySystem;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test @Test
public void noLocalRepositoryWhenNoGrapeRoot() { public void noLocalRepositoryWhenNoGrapeRoot() {
given(this.repositorySystem.newLocalRepositoryManager(eq(this.session), given(this.repositorySystem.newLocalRepositoryManager(eq(this.session),
......
...@@ -29,13 +29,13 @@ import org.eclipse.aether.repository.LocalRepository; ...@@ -29,13 +29,13 @@ import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.LocalRepositoryManager; import org.eclipse.aether.repository.LocalRepositoryManager;
import org.eclipse.aether.repository.Proxy; import org.eclipse.aether.repository.Proxy;
import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.repository.RemoteRepository;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.springframework.boot.cli.testutil.SystemProperties; import org.springframework.boot.cli.testutil.SystemProperties;
...@@ -50,7 +50,6 @@ import static org.mockito.Matchers.eq; ...@@ -50,7 +50,6 @@ import static org.mockito.Matchers.eq;
* *
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(MockitoJUnitRunner.class)
public class SettingsXmlRepositorySystemSessionAutoConfigurationTests { public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
@Rule @Rule
...@@ -59,6 +58,11 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests { ...@@ -59,6 +58,11 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
@Mock @Mock
private RepositorySystem repositorySystem; private RepositorySystem repositorySystem;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test @Test
public void basicSessionCustomization() throws SettingsBuildingException { public void basicSessionCustomization() throws SettingsBuildingException {
assertSessionCustomization("src/test/resources/maven-settings/basic"); assertSessionCustomization("src/test/resources/maven-settings/basic");
......
...@@ -22,9 +22,8 @@ import org.junit.Before; ...@@ -22,9 +22,8 @@ import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.MockitoAnnotations;
import org.springframework.http.HttpRequest; import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestExecution;
...@@ -41,7 +40,6 @@ import static org.mockito.BDDMockito.given; ...@@ -41,7 +40,6 @@ import static org.mockito.BDDMockito.given;
* @author Rob Winch * @author Rob Winch
* @since 1.3.0 * @since 1.3.0
*/ */
@RunWith(MockitoJUnitRunner.class)
public class HttpHeaderInterceptorTests { public class HttpHeaderInterceptorTests {
@Rule @Rule
...@@ -66,7 +64,8 @@ public class HttpHeaderInterceptorTests { ...@@ -66,7 +64,8 @@ public class HttpHeaderInterceptorTests {
private MockHttpServletRequest httpRequest; private MockHttpServletRequest httpRequest;
@Before @Before
public void setup() throws IOException { public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
this.body = new byte[] {}; this.body = new byte[] {};
this.httpRequest = new MockHttpServletRequest(); this.httpRequest = new MockHttpServletRequest();
this.request = new ServletServerHttpRequest(this.httpRequest); this.request = new ServletServerHttpRequest(this.httpRequest);
......
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
package org.springframework.boot.test.mock.mockito; package org.springframework.boot.test.mock.mockito;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.ContextCustomizer;
...@@ -29,11 +29,15 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -29,11 +29,15 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
@RunWith(MockitoJUnitRunner.class)
public class MockitoContextCustomizerFactoryTests { public class MockitoContextCustomizerFactoryTests {
private final MockitoContextCustomizerFactory factory = new MockitoContextCustomizerFactory(); private final MockitoContextCustomizerFactory factory = new MockitoContextCustomizerFactory();
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test @Test
public void getContextCustomizerWithoutAnnotationReturnsCustomizer() public void getContextCustomizerWithoutAnnotationReturnsCustomizer()
throws Exception { throws Exception {
...@@ -57,8 +61,8 @@ public class MockitoContextCustomizerFactoryTests { ...@@ -57,8 +61,8 @@ public class MockitoContextCustomizerFactoryTests {
ContextCustomizer same = this.factory ContextCustomizer same = this.factory
.createContextCustomizer(WithSameMockBeanAnnotation.class, null); .createContextCustomizer(WithSameMockBeanAnnotation.class, null);
assertThat(customizer).isNotNull(); assertThat(customizer).isNotNull();
ContextCustomizer different = this.factory.createContextCustomizer( ContextCustomizer different = this.factory
WithDifferentMockBeanAnnotation.class, null); .createContextCustomizer(WithDifferentMockBeanAnnotation.class, null);
assertThat(different).isNotNull(); assertThat(different).isNotNull();
assertThat(customizer.hashCode()).isEqualTo(same.hashCode()); assertThat(customizer.hashCode()).isEqualTo(same.hashCode());
assertThat(customizer.hashCode()).isNotEqualTo(different.hashCode()); assertThat(customizer.hashCode()).isNotEqualTo(different.hashCode());
......
...@@ -19,12 +19,12 @@ package org.springframework.boot; ...@@ -19,12 +19,12 @@ package org.springframework.boot;
import java.io.PrintStream; import java.io.PrintStream;
import org.junit.After; import org.junit.After;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Captor; import org.mockito.Captor;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.MockitoAnnotations;
import org.springframework.boot.Banner.Mode; import org.springframework.boot.Banner.Mode;
import org.springframework.boot.testutil.InternalOutputCapture; import org.springframework.boot.testutil.InternalOutputCapture;
...@@ -47,7 +47,6 @@ import static org.mockito.Mockito.verify; ...@@ -47,7 +47,6 @@ import static org.mockito.Mockito.verify;
* @author Michael Stummvoll * @author Michael Stummvoll
* @author Michael Simons * @author Michael Simons
*/ */
@RunWith(MockitoJUnitRunner.class)
public class BannerTests { public class BannerTests {
private ConfigurableApplicationContext context; private ConfigurableApplicationContext context;
...@@ -65,6 +64,11 @@ public class BannerTests { ...@@ -65,6 +64,11 @@ public class BannerTests {
@Captor @Captor
private ArgumentCaptor<Class<?>> sourceClassCaptor; private ArgumentCaptor<Class<?>> sourceClassCaptor;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test @Test
public void testDefaultBanner() throws Exception { public void testDefaultBanner() throws Exception {
SpringApplication application = new SpringApplication(Config.class); SpringApplication application = new SpringApplication(Config.class);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment