Improve exception asserts
This commit is contained in:
@@ -36,7 +36,7 @@ import org.springframework.session.data.redis.ReactiveRedisOperationsSessionRepo
|
||||
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.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -80,9 +80,9 @@ public class ReactiveRedisOperationsSessionRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void constructorWithNullReactiveRedisOperations() {
|
||||
assertThatThrownBy(() -> new ReactiveRedisOperationsSessionRepository(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("sessionRedisOperations cannot be null");
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> new ReactiveRedisOperationsSessionRepository(null))
|
||||
.withMessageContaining("sessionRedisOperations cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,16 +95,16 @@ public class ReactiveRedisOperationsSessionRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void nullRedisKeyNamespace() {
|
||||
assertThatThrownBy(() -> this.repository.setRedisKeyNamespace(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("namespace cannot be null or empty");
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> this.repository.setRedisKeyNamespace(null))
|
||||
.withMessage("namespace cannot be null or empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyRedisKeyNamespace() {
|
||||
assertThatThrownBy(() -> this.repository.setRedisKeyNamespace(""))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("namespace cannot be null or empty");
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> this.repository.setRedisKeyNamespace(""))
|
||||
.withMessage("namespace cannot be null or empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,9 +125,9 @@ public class ReactiveRedisOperationsSessionRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void nullRedisFlushMode() {
|
||||
assertThatThrownBy(() -> this.repository.setRedisFlushMode(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("redisFlushMode cannot be null");
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> this.repository.setRedisFlushMode(null))
|
||||
.withMessage("redisFlushMode cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -59,7 +59,7 @@ import org.springframework.session.data.redis.RedisOperationsSessionRepository.R
|
||||
import org.springframework.session.events.AbstractSessionEvent;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -115,9 +115,9 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void setApplicationEventPublisherNull() {
|
||||
assertThatThrownBy(() -> this.redisRepository.setApplicationEventPublisher(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("applicationEventPublisher cannot be null");
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> this.redisRepository.setApplicationEventPublisher(null))
|
||||
.withMessage("applicationEventPublisher cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -841,9 +841,9 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void setRedisFlushModeNull() {
|
||||
assertThatThrownBy(() -> this.redisRepository.setRedisFlushMode(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("redisFlushMode cannot be null");
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> this.redisRepository.setRedisFlushMode(null))
|
||||
.withMessage("redisFlushMode cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -868,16 +868,16 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void setRedisKeyNamespaceNullNamespace() {
|
||||
assertThatThrownBy(() -> this.redisRepository.setRedisKeyNamespace(null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("namespace cannot be null or empty");
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> this.redisRepository.setRedisKeyNamespace(null))
|
||||
.withMessage("namespace cannot be null or empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setRedisKeyNamespaceEmptyNamespace() {
|
||||
assertThatThrownBy(() -> this.redisRepository.setRedisKeyNamespace(" "))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("namespace cannot be null or empty");
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> this.redisRepository.setRedisKeyNamespace(" "))
|
||||
.withMessage("namespace cannot be null or empty");
|
||||
}
|
||||
|
||||
@Test // gh-1120
|
||||
|
||||
@@ -37,7 +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.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -184,10 +184,10 @@ public class RedisHttpSessionConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void multipleConnectionFactoryRedisConfig() {
|
||||
assertThatThrownBy(() -> registerAndRefresh(RedisConfig.class,
|
||||
MultipleConnectionFactoryRedisConfig.class))
|
||||
.isInstanceOf(BeanCreationException.class)
|
||||
.hasMessageContaining("expected single matching bean but found 2");
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() -> registerAndRefresh(RedisConfig.class,
|
||||
MultipleConnectionFactoryRedisConfig.class))
|
||||
.withMessageContaining("expected single matching bean but found 2");
|
||||
}
|
||||
|
||||
private void registerAndRefresh(Class<?>... annotatedClasses) {
|
||||
|
||||
@@ -36,7 +36,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.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -194,10 +194,10 @@ public class RedisWebSessionConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void multipleConnectionFactoryRedisConfig() {
|
||||
assertThatThrownBy(() -> registerAndRefresh(RedisConfig.class,
|
||||
MultipleConnectionFactoryRedisConfig.class))
|
||||
.isInstanceOf(BeanCreationException.class)
|
||||
.hasMessageContaining("expected single matching bean but found 2");
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() -> registerAndRefresh(RedisConfig.class,
|
||||
MultipleConnectionFactoryRedisConfig.class))
|
||||
.withMessageContaining("expected single matching bean but found 2");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user