Migrate to BDD Mockito
Migrate all tests to consistently use BDD Mockito. Also add checksyle rule to enforce going forwards.
This commit is contained in:
@@ -34,8 +34,8 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.withSettings;
|
||||
|
||||
/**
|
||||
@@ -83,7 +83,7 @@ public class HttpComponentsClientHttpRequestFactoryTests extends AbstractHttpReq
|
||||
CloseableHttpClient client = mock(CloseableHttpClient.class,
|
||||
withSettings().extraInterfaces(Configurable.class));
|
||||
Configurable configurable = (Configurable) client;
|
||||
when(configurable.getConfig()).thenReturn(defaultConfig);
|
||||
given(configurable.getConfig()).willReturn(defaultConfig);
|
||||
|
||||
HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(client);
|
||||
assertSame("Default client configuration is expected", defaultConfig, retrieveRequestConfig(hrf));
|
||||
@@ -103,7 +103,7 @@ public class HttpComponentsClientHttpRequestFactoryTests extends AbstractHttpReq
|
||||
CloseableHttpClient client = mock(CloseableHttpClient.class,
|
||||
withSettings().extraInterfaces(Configurable.class));
|
||||
Configurable configurable = (Configurable) client;
|
||||
when(configurable.getConfig()).thenReturn(defaultConfig);
|
||||
given(configurable.getConfig()).willReturn(defaultConfig);
|
||||
|
||||
HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(client);
|
||||
hrf.setConnectTimeout(5000);
|
||||
@@ -121,7 +121,7 @@ public class HttpComponentsClientHttpRequestFactoryTests extends AbstractHttpReq
|
||||
final CloseableHttpClient client = mock(CloseableHttpClient.class,
|
||||
withSettings().extraInterfaces(Configurable.class));
|
||||
Configurable configurable = (Configurable) client;
|
||||
when(configurable.getConfig()).thenReturn(defaultConfig);
|
||||
given(configurable.getConfig()).willReturn(defaultConfig);
|
||||
|
||||
HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory() {
|
||||
@Override
|
||||
@@ -139,7 +139,7 @@ public class HttpComponentsClientHttpRequestFactoryTests extends AbstractHttpReq
|
||||
// Update the Http client so that it returns an updated config
|
||||
RequestConfig updatedDefaultConfig = RequestConfig.custom()
|
||||
.setConnectTimeout(1234).build();
|
||||
when(configurable.getConfig()).thenReturn(updatedDefaultConfig);
|
||||
given(configurable.getConfig()).willReturn(updatedDefaultConfig);
|
||||
hrf.setReadTimeout(7000);
|
||||
RequestConfig requestConfig2 = retrieveRequestConfig(hrf);
|
||||
assertEquals(1234, requestConfig2.getConnectTimeout());
|
||||
|
||||
@@ -31,7 +31,7 @@ import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.BDDMockito.willDoNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -100,7 +100,7 @@ public class SimpleClientHttpResponseTests {
|
||||
public void shouldNotDrainWhenErrorStreamClosed() throws Exception {
|
||||
InputStream is = mock(InputStream.class);
|
||||
given(this.connection.getErrorStream()).willReturn(is);
|
||||
doNothing().when(is).close();
|
||||
willDoNothing().given(is).close();
|
||||
given(is.read(any())).willThrow(new NullPointerException("from HttpURLConnection#ErrorStream"));
|
||||
|
||||
InputStream responseStream = this.response.getBody();
|
||||
|
||||
@@ -45,7 +45,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.springframework.core.ResolvableType.forClass;
|
||||
import static org.springframework.http.MediaType.TEXT_HTML;
|
||||
import static org.springframework.http.MediaType.TEXT_PLAIN;
|
||||
@@ -88,7 +88,7 @@ public class EncoderHttpMessageWriterTests {
|
||||
@Test
|
||||
public void canWrite() {
|
||||
HttpMessageWriter<?> writer = getWriter(MimeTypeUtils.TEXT_HTML);
|
||||
when(this.encoder.canEncode(forClass(String.class), TEXT_HTML)).thenReturn(true);
|
||||
given(this.encoder.canEncode(forClass(String.class), TEXT_HTML)).willReturn(true);
|
||||
|
||||
assertTrue(writer.canWrite(forClass(String.class), TEXT_HTML));
|
||||
assertFalse(writer.canWrite(forClass(String.class), TEXT_XML));
|
||||
@@ -184,8 +184,8 @@ public class EncoderHttpMessageWriterTests {
|
||||
|
||||
private HttpMessageWriter<String> getWriter(Flux<DataBuffer> encodedStream, MimeType... mimeTypes) {
|
||||
List<MimeType> typeList = Arrays.asList(mimeTypes);
|
||||
when(this.encoder.getEncodableMimeTypes()).thenReturn(typeList);
|
||||
when(this.encoder.encode(any(), any(), any(), this.mediaTypeCaptor.capture(), any())).thenReturn(encodedStream);
|
||||
given(this.encoder.getEncodableMimeTypes()).willReturn(typeList);
|
||||
given(this.encoder.encode(any(), any(), any(), this.mediaTypeCaptor.capture(), any())).willReturn(encodedStream);
|
||||
return new EncoderHttpMessageWriter<>(this.encoder);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,8 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Sebastien Deleuze
|
||||
@@ -97,7 +97,7 @@ public class MultipartHttpMessageWriterTests extends AbstractLeakCheckingTestCas
|
||||
this.bufferFactory.wrap("Cc".getBytes(StandardCharsets.UTF_8))
|
||||
);
|
||||
Part mockPart = mock(Part.class);
|
||||
when(mockPart.content()).thenReturn(bufferPublisher);
|
||||
given(mockPart.content()).willReturn(bufferPublisher);
|
||||
|
||||
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
|
||||
bodyBuilder.part("name 1", "value 1");
|
||||
|
||||
@@ -56,8 +56,8 @@ import org.springframework.util.MimeTypeUtils;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link BaseDefaultCodecs}.
|
||||
@@ -110,14 +110,14 @@ public class CodecConfigurerTests {
|
||||
Decoder<?> customDecoder1 = mock(Decoder.class);
|
||||
Decoder<?> customDecoder2 = mock(Decoder.class);
|
||||
|
||||
when(customDecoder1.canDecode(ResolvableType.forClass(Object.class), null)).thenReturn(false);
|
||||
when(customDecoder2.canDecode(ResolvableType.forClass(Object.class), null)).thenReturn(true);
|
||||
given(customDecoder1.canDecode(ResolvableType.forClass(Object.class), null)).willReturn(false);
|
||||
given(customDecoder2.canDecode(ResolvableType.forClass(Object.class), null)).willReturn(true);
|
||||
|
||||
HttpMessageReader<?> customReader1 = mock(HttpMessageReader.class);
|
||||
HttpMessageReader<?> customReader2 = mock(HttpMessageReader.class);
|
||||
|
||||
when(customReader1.canRead(ResolvableType.forClass(Object.class), null)).thenReturn(false);
|
||||
when(customReader2.canRead(ResolvableType.forClass(Object.class), null)).thenReturn(true);
|
||||
given(customReader1.canRead(ResolvableType.forClass(Object.class), null)).willReturn(false);
|
||||
given(customReader2.canRead(ResolvableType.forClass(Object.class), null)).willReturn(true);
|
||||
|
||||
this.configurer.customCodecs().decoder(customDecoder1);
|
||||
this.configurer.customCodecs().decoder(customDecoder2);
|
||||
@@ -150,14 +150,14 @@ public class CodecConfigurerTests {
|
||||
Encoder<?> customEncoder1 = mock(Encoder.class);
|
||||
Encoder<?> customEncoder2 = mock(Encoder.class);
|
||||
|
||||
when(customEncoder1.canEncode(ResolvableType.forClass(Object.class), null)).thenReturn(false);
|
||||
when(customEncoder2.canEncode(ResolvableType.forClass(Object.class), null)).thenReturn(true);
|
||||
given(customEncoder1.canEncode(ResolvableType.forClass(Object.class), null)).willReturn(false);
|
||||
given(customEncoder2.canEncode(ResolvableType.forClass(Object.class), null)).willReturn(true);
|
||||
|
||||
HttpMessageWriter<?> customWriter1 = mock(HttpMessageWriter.class);
|
||||
HttpMessageWriter<?> customWriter2 = mock(HttpMessageWriter.class);
|
||||
|
||||
when(customWriter1.canWrite(ResolvableType.forClass(Object.class), null)).thenReturn(false);
|
||||
when(customWriter2.canWrite(ResolvableType.forClass(Object.class), null)).thenReturn(true);
|
||||
given(customWriter1.canWrite(ResolvableType.forClass(Object.class), null)).willReturn(false);
|
||||
given(customWriter2.canWrite(ResolvableType.forClass(Object.class), null)).willReturn(true);
|
||||
|
||||
this.configurer.customCodecs().encoder(customEncoder1);
|
||||
this.configurer.customCodecs().encoder(customEncoder2);
|
||||
@@ -189,14 +189,14 @@ public class CodecConfigurerTests {
|
||||
Decoder<?> customDecoder1 = mock(Decoder.class);
|
||||
Decoder<?> customDecoder2 = mock(Decoder.class);
|
||||
|
||||
when(customDecoder1.canDecode(ResolvableType.forClass(Object.class), null)).thenReturn(false);
|
||||
when(customDecoder2.canDecode(ResolvableType.forClass(Object.class), null)).thenReturn(true);
|
||||
given(customDecoder1.canDecode(ResolvableType.forClass(Object.class), null)).willReturn(false);
|
||||
given(customDecoder2.canDecode(ResolvableType.forClass(Object.class), null)).willReturn(true);
|
||||
|
||||
HttpMessageReader<?> customReader1 = mock(HttpMessageReader.class);
|
||||
HttpMessageReader<?> customReader2 = mock(HttpMessageReader.class);
|
||||
|
||||
when(customReader1.canRead(ResolvableType.forClass(Object.class), null)).thenReturn(false);
|
||||
when(customReader2.canRead(ResolvableType.forClass(Object.class), null)).thenReturn(true);
|
||||
given(customReader1.canRead(ResolvableType.forClass(Object.class), null)).willReturn(false);
|
||||
given(customReader2.canRead(ResolvableType.forClass(Object.class), null)).willReturn(true);
|
||||
|
||||
this.configurer.customCodecs().decoder(customDecoder1);
|
||||
this.configurer.customCodecs().decoder(customDecoder2);
|
||||
@@ -220,14 +220,14 @@ public class CodecConfigurerTests {
|
||||
Encoder<?> customEncoder1 = mock(Encoder.class);
|
||||
Encoder<?> customEncoder2 = mock(Encoder.class);
|
||||
|
||||
when(customEncoder1.canEncode(ResolvableType.forClass(Object.class), null)).thenReturn(false);
|
||||
when(customEncoder2.canEncode(ResolvableType.forClass(Object.class), null)).thenReturn(true);
|
||||
given(customEncoder1.canEncode(ResolvableType.forClass(Object.class), null)).willReturn(false);
|
||||
given(customEncoder2.canEncode(ResolvableType.forClass(Object.class), null)).willReturn(true);
|
||||
|
||||
HttpMessageWriter<?> customWriter1 = mock(HttpMessageWriter.class);
|
||||
HttpMessageWriter<?> customWriter2 = mock(HttpMessageWriter.class);
|
||||
|
||||
when(customWriter1.canWrite(ResolvableType.forClass(Object.class), null)).thenReturn(false);
|
||||
when(customWriter2.canWrite(ResolvableType.forClass(Object.class), null)).thenReturn(true);
|
||||
given(customWriter1.canWrite(ResolvableType.forClass(Object.class), null)).willReturn(false);
|
||||
given(customWriter2.canWrite(ResolvableType.forClass(Object.class), null)).willReturn(true);
|
||||
|
||||
this.configurer.customCodecs().encoder(customEncoder1);
|
||||
this.configurer.customCodecs().encoder(customEncoder2);
|
||||
|
||||
@@ -41,7 +41,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -141,7 +141,7 @@ public class ResourceHttpMessageConverterTests {
|
||||
InputStream inputStream = mock(InputStream.class);
|
||||
given(resource.getInputStream()).willReturn(inputStream);
|
||||
given(inputStream.read(any())).willReturn(-1);
|
||||
doThrow(new NullPointerException()).when(inputStream).close();
|
||||
willThrow(new NullPointerException()).given(inputStream).close();
|
||||
converter.write(resource, MediaType.APPLICATION_OCTET_STREAM, outputMessage);
|
||||
|
||||
assertEquals(0, outputMessage.getHeaders().getContentLength());
|
||||
|
||||
@@ -30,8 +30,8 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.withSettings;
|
||||
|
||||
/**
|
||||
@@ -75,7 +75,7 @@ public class HttpComponentsHttpInvokerRequestExecutorTests {
|
||||
CloseableHttpClient client = mock(CloseableHttpClient.class,
|
||||
withSettings().extraInterfaces(Configurable.class));
|
||||
Configurable configurable = (Configurable) client;
|
||||
when(configurable.getConfig()).thenReturn(defaultConfig);
|
||||
given(configurable.getConfig()).willReturn(defaultConfig);
|
||||
|
||||
HttpComponentsHttpInvokerRequestExecutor executor =
|
||||
new HttpComponentsHttpInvokerRequestExecutor(client);
|
||||
@@ -98,7 +98,7 @@ public class HttpComponentsHttpInvokerRequestExecutorTests {
|
||||
CloseableHttpClient client = mock(CloseableHttpClient.class,
|
||||
withSettings().extraInterfaces(Configurable.class));
|
||||
Configurable configurable = (Configurable) client;
|
||||
when(configurable.getConfig()).thenReturn(defaultConfig);
|
||||
given(configurable.getConfig()).willReturn(defaultConfig);
|
||||
|
||||
HttpComponentsHttpInvokerRequestExecutor executor =
|
||||
new HttpComponentsHttpInvokerRequestExecutor(client);
|
||||
@@ -119,7 +119,7 @@ public class HttpComponentsHttpInvokerRequestExecutorTests {
|
||||
final CloseableHttpClient client = mock(CloseableHttpClient.class,
|
||||
withSettings().extraInterfaces(Configurable.class));
|
||||
Configurable configurable = (Configurable) client;
|
||||
when(configurable.getConfig()).thenReturn(defaultConfig);
|
||||
given(configurable.getConfig()).willReturn(defaultConfig);
|
||||
|
||||
HttpComponentsHttpInvokerRequestExecutor executor =
|
||||
new HttpComponentsHttpInvokerRequestExecutor() {
|
||||
@@ -139,7 +139,7 @@ public class HttpComponentsHttpInvokerRequestExecutorTests {
|
||||
// Update the Http client so that it returns an updated config
|
||||
RequestConfig updatedDefaultConfig = RequestConfig.custom()
|
||||
.setConnectTimeout(1234).build();
|
||||
when(configurable.getConfig()).thenReturn(updatedDefaultConfig);
|
||||
given(configurable.getConfig()).willReturn(updatedDefaultConfig);
|
||||
executor.setReadTimeout(7000);
|
||||
HttpPost httpPost2 = executor.createHttpPost(config);
|
||||
RequestConfig requestConfig2 = httpPost2.getConfig();
|
||||
@@ -165,7 +165,7 @@ public class HttpComponentsHttpInvokerRequestExecutorTests {
|
||||
|
||||
private HttpInvokerClientConfiguration mockHttpInvokerClientConfiguration(String serviceUrl) {
|
||||
HttpInvokerClientConfiguration config = mock(HttpInvokerClientConfiguration.class);
|
||||
when(config.getServiceUrl()).thenReturn(serviceUrl);
|
||||
given(config.getServiceUrl()).willReturn(serviceUrl);
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.web.context.request.async.CallableProcessingInterceptor.RESULT_NONE;
|
||||
|
||||
/**
|
||||
@@ -163,7 +162,7 @@ public class WebAsyncManagerTimeoutTests {
|
||||
Future future = mock(Future.class);
|
||||
|
||||
AsyncTaskExecutor executor = mock(AsyncTaskExecutor.class);
|
||||
when(executor.submit(any(Runnable.class))).thenReturn(future);
|
||||
given(executor.submit(any(Runnable.class))).willReturn(future);
|
||||
|
||||
this.asyncManager.setTaskExecutor(executor);
|
||||
this.asyncManager.startCallableProcessing(callable);
|
||||
|
||||
@@ -23,10 +23,10 @@ import org.springframework.core.MethodParameter;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link HandlerMethodReturnValueHandlerComposite}.
|
||||
@@ -53,7 +53,7 @@ public class HandlerMethodReturnValueHandlerCompositeTests {
|
||||
this.stringType = new MethodParameter(getClass().getDeclaredMethod("handleString"), -1);
|
||||
|
||||
this.integerHandler = mock(HandlerMethodReturnValueHandler.class);
|
||||
when(this.integerHandler.supportsReturnType(this.integerType)).thenReturn(true);
|
||||
given(this.integerHandler.supportsReturnType(this.integerType)).willReturn(true);
|
||||
|
||||
this.handlers = new HandlerMethodReturnValueHandlerComposite();
|
||||
this.handlers.addHandler(this.integerHandler);
|
||||
@@ -76,7 +76,7 @@ public class HandlerMethodReturnValueHandlerCompositeTests {
|
||||
@Test
|
||||
public void handleReturnValueWithMultipleHandlers() throws Exception {
|
||||
HandlerMethodReturnValueHandler anotherIntegerHandler = mock(HandlerMethodReturnValueHandler.class);
|
||||
when(anotherIntegerHandler.supportsReturnType(this.integerType)).thenReturn(true);
|
||||
given(anotherIntegerHandler.supportsReturnType(this.integerType)).willReturn(true);
|
||||
|
||||
this.handlers.handleReturnValue(55, this.integerType, this.mavContainer, null);
|
||||
|
||||
@@ -91,12 +91,12 @@ public class HandlerMethodReturnValueHandlerCompositeTests {
|
||||
MethodParameter promiseType = new MethodParameter(getClass().getDeclaredMethod("handlePromise"), -1);
|
||||
|
||||
HandlerMethodReturnValueHandler responseBodyHandler = mock(HandlerMethodReturnValueHandler.class);
|
||||
when(responseBodyHandler.supportsReturnType(promiseType)).thenReturn(true);
|
||||
given(responseBodyHandler.supportsReturnType(promiseType)).willReturn(true);
|
||||
this.handlers.addHandler(responseBodyHandler);
|
||||
|
||||
AsyncHandlerMethodReturnValueHandler promiseHandler = mock(AsyncHandlerMethodReturnValueHandler.class);
|
||||
when(promiseHandler.supportsReturnType(promiseType)).thenReturn(true);
|
||||
when(promiseHandler.isAsyncReturnValue(promise, promiseType)).thenReturn(true);
|
||||
given(promiseHandler.supportsReturnType(promiseType)).willReturn(true);
|
||||
given(promiseHandler.isAsyncReturnValue(promise, promiseType)).willReturn(true);
|
||||
this.handlers.addHandler(promiseHandler);
|
||||
|
||||
this.handlers.handleReturnValue(promise, promiseType, this.mavContainer, null);
|
||||
|
||||
@@ -40,9 +40,9 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DefaultWebSessionManager}.
|
||||
@@ -72,12 +72,12 @@ public class DefaultWebSessionManagerTests {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
when(this.createSession.save()).thenReturn(Mono.empty());
|
||||
when(this.createSession.getId()).thenReturn("create-session-id");
|
||||
when(this.updateSession.getId()).thenReturn("update-session-id");
|
||||
given(this.createSession.save()).willReturn(Mono.empty());
|
||||
given(this.createSession.getId()).willReturn("create-session-id");
|
||||
given(this.updateSession.getId()).willReturn("update-session-id");
|
||||
|
||||
when(this.sessionStore.createWebSession()).thenReturn(Mono.just(this.createSession));
|
||||
when(this.sessionStore.retrieveSession(this.updateSession.getId())).thenReturn(Mono.just(this.updateSession));
|
||||
given(this.sessionStore.createWebSession()).willReturn(Mono.just(this.createSession));
|
||||
given(this.sessionStore.retrieveSession(this.updateSession.getId())).willReturn(Mono.just(this.updateSession));
|
||||
|
||||
this.sessionManager = new DefaultWebSessionManager();
|
||||
this.sessionManager.setSessionIdResolver(this.sessionIdResolver);
|
||||
@@ -92,7 +92,7 @@ public class DefaultWebSessionManagerTests {
|
||||
@Test
|
||||
public void getSessionSaveWhenCreatedAndNotStartedThenNotSaved() {
|
||||
|
||||
when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(Collections.emptyList());
|
||||
given(this.sessionIdResolver.resolveSessionIds(this.exchange)).willReturn(Collections.emptyList());
|
||||
WebSession session = this.sessionManager.getSession(this.exchange).block();
|
||||
this.exchange.getResponse().setComplete().block();
|
||||
|
||||
@@ -106,12 +106,12 @@ public class DefaultWebSessionManagerTests {
|
||||
@Test
|
||||
public void getSessionSaveWhenCreatedAndStartedThenSavesAndSetsId() {
|
||||
|
||||
when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(Collections.emptyList());
|
||||
given(this.sessionIdResolver.resolveSessionIds(this.exchange)).willReturn(Collections.emptyList());
|
||||
WebSession session = this.sessionManager.getSession(this.exchange).block();
|
||||
assertSame(this.createSession, session);
|
||||
String sessionId = this.createSession.getId();
|
||||
|
||||
when(this.createSession.isStarted()).thenReturn(true);
|
||||
given(this.createSession.isStarted()).willReturn(true);
|
||||
this.exchange.getResponse().setComplete().block();
|
||||
|
||||
verify(this.sessionStore).createWebSession();
|
||||
@@ -123,7 +123,7 @@ public class DefaultWebSessionManagerTests {
|
||||
public void existingSession() {
|
||||
|
||||
String sessionId = this.updateSession.getId();
|
||||
when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(Collections.singletonList(sessionId));
|
||||
given(this.sessionIdResolver.resolveSessionIds(this.exchange)).willReturn(Collections.singletonList(sessionId));
|
||||
|
||||
WebSession actual = this.sessionManager.getSession(this.exchange).block();
|
||||
assertNotNull(actual);
|
||||
@@ -134,9 +134,9 @@ public class DefaultWebSessionManagerTests {
|
||||
public void multipleSessionIds() {
|
||||
|
||||
List<String> ids = Arrays.asList("not-this", "not-that", this.updateSession.getId());
|
||||
when(this.sessionStore.retrieveSession("not-this")).thenReturn(Mono.empty());
|
||||
when(this.sessionStore.retrieveSession("not-that")).thenReturn(Mono.empty());
|
||||
when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(ids);
|
||||
given(this.sessionStore.retrieveSession("not-this")).willReturn(Mono.empty());
|
||||
given(this.sessionStore.retrieveSession("not-that")).willReturn(Mono.empty());
|
||||
given(this.sessionIdResolver.resolveSessionIds(this.exchange)).willReturn(ids);
|
||||
WebSession actual = this.sessionManager.getSession(this.exchange).block();
|
||||
|
||||
assertNotNull(actual);
|
||||
|
||||
Reference in New Issue
Block a user