Replace use of ExpectedException rule with AssertJ
Closes gh-1032
This commit is contained in:
@@ -21,9 +21,7 @@ import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
|
||||
@@ -46,6 +44,8 @@ import org.springframework.web.socket.sockjs.client.SockJsClient;
|
||||
import org.springframework.web.socket.sockjs.client.Transport;
|
||||
import org.springframework.web.socket.sockjs.client.WebSocketTransport;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author Vedran Pavic
|
||||
@@ -61,9 +61,6 @@ public class ApplicationTests {
|
||||
public static GenericContainer redisContainer = new GenericContainer(DOCKER_IMAGE)
|
||||
.withExposedPorts(6379);
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private String port;
|
||||
|
||||
@@ -71,7 +68,7 @@ public class ApplicationTests {
|
||||
private WebSocketHandler webSocketHandler;
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
public void run() {
|
||||
List<Transport> transports = new ArrayList<>(2);
|
||||
transports.add(new WebSocketTransport(new StandardWebSocketClient()));
|
||||
transports.add(new RestTemplateXhrTransport());
|
||||
@@ -80,8 +77,8 @@ public class ApplicationTests {
|
||||
ListenableFuture<WebSocketSession> wsSession = sockJsClient.doHandshake(
|
||||
this.webSocketHandler, "ws://localhost:" + this.port + "/sockjs");
|
||||
|
||||
this.thrown.expect(ExecutionException.class);
|
||||
wsSession.get().sendMessage(new TextMessage("a"));
|
||||
assertThatThrownBy(() -> wsSession.get().sendMessage(new TextMessage("a")))
|
||||
.isInstanceOf(ExecutionException.class);
|
||||
}
|
||||
|
||||
static class Initializer
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2018 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.
|
||||
@@ -21,11 +21,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.beans.factory.UnsatisfiedDependencyException;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -42,18 +38,15 @@ import org.springframework.session.web.http.SessionRepositoryFilter;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* Tests for {@link SpringHttpSessionConfiguration}.
|
||||
*
|
||||
* @author Vedran Pavic
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SpringHttpSessionConfigurationTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
@After
|
||||
@@ -70,10 +63,9 @@ public class SpringHttpSessionConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void noSessionRepositoryConfiguration() {
|
||||
this.thrown.expect(UnsatisfiedDependencyException.class);
|
||||
this.thrown.expectMessage("org.springframework.session.SessionRepository");
|
||||
|
||||
registerAndRefresh(EmptyConfiguration.class);
|
||||
assertThatThrownBy(() -> registerAndRefresh(EmptyConfiguration.class))
|
||||
.isInstanceOf(UnsatisfiedDependencyException.class)
|
||||
.hasMessageContaining("org.springframework.session.SessionRepository");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2018 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,14 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -43,9 +42,6 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
*/
|
||||
public class SpringSessionRememberMeServicesTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private SpringSessionRememberMeServices rememberMeServices;
|
||||
|
||||
@Test
|
||||
@@ -71,10 +67,10 @@ public class SpringSessionRememberMeServicesTests {
|
||||
|
||||
@Test
|
||||
public void createWithNullParameter() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("rememberMeParameterName cannot be empty or null");
|
||||
this.rememberMeServices = new SpringSessionRememberMeServices();
|
||||
this.rememberMeServices.setRememberMeParameterName(null);
|
||||
assertThatThrownBy(() -> this.rememberMeServices.setRememberMeParameterName(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("rememberMeParameterName cannot be empty or null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,7 +110,8 @@ public class SpringSessionRememberMeServicesTests {
|
||||
this.rememberMeServices = new SpringSessionRememberMeServices();
|
||||
this.rememberMeServices.loginFail(request, response);
|
||||
verify(request, times(1)).getSession(eq(false));
|
||||
verify(session, times(1)).removeAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
|
||||
verify(session, times(1)).removeAttribute(
|
||||
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
|
||||
verifyZeroInteractions(request, response, session);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2018 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.
|
||||
@@ -21,9 +21,7 @@ import java.util.Base64;
|
||||
import javax.servlet.http.Cookie;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
@@ -50,9 +48,6 @@ public class DefaultCookieSerializerTests {
|
||||
return new Object[] { false, true };
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private boolean useBase64Encoding;
|
||||
|
||||
private String cookieName;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2018 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,14 @@ import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* Tests for {@link HeaderHttpSessionIdResolver}.
|
||||
@@ -37,9 +36,6 @@ public class HeaderHttpSessionIdResolverTests {
|
||||
|
||||
private static final String HEADER_X_AUTH_TOKEN = "X-Auth-Token";
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
private MockHttpServletResponse response;
|
||||
@@ -47,7 +43,7 @@ public class HeaderHttpSessionIdResolverTests {
|
||||
private HeaderHttpSessionIdResolver resolver;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
public void setup() {
|
||||
this.request = new MockHttpServletRequest();
|
||||
this.response = new MockHttpServletResponse();
|
||||
this.resolver = HeaderHttpSessionIdResolver.xAuthToken();
|
||||
@@ -78,9 +74,9 @@ public class HeaderHttpSessionIdResolverTests {
|
||||
|
||||
@Test
|
||||
public void createResolverWithNullHeaderName() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("headerName cannot be null");
|
||||
new HeaderHttpSessionIdResolver(null);
|
||||
assertThatThrownBy(() -> new HeaderHttpSessionIdResolver(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("headerName cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2018 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,9 +23,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -37,6 +35,7 @@ import org.springframework.session.MapSession;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -50,9 +49,6 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
*/
|
||||
public class ReactiveRedisOperationsSessionRepositoryTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ReactiveRedisOperations<String, Object> redisOperations = mock(
|
||||
ReactiveRedisOperations.class);
|
||||
@@ -68,17 +64,16 @@ public class ReactiveRedisOperationsSessionRepositoryTests {
|
||||
private ReactiveRedisOperationsSessionRepository repository;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
this.repository = new ReactiveRedisOperationsSessionRepository(
|
||||
this.redisOperations);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWithNullReactiveRedisOperations() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("sessionRedisOperations cannot be null");
|
||||
|
||||
new ReactiveRedisOperationsSessionRepository(null);
|
||||
assertThatThrownBy(() -> new ReactiveRedisOperationsSessionRepository(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("sessionRedisOperations cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,18 +86,16 @@ public class ReactiveRedisOperationsSessionRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void nullRedisKeyNamespace() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("namespace cannot be null or empty");
|
||||
|
||||
this.repository.setRedisKeyNamespace(null);
|
||||
assertThatThrownBy(() -> this.repository.setRedisKeyNamespace(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("namespace cannot be null or empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyRedisKeyNamespace() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("namespace cannot be null or empty");
|
||||
|
||||
this.repository.setRedisKeyNamespace("");
|
||||
assertThatThrownBy(() -> this.repository.setRedisKeyNamespace(""))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("namespace cannot be null or empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,10 +116,9 @@ public class ReactiveRedisOperationsSessionRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void nullRedisFlushMode() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("redisFlushMode cannot be null");
|
||||
|
||||
this.repository.setRedisFlushMode(null);
|
||||
assertThatThrownBy(() -> this.repository.setRedisFlushMode(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("redisFlushMode cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2018 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,9 +20,7 @@ import java.util.Properties;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -39,6 +37,7 @@ import org.springframework.session.data.redis.config.annotation.SpringSessionRed
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -54,9 +53,6 @@ public class RedisHttpSessionConfigurationTests {
|
||||
|
||||
private static final String CLEANUP_CRON_EXPRESSION = "0 0 * * * *";
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@Before
|
||||
@@ -188,10 +184,10 @@ public class RedisHttpSessionConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void multipleConnectionFactoryRedisConfig() {
|
||||
this.thrown.expect(BeanCreationException.class);
|
||||
this.thrown.expectMessage("expected single matching bean but found 2");
|
||||
|
||||
registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class);
|
||||
assertThatThrownBy(() -> registerAndRefresh(RedisConfig.class,
|
||||
MultipleConnectionFactoryRedisConfig.class))
|
||||
.isInstanceOf(BeanCreationException.class)
|
||||
.hasMessageContaining("expected single matching bean but found 2");
|
||||
}
|
||||
|
||||
private void registerAndRefresh(Class<?>... annotatedClasses) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2018 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.
|
||||
@@ -18,9 +18,7 @@ package org.springframework.session.data.redis.config.annotation.web.server;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -35,6 +33,7 @@ import org.springframework.session.data.redis.config.annotation.SpringSessionRed
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -48,9 +47,6 @@ public class RedisWebSessionConfigurationTests {
|
||||
|
||||
private static final int MAX_INACTIVE_INTERVAL_IN_SECONDS = 600;
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@Before
|
||||
@@ -179,10 +175,10 @@ public class RedisWebSessionConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void multipleConnectionFactoryRedisConfig() {
|
||||
this.thrown.expect(BeanCreationException.class);
|
||||
this.thrown.expectMessage("expected single matching bean but found 2");
|
||||
|
||||
registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class);
|
||||
assertThatThrownBy(() -> registerAndRefresh(RedisConfig.class,
|
||||
MultipleConnectionFactoryRedisConfig.class))
|
||||
.isInstanceOf(BeanCreationException.class)
|
||||
.hasMessageContaining("expected single matching bean but found 2");
|
||||
}
|
||||
|
||||
private void registerAndRefresh(Class<?>... annotatedClasses) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2018 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.
|
||||
@@ -29,12 +29,7 @@ import com.hazelcast.map.EntryProcessor;
|
||||
import com.hazelcast.map.listener.MapListener;
|
||||
import com.hazelcast.query.impl.predicates.EqualPredicate;
|
||||
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.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -44,12 +39,14 @@ import org.springframework.session.MapSession;
|
||||
import org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isA;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
@@ -60,19 +57,14 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
* @author Vedran Pavic
|
||||
* @author Aleksandar Stojsavljevic
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HazelcastSessionRepositoryTests {
|
||||
|
||||
private static final String SPRING_SECURITY_CONTEXT = "SPRING_SECURITY_CONTEXT";
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
private HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
|
||||
|
||||
@Mock
|
||||
private HazelcastInstance hazelcastInstance;
|
||||
|
||||
@Mock
|
||||
private IMap<String, MapSession> sessions;
|
||||
@SuppressWarnings("unchecked")
|
||||
private IMap<String, MapSession> sessions = mock(IMap.class);
|
||||
|
||||
private HazelcastSessionRepository repository;
|
||||
|
||||
@@ -86,14 +78,13 @@ public class HazelcastSessionRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void constructorNullHazelcastInstance() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("HazelcastInstance must not be null");
|
||||
|
||||
new HazelcastSessionRepository(null);
|
||||
assertThatThrownBy(() -> new HazelcastSessionRepository(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("HazelcastInstance must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionDefaultMaxInactiveInterval() throws Exception {
|
||||
public void createSessionDefaultMaxInactiveInterval() {
|
||||
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
|
||||
anyBoolean());
|
||||
|
||||
@@ -105,7 +96,7 @@ public class HazelcastSessionRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionCustomMaxInactiveInterval() throws Exception {
|
||||
public void createSessionCustomMaxInactiveInterval() {
|
||||
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
|
||||
anyBoolean());
|
||||
|
||||
|
||||
@@ -19,9 +19,7 @@ package org.springframework.session.hazelcast.config.annotation.web.http;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.core.IMap;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -34,6 +32,7 @@ import org.springframework.session.hazelcast.config.annotation.SpringSessionHaze
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -52,9 +51,6 @@ public class HazelcastHttpSessionConfigurationTests {
|
||||
|
||||
private static final HazelcastFlushMode HAZELCAST_FLUSH_MODE = HazelcastFlushMode.IMMEDIATE;
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
@After
|
||||
@@ -66,10 +62,10 @@ public class HazelcastHttpSessionConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void noHazelcastInstanceConfiguration() {
|
||||
this.thrown.expect(BeanCreationException.class);
|
||||
this.thrown.expectMessage("HazelcastInstance");
|
||||
|
||||
registerAndRefresh(NoHazelcastInstanceConfiguration.class);
|
||||
assertThatThrownBy(
|
||||
() -> registerAndRefresh(NoHazelcastInstanceConfiguration.class))
|
||||
.isInstanceOf(BeanCreationException.class)
|
||||
.hasMessageContaining("HazelcastInstance");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -210,10 +206,10 @@ public class HazelcastHttpSessionConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void multipleHazelcastInstanceConfiguration() {
|
||||
this.thrown.expect(BeanCreationException.class);
|
||||
this.thrown.expectMessage("expected single matching bean but found 2");
|
||||
|
||||
registerAndRefresh(MultipleHazelcastInstanceConfiguration.class);
|
||||
assertThatThrownBy(
|
||||
() -> registerAndRefresh(MultipleHazelcastInstanceConfiguration.class))
|
||||
.isInstanceOf(BeanCreationException.class)
|
||||
.hasMessageContaining("expected single matching bean but found 2");
|
||||
}
|
||||
|
||||
private void registerAndRefresh(Class<?>... annotatedClasses) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2018 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.
|
||||
@@ -24,13 +24,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
@@ -46,6 +41,7 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.AdditionalMatchers.and;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.contains;
|
||||
@@ -54,6 +50,7 @@ import static org.mockito.ArgumentMatchers.isA;
|
||||
import static org.mockito.ArgumentMatchers.startsWith;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
@@ -65,222 +62,194 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
* @author Vedran Pavic
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class JdbcOperationsSessionRepositoryTests {
|
||||
|
||||
private static final String SPRING_SECURITY_CONTEXT = "SPRING_SECURITY_CONTEXT";
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
private JdbcOperations jdbcOperations = mock(JdbcOperations.class);
|
||||
|
||||
@Mock
|
||||
private JdbcOperations jdbcOperations;
|
||||
|
||||
@Mock
|
||||
private PlatformTransactionManager transactionManager;
|
||||
private PlatformTransactionManager transactionManager = mock(PlatformTransactionManager.class);
|
||||
|
||||
private JdbcOperationsSessionRepository repository;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.repository = new JdbcOperationsSessionRepository(
|
||||
this.jdbcOperations, this.transactionManager);
|
||||
this.repository = new JdbcOperationsSessionRepository(this.jdbcOperations, this.transactionManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorNullJdbcOperations() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("JdbcOperations must not be null");
|
||||
|
||||
new JdbcOperationsSessionRepository((JdbcOperations) null, this.transactionManager);
|
||||
assertThatThrownBy(
|
||||
() -> new JdbcOperationsSessionRepository(null, this.transactionManager))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("JdbcOperations must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorNullTransactionManager() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Property 'transactionManager' is required");
|
||||
|
||||
new JdbcOperationsSessionRepository(this.jdbcOperations, null);
|
||||
assertThatThrownBy(
|
||||
() -> new JdbcOperationsSessionRepository(this.jdbcOperations, null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Property 'transactionManager' is required");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTableNameNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Table name must not be empty");
|
||||
|
||||
this.repository.setTableName(null);
|
||||
assertThatThrownBy(() -> this.repository.setTableName(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Table name must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTableNameEmpty() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Table name must not be empty");
|
||||
|
||||
this.repository.setTableName(" ");
|
||||
assertThatThrownBy(() -> this.repository.setTableName(" "))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Table name must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCreateSessionQueryNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setCreateSessionQuery(null);
|
||||
assertThatThrownBy(() -> this.repository.setCreateSessionQuery(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCreateSessionQueryEmpty() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setCreateSessionQuery(" ");
|
||||
assertThatThrownBy(() -> this.repository.setCreateSessionQuery(" "))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCreateSessionAttributeQueryNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setCreateSessionAttributeQuery(null);
|
||||
assertThatThrownBy(() -> this.repository.setCreateSessionAttributeQuery(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCreateSessionAttributeQueryEmpty() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setCreateSessionAttributeQuery(" ");
|
||||
assertThatThrownBy(() -> this.repository.setCreateSessionAttributeQuery(" "))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setGetSessionQueryNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setGetSessionQuery(null);
|
||||
assertThatThrownBy(() -> this.repository.setGetSessionQuery(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setGetSessionQueryEmpty() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setGetSessionQuery(" ");
|
||||
assertThatThrownBy(() -> this.repository.setGetSessionQuery(" "))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setUpdateSessionQueryNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setUpdateSessionQuery(null);
|
||||
assertThatThrownBy(() -> this.repository.setUpdateSessionQuery(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setUpdateSessionQueryEmpty() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setUpdateSessionQuery(" ");
|
||||
assertThatThrownBy(() -> this.repository.setUpdateSessionQuery(" "))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setUpdateSessionAttributeQueryNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setUpdateSessionAttributeQuery(null);
|
||||
assertThatThrownBy(() -> this.repository.setUpdateSessionAttributeQuery(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setUpdateSessionAttributeQueryEmpty() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setUpdateSessionAttributeQuery(" ");
|
||||
assertThatThrownBy(() -> this.repository.setUpdateSessionAttributeQuery(" "))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDeleteSessionAttributeQueryNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setDeleteSessionAttributeQuery(null);
|
||||
assertThatThrownBy(() -> this.repository.setDeleteSessionAttributeQuery(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDeleteSessionAttributeQueryEmpty() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setDeleteSessionAttributeQuery(" ");
|
||||
assertThatThrownBy(() -> this.repository.setDeleteSessionAttributeQuery(" "))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDeleteSessionQueryNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setDeleteSessionQuery(null);
|
||||
assertThatThrownBy(() -> this.repository.setDeleteSessionQuery(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDeleteSessionQueryEmpty() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setDeleteSessionQuery(" ");
|
||||
assertThatThrownBy(() -> this.repository.setDeleteSessionQuery(" "))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setListSessionsByPrincipalNameQueryNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setListSessionsByPrincipalNameQuery(null);
|
||||
assertThatThrownBy(
|
||||
() -> this.repository.setListSessionsByPrincipalNameQuery(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setListSessionsByPrincipalNameQueryEmpty() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setListSessionsByPrincipalNameQuery(" ");
|
||||
assertThatThrownBy(() -> this.repository.setListSessionsByPrincipalNameQuery(" "))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDeleteSessionsByLastAccessTimeQueryNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setDeleteSessionsByExpiryTimeQuery(null);
|
||||
assertThatThrownBy(() -> this.repository.setDeleteSessionsByExpiryTimeQuery(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDeleteSessionsByLastAccessTimeQueryEmpty() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Query must not be empty");
|
||||
|
||||
this.repository.setDeleteSessionsByExpiryTimeQuery(" ");
|
||||
assertThatThrownBy(() -> this.repository.setDeleteSessionsByExpiryTimeQuery(" "))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Query must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setLobHandlerNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("LobHandler must not be null");
|
||||
|
||||
this.repository.setLobHandler(null);
|
||||
assertThatThrownBy(() -> this.repository.setLobHandler(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("LobHandler must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setConversionServiceNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("conversionService must not be null");
|
||||
|
||||
this.repository.setConversionService(null);
|
||||
assertThatThrownBy(() -> this.repository.setConversionService(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("conversionService must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionDefaultMaxInactiveInterval() throws Exception {
|
||||
public void createSessionDefaultMaxInactiveInterval() {
|
||||
JdbcOperationsSessionRepository.JdbcSession session = this.repository
|
||||
.createSession();
|
||||
|
||||
@@ -291,7 +260,7 @@ public class JdbcOperationsSessionRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionCustomMaxInactiveInterval() throws Exception {
|
||||
public void createSessionCustomMaxInactiveInterval() {
|
||||
int interval = 1;
|
||||
this.repository.setDefaultMaxInactiveInterval(interval);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2018 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.
|
||||
@@ -19,9 +19,7 @@ package org.springframework.session.jdbc.config.annotation.web.http;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -39,6 +37,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -56,9 +55,6 @@ public class JdbcHttpSessionConfigurationTests {
|
||||
|
||||
private static final String CLEANUP_CRON_EXPRESSION = "0 0 * * * *";
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
@After
|
||||
@@ -70,11 +66,9 @@ public class JdbcHttpSessionConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void noDataSourceConfiguration() {
|
||||
this.thrown.expect(BeanCreationException.class);
|
||||
this.thrown.expectMessage(
|
||||
"expected at least 1 bean which qualifies as autowire candidate");
|
||||
|
||||
registerAndRefresh(NoDataSourceConfiguration.class);
|
||||
assertThatThrownBy(() -> registerAndRefresh(NoDataSourceConfiguration.class))
|
||||
.isInstanceOf(BeanCreationException.class).hasMessageContaining(
|
||||
"expected at least 1 bean which qualifies as autowire candidate");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,11 +224,10 @@ public class JdbcHttpSessionConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void multipleDataSourceConfiguration() {
|
||||
this.thrown.expect(BeanCreationException.class);
|
||||
this.thrown.expectMessage("expected single matching bean but found 2");
|
||||
|
||||
registerAndRefresh(DataSourceConfiguration.class,
|
||||
MultipleDataSourceConfiguration.class);
|
||||
assertThatThrownBy(() -> registerAndRefresh(DataSourceConfiguration.class,
|
||||
MultipleDataSourceConfiguration.class))
|
||||
.isInstanceOf(BeanCreationException.class)
|
||||
.hasMessageContaining("expected single matching bean but found 2");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user