Replace Mockito.times(0) with Mockito.never()

Closes gh-12475
pull/12477/merge
dreis2211 7 years ago committed by Phillip Webb
parent 1412e7e690
commit 8626daf135

@ -32,6 +32,7 @@ import org.springframework.context.annotation.Configuration;
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;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -54,7 +55,7 @@ public class HealthEndpointAutoConfigurationTests {
.run((context) -> { .run((context) -> {
ReactiveHealthIndicator indicator = context.getBean( ReactiveHealthIndicator indicator = context.getBean(
"reactiveHealthIndicator", ReactiveHealthIndicator.class); "reactiveHealthIndicator", ReactiveHealthIndicator.class);
verify(indicator, times(0)).health(); verify(indicator, never()).health();
Health health = context.getBean(HealthEndpoint.class).health(); Health health = context.getBean(HealthEndpoint.class).health();
assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails()).isNotEmpty(); assertThat(health.getDetails()).isNotEmpty();
@ -70,7 +71,7 @@ public class HealthEndpointAutoConfigurationTests {
.run((context) -> { .run((context) -> {
ReactiveHealthIndicator indicator = context.getBean( ReactiveHealthIndicator indicator = context.getBean(
"reactiveHealthIndicator", ReactiveHealthIndicator.class); "reactiveHealthIndicator", ReactiveHealthIndicator.class);
verify(indicator, times(0)).health(); verify(indicator, never()).health();
Health health = context.getBean(HealthEndpoint.class).health(); Health health = context.getBean(HealthEndpoint.class).health();
assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails()).containsOnlyKeys("reactive"); assertThat(health.getDetails()).containsOnlyKeys("reactive");
@ -89,8 +90,8 @@ public class HealthEndpointAutoConfigurationTests {
HealthIndicator.class); HealthIndicator.class);
ReactiveHealthIndicator reactiveHealthIndicator = context.getBean( ReactiveHealthIndicator reactiveHealthIndicator = context.getBean(
"reactiveHealthIndicator", ReactiveHealthIndicator.class); "reactiveHealthIndicator", ReactiveHealthIndicator.class);
verify(indicator, times(0)).health(); verify(indicator, never()).health();
verify(reactiveHealthIndicator, times(0)).health(); verify(reactiveHealthIndicator, never()).health();
Health health = context.getBean(HealthEndpoint.class).health(); Health health = context.getBean(HealthEndpoint.class).health();
assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails()).containsOnlyKeys("simple", assertThat(health.getDetails()).containsOnlyKeys("simple",

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ import reactor.test.StepVerifier;
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;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -87,7 +88,7 @@ public class CompositeReactiveHealthIndicatorFactoryTests {
assertThat(h.getDetails()).containsOnlyKeys("test"); assertThat(h.getDetails()).containsOnlyKeys("test");
}).verifyComplete(); }).verifyComplete();
verify(reactiveHealthIndicator, times(1)).health(); verify(reactiveHealthIndicator, times(1)).health();
verify(regularHealthIndicator, times(0)).health(); verify(regularHealthIndicator, never()).health();
} }
private ReactiveHealthIndicator createHealthIndicator( private ReactiveHealthIndicator createHealthIndicator(

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,6 +33,7 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -69,7 +70,7 @@ public class ValidatorAdapterTests {
.getBean(NonManagedBeanConfig.class).validator; .getBean(NonManagedBeanConfig.class).validator;
verify(validator, times(1)).setApplicationContext(any(ApplicationContext.class)); verify(validator, times(1)).setApplicationContext(any(ApplicationContext.class));
verify(validator, times(1)).afterPropertiesSet(); verify(validator, times(1)).afterPropertiesSet();
verify(validator, times(0)).destroy(); verify(validator, never()).destroy();
this.context.close(); this.context.close();
this.context = null; this.context = null;
verify(validator, times(1)).destroy(); verify(validator, times(1)).destroy();
@ -80,12 +81,12 @@ public class ValidatorAdapterTests {
load(ManagedBeanConfig.class); load(ManagedBeanConfig.class);
LocalValidatorFactoryBean validator = this.context LocalValidatorFactoryBean validator = this.context
.getBean(ManagedBeanConfig.class).validator; .getBean(ManagedBeanConfig.class).validator;
verify(validator, times(0)).setApplicationContext(any(ApplicationContext.class)); verify(validator, never()).setApplicationContext(any(ApplicationContext.class));
verify(validator, times(0)).afterPropertiesSet(); verify(validator, never()).afterPropertiesSet();
verify(validator, times(0)).destroy(); verify(validator, never()).destroy();
this.context.close(); this.context.close();
this.context = null; this.context = null;
verify(validator, times(0)).destroy(); verify(validator, never()).destroy();
} }
private ValidatorAdapter load(Class<?> config) { private ValidatorAdapter load(Class<?> config) {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -67,8 +68,8 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
}); });
new GrapeRootRepositorySystemSessionAutoConfiguration().apply(this.session, new GrapeRootRepositorySystemSessionAutoConfiguration().apply(this.session,
this.repositorySystem); this.repositorySystem);
verify(this.repositorySystem, times(0)) verify(this.repositorySystem, never()).newLocalRepositoryManager(eq(this.session),
.newLocalRepositoryManager(eq(this.session), any(LocalRepository.class)); any(LocalRepository.class));
assertThat(this.session.getLocalRepository()).isNull(); assertThat(this.session.getLocalRepository()).isNull();
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,8 +39,8 @@ import org.springframework.context.annotation.Configuration;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
@ -57,7 +57,7 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
SingleDataSourceConfiguration.class); SingleDataSourceConfiguration.class);
DataSource dataSource = context.getBean(DataSource.class); DataSource dataSource = context.getBean(DataSource.class);
Statement statement = configureDataSourceBehavior(dataSource); Statement statement = configureDataSourceBehavior(dataSource);
verify(statement, times(0)).execute("SHUTDOWN"); verify(statement, never()).execute("SHUTDOWN");
} }
@Test @Test
@ -69,7 +69,7 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
.values(); .values();
for (DataSource dataSource : dataSources) { for (DataSource dataSource : dataSources) {
Statement statement = configureDataSourceBehavior(dataSource); Statement statement = configureDataSourceBehavior(dataSource);
verify(statement, times(0)).execute("SHUTDOWN"); verify(statement, never()).execute("SHUTDOWN");
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +29,7 @@ import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner; import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
@ -49,7 +49,7 @@ public class DevToolsEmbeddedDataSourceAutoConfigurationTests
Statement statement = configureDataSourceBehavior( Statement statement = configureDataSourceBehavior(
context.getBean(DataSource.class)); context.getBean(DataSource.class));
context.close(); context.close();
verify(statement, times(0)).execute("SHUTDOWN"); verify(statement, never()).execute("SHUTDOWN");
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,6 +28,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -66,7 +67,7 @@ public class DevToolsPooledDataSourceAutoConfigurationTests
Statement statement = configureDataSourceBehavior( Statement statement = configureDataSourceBehavior(
context.getBean(DataSource.class)); context.getBean(DataSource.class));
context.close(); context.close();
verify(statement, times(0)).execute("SHUTDOWN"); verify(statement, never()).execute("SHUTDOWN");
} }
@Test @Test
@ -77,7 +78,7 @@ public class DevToolsPooledDataSourceAutoConfigurationTests
Statement statement = configureDataSourceBehavior( Statement statement = configureDataSourceBehavior(
context.getBean(DataSource.class)); context.getBean(DataSource.class));
context.close(); context.close();
verify(statement, times(0)).execute("SHUTDOWN"); verify(statement, never()).execute("SHUTDOWN");
} }
@Test @Test
@ -99,7 +100,7 @@ public class DevToolsPooledDataSourceAutoConfigurationTests
Statement statement = configureDataSourceBehavior( Statement statement = configureDataSourceBehavior(
context.getBean(DataSource.class)); context.getBean(DataSource.class));
context.close(); context.close();
verify(statement, times(0)).execute("SHUTDOWN"); verify(statement, never()).execute("SHUTDOWN");
} }
@Test @Test
@ -121,7 +122,7 @@ public class DevToolsPooledDataSourceAutoConfigurationTests
Statement statement = configureDataSourceBehavior( Statement statement = configureDataSourceBehavior(
context.getBean(DataSource.class)); context.getBean(DataSource.class));
context.close(); context.close();
verify(statement, times(0)).execute("SHUTDOWN"); verify(statement, never()).execute("SHUTDOWN");
} }
@Test @Test

@ -106,7 +106,6 @@ import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions;
@ -655,7 +654,7 @@ public class SpringApplicationTests {
finally { finally {
verify(listener).onApplicationEvent(isA(ApplicationStartedEvent.class)); verify(listener).onApplicationEvent(isA(ApplicationStartedEvent.class));
verify(listener).onApplicationEvent(isA(ApplicationFailedEvent.class)); verify(listener).onApplicationEvent(isA(ApplicationFailedEvent.class));
verify(listener, times(0)) verify(listener, never())
.onApplicationEvent(isA(ApplicationReadyEvent.class)); .onApplicationEvent(isA(ApplicationReadyEvent.class));
} }
} }
@ -681,7 +680,7 @@ public class SpringApplicationTests {
finally { finally {
verify(listener).onApplicationEvent(isA(ApplicationStartedEvent.class)); verify(listener).onApplicationEvent(isA(ApplicationStartedEvent.class));
verify(listener).onApplicationEvent(isA(ApplicationFailedEvent.class)); verify(listener).onApplicationEvent(isA(ApplicationFailedEvent.class));
verify(listener, times(0)) verify(listener, never())
.onApplicationEvent(isA(ApplicationReadyEvent.class)); .onApplicationEvent(isA(ApplicationReadyEvent.class));
} }
} }
@ -703,7 +702,7 @@ public class SpringApplicationTests {
} }
finally { finally {
verify(listener).onApplicationEvent(isA(ApplicationReadyEvent.class)); verify(listener).onApplicationEvent(isA(ApplicationReadyEvent.class));
verify(listener, times(0)) verify(listener, never())
.onApplicationEvent(isA(ApplicationFailedEvent.class)); .onApplicationEvent(isA(ApplicationFailedEvent.class));
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -89,7 +90,7 @@ public class DataSourceXAResourceRecoveryHelperTests {
XAResource[] xaResources = this.recoveryHelper.getXAResources(); XAResource[] xaResources = this.recoveryHelper.getXAResources();
assertThat(xaResources.length).isEqualTo(0); assertThat(xaResources.length).isEqualTo(0);
verify(this.xaDataSource, times(1)).getXAConnection(); verify(this.xaDataSource, times(1)).getXAConnection();
verify(this.xaConnection, times(0)).getXAResource(); verify(this.xaConnection, never()).getXAResource();
} }
@Test @Test

@ -39,7 +39,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
@ -123,7 +123,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean(); AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
bean.setEnabled(false); bean.setEnabled(false);
bean.onStartup(this.servletContext); bean.onStartup(this.servletContext);
verify(this.servletContext, times(0)).addFilter(eq("mockFilter"), verify(this.servletContext, never()).addFilter(eq("mockFilter"),
getExpectedFilter()); getExpectedFilter());
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +29,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
@ -67,7 +67,7 @@ public class ServletListenerRegistrationBeanTests {
this.listener); this.listener);
bean.setEnabled(false); bean.setEnabled(false);
bean.onStartup(this.servletContext); bean.onStartup(this.servletContext);
verify(this.servletContext, times(0)) verify(this.servletContext, never())
.addListener(any(ServletContextListener.class)); .addListener(any(ServletContextListener.class));
} }

@ -41,7 +41,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
@ -140,7 +139,7 @@ public class ServletRegistrationBeanTests {
bean.setServlet(this.servlet); bean.setServlet(this.servlet);
bean.setEnabled(false); bean.setEnabled(false);
bean.onStartup(this.servletContext); bean.onStartup(this.servletContext);
verify(this.servletContext, times(0)).addServlet("mockServlet", this.servlet); verify(this.servletContext, never()).addServlet("mockServlet", this.servlet);
} }
@Test @Test

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -48,7 +48,7 @@ import org.springframework.web.util.NestedServletException;
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;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
@ -447,7 +447,7 @@ public class ErrorPageFilterTests {
given(committedResponse.isCommitted()).willReturn(true); given(committedResponse.isCommitted()).willReturn(true);
given(committedResponse.getStatus()).willReturn(200); given(committedResponse.getStatus()).willReturn(200);
this.filter.doFilter(this.request, committedResponse, this.chain); this.filter.doFilter(this.request, committedResponse, this.chain);
verify(committedResponse, times(0)).flushBuffer(); verify(committedResponse, never()).flushBuffer();
} }
@Test @Test

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,7 +24,7 @@ import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
@ -50,7 +50,7 @@ public class ServletContextApplicationContextInitializerTests {
public void applicationContextIsNotStoredInServletContextByDefault() { public void applicationContextIsNotStoredInServletContextByDefault() {
new ServletContextApplicationContextInitializer(this.servletContext) new ServletContextApplicationContextInitializer(this.servletContext)
.initialize(this.applicationContext); .initialize(this.applicationContext);
verify(this.servletContext, times(0)).setAttribute( verify(this.servletContext, never()).setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
this.applicationContext); this.applicationContext);
} }

Loading…
Cancel
Save