Skip to content

Commit

Permalink
Don't use MockitoJUnitRunner
Browse files Browse the repository at this point in the history
Replace `@RunWith(MockitoJUnitRunner.class)` with direct Mockito
initialization since the running doesn't support parallel test
execution.
  • Loading branch information
philwebb committed Jun 10, 2016
1 parent 77f6b4c commit 99c6194
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +33,6 @@
*
* @author Mattias Severson
*/
@RunWith(MockitoJUnitRunner.class)
public class DiskSpaceHealthIndicatorTests {

static final long THRESHOLD_BYTES = 1024;
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,7 +47,6 @@
*
* @author Andy Wilkinson
*/
@RunWith(MockitoJUnitRunner.class)
public class ElasticsearchHealthIndicatorTests {

@Mock
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +31,6 @@
*
* @author Dave Syer
*/
@RunWith(MockitoJUnitRunner.class)
public class DefaultCounterServiceTests {

private final MetricWriter repository = mock(MetricWriter.class);
Expand All @@ -42,6 +41,11 @@ public class DefaultCounterServiceTests {
@Captor
private ArgumentCaptor<Delta<Number>> captor;

@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}

@Test
public void incrementWithExistingCounter() {
this.service.increment("counter.foo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,7 +47,6 @@
*
*/
@SuppressWarnings("deprecation")
@RunWith(MockitoJUnitRunner.class)
public class EnableAutoConfigurationImportSelectorTests {

private final EnableAutoConfigurationImportSelector importSelector = new EnableAutoConfigurationImportSelector();
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,7 +43,6 @@
* @author Phillip Webb
* @author Andy Wilkinson
*/
@RunWith(MockitoJUnitRunner.class)
public class ImportAutoConfigurationImportSelectorTests {

private final ImportAutoConfigurationImportSelector importSelector = new ImportAutoConfigurationImportSelector();
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +31,6 @@
*
* @author Andy Wilkinson
*/
@RunWith(MockitoJUnitRunner.class)
public class CompositeDependencyManagementTests {

@Mock
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,7 +43,6 @@
*
* @author Andy Wilkinson
*/
@RunWith(MockitoJUnitRunner.class)
public class GrapeRootRepositorySystemSessionAutoConfigurationTests {

private DefaultRepositorySystemSession session = MavenRepositorySystemUtils
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -50,7 +50,6 @@
*
* @author Andy Wilkinson
*/
@RunWith(MockitoJUnitRunner.class)
public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {

@Rule
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +40,6 @@
* @author Rob Winch
* @since 1.3.0
*/
@RunWith(MockitoJUnitRunner.class)
public class HttpHeaderInterceptorTests {

@Rule
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,7 +47,6 @@
* @author Michael Stummvoll
* @author Michael Simons
*/
@RunWith(MockitoJUnitRunner.class)
public class BannerTests {

private ConfigurableApplicationContext context;
Expand All @@ -65,6 +64,11 @@ public void cleanUp() {
@Captor
private ArgumentCaptor<Class<?>> sourceClassCaptor;

@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}

@Test
public void testDefaultBanner() throws Exception {
SpringApplication application = new SpringApplication(Config.class);
Expand Down

0 comments on commit 99c6194

Please sign in to comment.