Enforce use of BDDMockito

1. Replace Mockito.verify*() with BDDMockito.then()
2. Replace Mockito.doReturn() with BDDMockito.willReturn()
3. Adjust checkstyle rule

See gh-29178
This commit is contained in:
Yanming Zhou
2021-12-27 18:36:32 +08:00
committed by Stephane Nicoll
parent f60af4dbbd
commit b49418aaaf
190 changed files with 1291 additions and 1142 deletions

View File

@@ -36,16 +36,17 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doReturn;
import static org.mockito.BDDMockito.then;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
/**
* Base class for tests for {@link DevToolsDataSourceAutoConfiguration}.
*
* @author Andy Wilkinson
* @author Yanming Zhou
*/
abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
@@ -54,7 +55,7 @@ abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
ConfigurableApplicationContext context = getContext(() -> createContext(SingleDataSourceConfiguration.class));
DataSource dataSource = context.getBean(DataSource.class);
Statement statement = configureDataSourceBehavior(dataSource);
verify(statement, never()).execute("SHUTDOWN");
then(statement).should(never()).execute("SHUTDOWN");
}
@Test
@@ -64,7 +65,7 @@ abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
Collection<DataSource> dataSources = context.getBeansOfType(DataSource.class).values();
for (DataSource dataSource : dataSources) {
Statement statement = configureDataSourceBehavior(dataSource);
verify(statement, never()).execute("SHUTDOWN");
then(statement).should(never()).execute("SHUTDOWN");
}
}
@@ -82,7 +83,7 @@ abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
protected final Statement configureDataSourceBehavior(DataSource dataSource) throws SQLException {
Connection connection = mock(Connection.class);
Statement statement = mock(Statement.class);
doReturn(connection).when(dataSource).getConnection();
willReturn(connection).given(dataSource).getConnection();
given(connection.createStatement()).willReturn(statement);
return statement;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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,13 +27,14 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import org.springframework.context.ConfigurableApplicationContext;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link DevToolsDataSourceAutoConfiguration} with an embedded data source.
*
* @author Andy Wilkinson
* @author Yanming Zhou
*/
@ClassPathExclusions("HikariCP-*.jar")
class DevToolsEmbeddedDataSourceAutoConfigurationTests extends AbstractDevToolsDataSourceAutoConfigurationTests {
@@ -44,7 +45,7 @@ class DevToolsEmbeddedDataSourceAutoConfigurationTests extends AbstractDevToolsD
DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close();
verify(statement, never()).execute("SHUTDOWN");
then(statement).should(never()).execute("SHUTDOWN");
}
}

View File

@@ -39,14 +39,14 @@ import org.springframework.jdbc.core.JdbcTemplate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link DevToolsDataSourceAutoConfiguration} with a pooled data source.
*
* @author Andy Wilkinson
* @author Yanming Zhou
*/
class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDataSourceAutoConfigurationTests {
@@ -66,7 +66,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat
() -> createContext(DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class));
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close();
verify(statement).execute("SHUTDOWN");
then(statement).should().execute("SHUTDOWN");
}
@Test
@@ -75,7 +75,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class));
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close();
verify(statement, never()).execute("SHUTDOWN");
then(statement).should(never()).execute("SHUTDOWN");
}
@Test
@@ -84,7 +84,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat
"jdbc:h2:hsql://localhost", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class));
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close();
verify(statement, never()).execute("SHUTDOWN");
then(statement).should(never()).execute("SHUTDOWN");
}
@Test
@@ -93,7 +93,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class));
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close();
verify(statement, times(1)).execute("SHUTDOWN");
then(statement).should().execute("SHUTDOWN");
}
@Test
@@ -102,7 +102,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat
"jdbc:hsqldb:hsql://localhost", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class));
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close();
verify(statement, never()).execute("SHUTDOWN");
then(statement).should(never()).execute("SHUTDOWN");
}
@Test
@@ -111,7 +111,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat
"jdbc:hsqldb:mem:test", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class));
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close();
verify(statement, times(1)).execute("SHUTDOWN");
then(statement).should().execute("SHUTDOWN");
}
@Test
@@ -120,7 +120,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat
"jdbc:derby://localhost", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class));
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close();
verify(statement, never()).execute("SHUTDOWN");
then(statement).should(never()).execute("SHUTDOWN");
}
@Test

View File

@@ -59,10 +59,10 @@ import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link LocalDevToolsAutoConfiguration}.
@@ -70,6 +70,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Andy Wilkinson
* @author Vladimir Tsanev
* @author Yanming Zhou
*/
@ExtendWith(MockRestarter.class)
class LocalDevToolsAutoConfigurationTests {
@@ -134,7 +135,7 @@ class LocalDevToolsAutoConfigurationTests {
LiveReloadServer server = this.context.getBean(LiveReloadServer.class);
reset(server);
this.context.publishEvent(new ContextRefreshedEvent(this.context));
verify(server).triggerReload();
then(server).should().triggerReload();
}
@Test
@@ -144,7 +145,7 @@ class LocalDevToolsAutoConfigurationTests {
reset(server);
ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.emptySet(), false);
this.context.publishEvent(event);
verify(server).triggerReload();
then(server).should().triggerReload();
}
@Test
@@ -154,7 +155,7 @@ class LocalDevToolsAutoConfigurationTests {
reset(server);
ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.emptySet(), true);
this.context.publishEvent(event);
verify(server, never()).triggerReload();
then(server).should(never()).triggerReload();
}
@Test
@@ -171,7 +172,7 @@ class LocalDevToolsAutoConfigurationTests {
this.context = getContext(() -> initializeAndRun(Config.class));
ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.emptySet(), true);
this.context.publishEvent(event);
verify(restarter).restart(any(FailureHandler.class));
then(restarter).should().restart(any(FailureHandler.class));
}
@Test
@@ -179,7 +180,7 @@ class LocalDevToolsAutoConfigurationTests {
this.context = getContext(() -> initializeAndRun(Config.class));
ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.emptySet(), false);
this.context.publishEvent(event);
verify(restarter, never()).restart();
then(restarter).should(never()).restart();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -20,15 +20,16 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.devtools.livereload.LiveReloadServer;
import static org.mockito.BDDMockito.then;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link OptionalLiveReloadServer}.
*
* @author Phillip Webb
* @author Yanming Zhou
*/
class OptionalLiveReloadServerTests {
@@ -46,7 +47,7 @@ class OptionalLiveReloadServerTests {
willThrow(new RuntimeException("Error")).given(delegate).start();
server.startServer();
server.triggerReload();
verify(delegate, never()).triggerReload();
then(delegate).should(never()).triggerReload();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -37,13 +37,14 @@ import org.springframework.context.ApplicationEventPublisher;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link ClassPathFileChangeListener}.
*
* @author Phillip Webb
* @author Yanming Zhou
*/
@ExtendWith(MockitoExtension.class)
class ClassPathFileChangeListenerTests {
@@ -77,13 +78,13 @@ class ClassPathFileChangeListenerTests {
@Test
void sendsEventWithoutRestart() {
testSendsEvent(false);
verify(this.fileSystemWatcher, never()).stop();
then(this.fileSystemWatcher).should(never()).stop();
}
@Test
void sendsEventWithRestart() {
testSendsEvent(true);
verify(this.fileSystemWatcher).stop();
then(this.fileSystemWatcher).should().stop();
}
private void testSendsEvent(boolean restart) {
@@ -102,7 +103,7 @@ class ClassPathFileChangeListenerTests {
given(this.restartStrategy.isRestartRequired(file2)).willReturn(true);
}
listener.onChange(changeSet);
verify(this.eventPublisher).publishEvent(this.eventCaptor.capture());
then(this.eventPublisher).should().publishEvent(this.eventCaptor.capture());
ClassPathChangedEvent actualEvent = (ClassPathChangedEvent) this.eventCaptor.getValue();
assertThat(actualEvent.getChangeSet()).isEqualTo(changeSet);
assertThat(actualEvent.isRestartRequired()).isEqualTo(restart);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -23,13 +23,14 @@ import java.io.OutputStream;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link ConnectionOutputStream}.
*
* @author Phillip Webb
* @author Yanming Zhou
*/
@SuppressWarnings("resource")
class ConnectionOutputStreamTests {
@@ -40,7 +41,7 @@ class ConnectionOutputStreamTests {
ConnectionOutputStream outputStream = new ConnectionOutputStream(out);
byte[] b = new byte[100];
outputStream.write(b, 1, 2);
verify(out).write(b, 1, 2);
then(out).should().write(b, 1, 2);
}
@Test

View File

@@ -35,13 +35,14 @@ import org.springframework.http.client.ClientHttpResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link DelayedLiveReloadTrigger}.
*
* @author Phillip Webb
* @author Yanming Zhou
*/
@ExtendWith(MockitoExtension.class)
class DelayedLiveReloadTriggerTests {
@@ -113,7 +114,7 @@ class DelayedLiveReloadTriggerTests {
this.trigger.setTimings(10, 200, 30000);
this.trigger.run();
assertThat(System.currentTimeMillis() - startTime).isGreaterThan(300L);
verify(this.liveReloadServer).triggerReload();
then(this.liveReloadServer).should().triggerReload();
}
@Test
@@ -121,7 +122,7 @@ class DelayedLiveReloadTriggerTests {
given(this.requestFactory.createRequest(new URI(URL), HttpMethod.GET)).willThrow(new IOException());
this.trigger.setTimings(10, 0, 10);
this.trigger.run();
verify(this.liveReloadServer, never()).triggerReload();
then(this.liveReloadServer).should(never()).triggerReload();
}
}

View File

@@ -52,13 +52,14 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link RemoteClientConfiguration}.
*
* @author Phillip Webb
* @author Yanming Zhou
*/
@ExtendWith({ OutputCaptureExtension.class, MockRestarter.class })
class RemoteClientConfigurationTests {
@@ -108,7 +109,7 @@ class RemoteClientConfigurationTests {
ClassPathChangedEvent event = new ClassPathChangedEvent(this, changeSet, false);
this.clientContext.publishEvent(event);
LiveReloadServer server = this.clientContext.getBean(LiveReloadServer.class);
Awaitility.await().atMost(Duration.ofMinutes(1)).untilAsserted(() -> verify(server).triggerReload());
Awaitility.await().atMost(Duration.ofMinutes(1)).untilAsserted(() -> then(server).should().triggerReload());
}
@Test

View File

@@ -40,10 +40,9 @@ import org.springframework.mock.web.MockHttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.then;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
/**
* Tests for {@link DispatcherFilter}.
@@ -83,8 +82,8 @@ class DispatcherFilterTests {
ServletRequest request = mock(ServletRequest.class);
ServletResponse response = mock(ServletResponse.class);
this.filter.doFilter(request, response, this.chain);
verifyNoInteractions(this.dispatcher);
verify(this.chain).doFilter(request, response);
then(this.dispatcher).shouldHaveNoInteractions();
then(this.chain).should().doFilter(request, response);
}
@Test
@@ -92,7 +91,7 @@ class DispatcherFilterTests {
HttpServletRequest request = new MockHttpServletRequest("GET", "/hello");
HttpServletResponse response = new MockHttpServletResponse();
this.filter.doFilter(request, response, this.chain);
verify(this.chain).doFilter(request, response);
then(this.chain).should().doFilter(request, response);
}
@Test
@@ -101,8 +100,8 @@ class DispatcherFilterTests {
HttpServletResponse response = new MockHttpServletResponse();
willReturn(true).given(this.dispatcher).handle(any(ServerHttpRequest.class), any(ServerHttpResponse.class));
this.filter.doFilter(request, response, this.chain);
verifyNoInteractions(this.chain);
verify(this.dispatcher).handle(this.serverRequestCaptor.capture(), this.serverResponseCaptor.capture());
then(this.chain).shouldHaveNoInteractions();
then(this.dispatcher).should().handle(this.serverRequestCaptor.capture(), this.serverResponseCaptor.capture());
ServerHttpRequest dispatcherRequest = this.serverRequestCaptor.getValue();
ServletServerHttpRequest actualRequest = (ServletServerHttpRequest) dispatcherRequest;
ServerHttpResponse dispatcherResponse = this.serverResponseCaptor.getValue();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -38,16 +38,16 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.withSettings;
/**
* Tests for {@link Dispatcher}.
*
* @author Phillip Webb
* @author Yanming Zhou
*/
@ExtendWith(MockitoExtension.class)
class DispatcherTests {
@@ -81,7 +81,7 @@ class DispatcherTests {
given(mapper.getHandler(any(ServerHttpRequest.class))).willReturn(handler);
Dispatcher dispatcher = new Dispatcher(this.accessManager, Collections.singleton(mapper));
dispatcher.handle(this.serverRequest, this.serverResponse);
verifyNoInteractions(handler);
then(handler).shouldHaveNoInteractions();
assertThat(this.response.getStatus()).isEqualTo(403);
}
@@ -93,7 +93,7 @@ class DispatcherTests {
given(mapper.getHandler(any(ServerHttpRequest.class))).willReturn(handler);
Dispatcher dispatcher = new Dispatcher(this.accessManager, Collections.singleton(mapper));
dispatcher.handle(this.serverRequest, this.serverResponse);
verify(handler).handle(this.serverRequest, this.serverResponse);
then(handler).should().handle(this.serverRequest, this.serverResponse);
}
@Test
@@ -106,8 +106,8 @@ class DispatcherTests {
Dispatcher dispatcher = new Dispatcher(AccessManager.PERMIT_ALL, mappers);
dispatcher.handle(this.serverRequest, this.serverResponse);
InOrder inOrder = inOrder(mapper1, mapper2);
inOrder.verify(mapper1).getHandler(this.serverRequest);
inOrder.verify(mapper2).getHandler(this.serverRequest);
then(mapper1).should(inOrder).getHandler(this.serverRequest);
then(mapper2).should(inOrder).getHandler(this.serverRequest);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -41,8 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link ClassLoaderFilesResourcePatternResolver}.
@@ -50,6 +50,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Yanming Zhou
*/
class ClassLoaderFilesResourcePatternResolverTests {
@@ -112,7 +113,7 @@ class ClassLoaderFilesResourcePatternResolverTests {
context.setResourceLoader(resourceLoader);
this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
this.resolver.getResource("foo.txt");
verify(resourceLoader).getResource("foo.txt");
then(resourceLoader).should().getResource("foo.txt");
}
@Test
@@ -124,7 +125,7 @@ class ClassLoaderFilesResourcePatternResolverTests {
this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
Resource actual = this.resolver.getResource("foo:some-file.txt");
assertThat(actual).isSameAs(resource);
verify(resolver).resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
}
@Test
@@ -136,7 +137,7 @@ class ClassLoaderFilesResourcePatternResolverTests {
context.addProtocolResolver(resolver);
Resource actual = this.resolver.getResource("foo:some-file.txt");
assertThat(actual).isSameAs(resource);
verify(resolver).resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
}
@Test
@@ -146,7 +147,7 @@ class ClassLoaderFilesResourcePatternResolverTests {
context.setResourceLoader(resourceLoader);
this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
this.resolver.getResource("foo.txt");
verify(resourceLoader).getResource("foo.txt");
then(resourceLoader).should().getResource("foo.txt");
}
@Test
@@ -158,7 +159,7 @@ class ClassLoaderFilesResourcePatternResolverTests {
this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
Resource actual = this.resolver.getResource("foo:some-file.txt");
assertThat(actual).isSameAs(resource);
verify(resolver).resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
}
@Test
@@ -170,7 +171,7 @@ class ClassLoaderFilesResourcePatternResolverTests {
context.addProtocolResolver(resolver);
Resource actual = this.resolver.getResource("foo:some-file.txt");
assertThat(actual).isSameAs(resource);
verify(resolver).resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
}
private ProtocolResolver mockProtocolResolver(String path, Resource resource) {

View File

@@ -49,14 +49,15 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;
/**
* Tests for {@link Restarter}.
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Yanming Zhou
*/
@ExtendWith(OutputCaptureExtension.class)
class RestarterTests {
@@ -140,7 +141,7 @@ class RestarterTests {
ObjectFactory objectFactory = mock(ObjectFactory.class);
Object attribute = Restarter.getInstance().getOrAddAttribute("x", objectFactory);
assertThat(attribute).isEqualTo("abc");
verifyNoInteractions(objectFactory);
then(objectFactory).shouldHaveNoInteractions();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -22,13 +22,14 @@ import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link HttpRestartServerHandler}.
*
* @author Phillip Webb
* @author Yanming Zhou
*/
class HttpRestartServerHandlerTests {
@@ -45,7 +46,7 @@ class HttpRestartServerHandlerTests {
ServerHttpRequest request = mock(ServerHttpRequest.class);
ServerHttpResponse response = mock(ServerHttpResponse.class);
handler.handle(request, response);
verify(server).handle(request, response);
then(server).should().handle(request, response);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -38,13 +38,13 @@ import org.springframework.mock.web.MockHttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.BDDMockito.then;
/**
* Tests for {@link HttpRestartServer}.
*
* @author Phillip Webb
* @author Yanming Zhou
*/
@ExtendWith(MockitoExtension.class)
class HttpRestartServerTests {
@@ -83,7 +83,7 @@ class HttpRestartServerTests {
byte[] bytes = serialize(files);
request.setContent(bytes);
this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response));
verify(this.delegate).updateAndRestart(this.filesCaptor.capture());
then(this.delegate).should().updateAndRestart(this.filesCaptor.capture());
assertThat(this.filesCaptor.getValue().getFile("name")).isNotNull();
assertThat(response.getStatus()).isEqualTo(200);
}
@@ -93,7 +93,7 @@ class HttpRestartServerTests {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response));
verifyNoInteractions(this.delegate);
then(this.delegate).shouldHaveNoInteractions();
assertThat(response.getStatus()).isEqualTo(500);
}
@@ -104,7 +104,7 @@ class HttpRestartServerTests {
MockHttpServletResponse response = new MockHttpServletResponse();
request.setContent(new byte[] { 0, 0, 0 });
this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response));
verifyNoInteractions(this.delegate);
then(this.delegate).shouldHaveNoInteractions();
assertThat(response.getStatus()).isEqualTo(500);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -39,9 +39,8 @@ import org.springframework.http.HttpStatus;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link HttpTunnelConnection}.
@@ -49,6 +48,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Rob Winch
* @author Andy Wilkinson
* @author Yanming Zhou
*/
@ExtendWith({ OutputCaptureExtension.class, MockitoExtension.class })
class HttpTunnelConnectionTests {
@@ -109,10 +109,10 @@ class HttpTunnelConnectionTests {
void closeTunnelCallsCloseableOnce() throws Exception {
this.requestFactory.willRespondAfterDelay(1000, HttpStatus.GONE);
WritableByteChannel channel = openTunnel(false);
verify(this.closeable, never()).close();
then(this.closeable).should(never()).close();
channel.close();
channel.close();
verify(this.closeable, times(1)).close();
then(this.closeable).should().close();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -22,13 +22,14 @@ import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link HttpTunnelServerHandler}.
*
* @author Phillip Webb
* @author Yanming Zhou
*/
class HttpTunnelServerHandlerTests {
@@ -45,7 +46,7 @@ class HttpTunnelServerHandlerTests {
ServerHttpRequest request = mock(ServerHttpRequest.class);
ServerHttpResponse response = mock(ServerHttpResponse.class);
handler.handle(request, response);
verify(server).handle(request, response);
then(server).should().handle(request, response);
}
}

View File

@@ -50,15 +50,15 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link HttpTunnelServer}.
*
* @author Phillip Webb
* @author Yanming Zhou
*/
@ExtendWith(MockitoExtension.class)
class HttpTunnelServerTests {
@@ -105,10 +105,10 @@ class HttpTunnelServerTests {
@Test
void serverConnectedOnFirstRequest() throws Exception {
verify(this.serverConnection, never()).open(anyInt());
then(this.serverConnection).should(never()).open(anyInt());
givenServerConnectionOpenWillAnswerWithServerChannel();
this.server.handle(this.request, this.response);
verify(this.serverConnection, times(1)).open(DEFAULT_LONG_POLL_TIMEOUT);
then(this.serverConnection).should().open(DEFAULT_LONG_POLL_TIMEOUT);
}
@Test
@@ -116,7 +116,7 @@ class HttpTunnelServerTests {
givenServerConnectionOpenWillAnswerWithServerChannel();
this.server.setLongPollTimeout(800);
this.server.handle(this.request, this.response);
verify(this.serverConnection, times(1)).open(800);
then(this.serverConnection).should().open(800);
}
@Test
@@ -294,9 +294,9 @@ class HttpTunnelServerTests {
given(request.getAsyncRequestControl(this.response)).willReturn(async);
HttpConnection connection = new HttpConnection(request, this.response);
connection.waitForResponse();
verify(async).start();
then(async).should().start();
connection.respond(HttpStatus.NO_CONTENT);
verify(async).complete();
then(async).should().complete();
}
@Test