Browse Source

Upgrade to AssertJ 3.16

pull/25021/head
Sam Brannen 6 years ago
parent
commit
12e05280ad
  1. 2
      build.gradle
  2. 2
      integration-tests/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java
  3. 6
      spring-beans/src/test/java/org/springframework/beans/factory/support/security/CallbacksSecurityTests.java
  4. 14
      spring-context-support/src/test/java/org/springframework/validation/beanvalidation2/BeanValidationPostProcessorTests.java
  5. 24
      spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java
  6. 3
      spring-context/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java
  7. 6
      spring-context/src/test/java/org/springframework/context/config/ContextNamespaceHandlerTests.java
  8. 12
      spring-context/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java
  9. 14
      spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java
  10. 6
      spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java
  11. 14
      spring-context/src/test/java/org/springframework/validation/DataBinderTests.java
  12. 16
      spring-context/src/test/java/org/springframework/validation/beanvalidation/BeanValidationPostProcessorTests.java
  13. 13
      spring-core/src/test/java/org/springframework/core/testfixture/TestGroupTests.java
  14. 16
      spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java
  15. 6
      spring-expression/src/test/java/org/springframework/expression/spel/ConstructorInvocationTests.java
  16. 5
      spring-expression/src/test/java/org/springframework/expression/spel/MethodInvocationTests.java
  17. 11
      spring-jms/src/test/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapterTests.java
  18. 10
      spring-test/src/test/java/org/springframework/test/web/reactive/server/HeaderAssertionTests.java
  19. 7
      spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java
  20. 20
      spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java

2
build.gradle

@ -178,7 +178,7 @@ configure(allprojects) { project ->
dependency "org.testng:testng:7.1.0" dependency "org.testng:testng:7.1.0"
dependency "org.hamcrest:hamcrest:2.1" dependency "org.hamcrest:hamcrest:2.1"
dependency "org.awaitility:awaitility:3.1.6" dependency "org.awaitility:awaitility:3.1.6"
dependency "org.assertj:assertj-core:3.15.0" dependency "org.assertj:assertj-core:3.16.0"
dependencySet(group: 'org.xmlunit', version: '2.6.2') { dependencySet(group: 'org.xmlunit', version: '2.6.2') {
entry 'xmlunit-assertj' entry 'xmlunit-assertj'
entry('xmlunit-matchers') { entry('xmlunit-matchers') {

2
integration-tests/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java

@ -61,7 +61,7 @@ class ScheduledAndTransactionalAnnotationIntegrationTests {
ctx.register(Config.class, JdkProxyTxConfig.class, RepoConfigA.class); ctx.register(Config.class, JdkProxyTxConfig.class, RepoConfigA.class);
assertThatExceptionOfType(BeanCreationException.class) assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(ctx::refresh) .isThrownBy(ctx::refresh)
.satisfies(ex -> assertThat(ex.getRootCause()).isInstanceOf(IllegalStateException.class)); .withCauseInstanceOf(IllegalStateException.class);
} }
@Test @Test

6
spring-beans/src/test/java/org/springframework/beans/factory/support/security/CallbacksSecurityTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -360,14 +360,14 @@ public class CallbacksSecurityTests {
public void testCustomStaticFactoryMethod() throws Exception { public void testCustomStaticFactoryMethod() throws Exception {
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
beanFactory.getBean("custom-static-factory-method")) beanFactory.getBean("custom-static-factory-method"))
.satisfies(ex -> assertThat(ex.getMostSpecificCause()).isInstanceOf(SecurityException.class)); .satisfies(mostSpecificCauseOf(SecurityException.class));
} }
@Test @Test
public void testCustomInstanceFactoryMethod() throws Exception { public void testCustomInstanceFactoryMethod() throws Exception {
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
beanFactory.getBean("custom-factory-method")) beanFactory.getBean("custom-factory-method"))
.satisfies(ex -> assertThat(ex.getMostSpecificCause()).isInstanceOf(SecurityException.class)); .satisfies(mostSpecificCauseOf(SecurityException.class));
} }
@Test @Test

14
spring-context-support/src/test/java/org/springframework/validation/beanvalidation2/BeanValidationPostProcessorTests.java

@ -43,9 +43,10 @@ public class BeanValidationPostProcessorTests {
ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class)); ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
ac.registerBeanDefinition("bean", new RootBeanDefinition(NotNullConstrainedBean.class)); ac.registerBeanDefinition("bean", new RootBeanDefinition(NotNullConstrainedBean.class));
assertThatExceptionOfType(BeanCreationException.class).isThrownBy( assertThatExceptionOfType(BeanCreationException.class)
ac::refresh) .isThrownBy(ac::refresh)
.satisfies(ex -> assertThat(ex.getRootCause().getMessage()).contains("testBean", "invalid")); .havingRootCause()
.withMessageContainingAll("testBean", "invalid");
ac.close(); ac.close();
} }
@ -81,9 +82,10 @@ public class BeanValidationPostProcessorTests {
bd.getPropertyValues().add("testBean", new TestBean()); bd.getPropertyValues().add("testBean", new TestBean());
bd.getPropertyValues().add("stringValue", "s"); bd.getPropertyValues().add("stringValue", "s");
ac.registerBeanDefinition("bean", bd); ac.registerBeanDefinition("bean", bd);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy( assertThatExceptionOfType(BeanCreationException.class)
ac::refresh) .isThrownBy(ac::refresh)
.satisfies(ex -> assertThat(ex.getRootCause().getMessage()).contains("stringValue", "invalid")); .havingRootCause()
.withMessageContainingAll("stringValue", "invalid");
ac.close(); ac.close();
} }

24
spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java

@ -138,20 +138,22 @@ public class ProxyFactoryBeanTests {
private void testDoubleTargetSourceIsRejected(String name) { private void testDoubleTargetSourceIsRejected(String name) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(DBL_TARGETSOURCE_CONTEXT, CLASS)); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(DBL_TARGETSOURCE_CONTEXT, CLASS));
assertThatExceptionOfType(BeanCreationException.class).as("Should not allow TargetSource to be specified in interceptorNames as well as targetSource property").isThrownBy(() -> assertThatExceptionOfType(BeanCreationException.class).as("Should not allow TargetSource to be specified in interceptorNames as well as targetSource property")
bf.getBean(name)) .isThrownBy(() -> bf.getBean(name))
.withCauseInstanceOf(AopConfigException.class) .havingCause()
.satisfies(ex -> assertThat(ex.getCause().getMessage()).contains("TargetSource")); .isInstanceOf(AopConfigException.class)
.withMessageContaining("TargetSource");
} }
@Test @Test
public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected() { public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(NOTLAST_TARGETSOURCE_CONTEXT, CLASS)); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(NOTLAST_TARGETSOURCE_CONTEXT, CLASS));
assertThatExceptionOfType(BeanCreationException.class).as("TargetSource or non-advised object must be last in interceptorNames").isThrownBy(() -> assertThatExceptionOfType(BeanCreationException.class).as("TargetSource or non-advised object must be last in interceptorNames")
bf.getBean("targetSourceNotLast")) .isThrownBy(() -> bf.getBean("targetSourceNotLast"))
.withCauseInstanceOf(AopConfigException.class) .havingCause()
.satisfies(ex -> assertThat(ex.getCause().getMessage()).contains("interceptorNames")); .isInstanceOf(AopConfigException.class)
.withMessageContaining("interceptorNames");
} }
@Test @Test
@ -311,9 +313,9 @@ public class ProxyFactoryBeanTests {
assertThat(config.getAdvisors().length).as("Have correct advisor count").isEqualTo(2); assertThat(config.getAdvisors().length).as("Have correct advisor count").isEqualTo(2);
ITestBean tb1 = (ITestBean) factory.getBean("test1"); ITestBean tb1 = (ITestBean) factory.getBean("test1");
assertThatExceptionOfType(Exception.class).isThrownBy( assertThatExceptionOfType(Exception.class)
tb1::toString) .isThrownBy(tb1::toString)
.satisfies(thrown -> assertThat(thrown).isSameAs(ex)); .isSameAs(ex);
} }
/** /**

3
spring-context/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java

@ -126,7 +126,8 @@ public class CustomNamespaceHandlerTests {
assertThat(this.beanFactory.getType("debuggingTestBeanNoInstance")).isEqualTo(ApplicationListener.class); assertThat(this.beanFactory.getType("debuggingTestBeanNoInstance")).isEqualTo(ApplicationListener.class);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
this.beanFactory.getBean("debuggingTestBeanNoInstance")) this.beanFactory.getBean("debuggingTestBeanNoInstance"))
.satisfies(ex -> assertThat(ex.getRootCause()).isInstanceOf(BeanInstantiationException.class)); .havingRootCause()
.isInstanceOf(BeanInstantiationException.class);
} }
@Test @Test

6
spring-context/src/test/java/org/springframework/context/config/ContextNamespaceHandlerTests.java

@ -129,9 +129,9 @@ public class ContextNamespaceHandlerTests {
public void propertyPlaceholderLocationWithSystemPropertyMissing() { public void propertyPlaceholderLocationWithSystemPropertyMissing() {
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(() -> assertThatExceptionOfType(FatalBeanException.class).isThrownBy(() ->
new ClassPathXmlApplicationContext("contextNamespaceHandlerTests-location-placeholder.xml", getClass())) new ClassPathXmlApplicationContext("contextNamespaceHandlerTests-location-placeholder.xml", getClass()))
.satisfies(ex -> assertThat(ex.getRootCause()) .havingRootCause()
.isInstanceOf(IllegalArgumentException.class) .isInstanceOf(IllegalArgumentException.class)
.hasMessage("Could not resolve placeholder 'foo' in value \"${foo}\"")); .withMessage("Could not resolve placeholder 'foo' in value \"${foo}\"");
} }
@Test @Test

12
spring-context/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java

@ -72,9 +72,9 @@ public class LocalSlsbInvokerInterceptorTests {
// default resourceRef=false should cause this to fail, as java:/comp/env will not // default resourceRef=false should cause this to fail, as java:/comp/env will not
// automatically be added // automatically be added
si.setJndiTemplate(jt); si.setJndiTemplate(jt);
assertThatExceptionOfType(NamingException.class).isThrownBy( assertThatExceptionOfType(NamingException.class)
si::afterPropertiesSet) .isThrownBy(si::afterPropertiesSet)
.satisfies(ex -> assertThat(ex).isSameAs(nex)); .isSameAs(nex);
} }
@Test @Test
@ -132,9 +132,9 @@ public class LocalSlsbInvokerInterceptorTests {
pf.addAdvice(si); pf.addAdvice(si);
LocalInterfaceWithBusinessMethods target = (LocalInterfaceWithBusinessMethods) pf.getProxy(); LocalInterfaceWithBusinessMethods target = (LocalInterfaceWithBusinessMethods) pf.getProxy();
assertThatExceptionOfType(Exception.class).isThrownBy( assertThatExceptionOfType(Exception.class)
target::targetMethod) .isThrownBy(target::targetMethod)
.satisfies(ex -> assertThat(ex).isSameAs(expected)); .isSameAs(expected);
verify(mockContext).close(); verify(mockContext).close();
} }

14
spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -130,9 +130,9 @@ public class SimpleRemoteSlsbInvokerInterceptorTests {
// default resourceRef=false should cause this to fail, as java:/comp/env will not // default resourceRef=false should cause this to fail, as java:/comp/env will not
// automatically be added // automatically be added
si.setJndiTemplate(jt); si.setJndiTemplate(jt);
assertThatExceptionOfType(NamingException.class).isThrownBy( assertThatExceptionOfType(NamingException.class)
si::afterPropertiesSet) .isThrownBy(si::afterPropertiesSet)
.satisfies(ex -> assertThat(ex).isSameAs(nex)); .isSameAs(nex);
} }
@Test @Test
@ -308,9 +308,9 @@ public class SimpleRemoteSlsbInvokerInterceptorTests {
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName); SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class); RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
assertThatExceptionOfType(Exception.class).isThrownBy( assertThatExceptionOfType(Exception.class)
target::targetMethod) .isThrownBy(target::targetMethod)
.satisfies(ex -> assertThat(ex).isSameAs(expected)); .isSameAs(expected);
verify(mockContext).close(); verify(mockContext).close();
verify(ejb).remove(); verify(ejb).remove();
} }

6
spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java

@ -157,9 +157,9 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject(); MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
assertThat(Proxy.isProxyClass(mbm.getClass())).isTrue(); assertThat(Proxy.isProxyClass(mbm.getClass())).isTrue();
assertThatExceptionOfType(RemoteException.class).isThrownBy( assertThatExceptionOfType(RemoteException.class)
mbm::getValue) .isThrownBy(mbm::getValue)
.satisfies(ex -> assertThat(ex).isSameAs(rex)); .isSameAs(rex);
verify(myEjb).remove(); verify(myEjb).remove();
} }

14
spring-context/src/test/java/org/springframework/validation/DataBinderTests.java

@ -1887,9 +1887,10 @@ public class DataBinderTests {
MutablePropertyValues mpvs = new MutablePropertyValues(); MutablePropertyValues mpvs = new MutablePropertyValues();
mpvs.add("friends[256]", ""); mpvs.add("friends[256]", "");
assertThatExceptionOfType(InvalidPropertyException.class).isThrownBy(() -> assertThatExceptionOfType(InvalidPropertyException.class)
binder.bind(mpvs)) .isThrownBy(() -> binder.bind(mpvs))
.satisfies(ex -> assertThat(ex.getRootCause()).isInstanceOf(IndexOutOfBoundsException.class)); .havingRootCause()
.isInstanceOf(IndexOutOfBoundsException.class);
} }
@Test @Test
@ -1913,9 +1914,10 @@ public class DataBinderTests {
MutablePropertyValues mpvs = new MutablePropertyValues(); MutablePropertyValues mpvs = new MutablePropertyValues();
mpvs.add("friends[16]", ""); mpvs.add("friends[16]", "");
assertThatExceptionOfType(InvalidPropertyException.class).isThrownBy(() -> assertThatExceptionOfType(InvalidPropertyException.class)
binder.bind(mpvs)) .isThrownBy(() -> binder.bind(mpvs))
.satisfies(ex -> assertThat(ex.getRootCause()).isInstanceOf(IndexOutOfBoundsException.class)); .havingRootCause()
.isInstanceOf(IndexOutOfBoundsException.class);
} }
@Test @Test

16
spring-context/src/test/java/org/springframework/validation/beanvalidation/BeanValidationPostProcessorTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,9 +45,10 @@ public class BeanValidationPostProcessorTests {
ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class)); ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
ac.registerBeanDefinition("bean", new RootBeanDefinition(NotNullConstrainedBean.class)); ac.registerBeanDefinition("bean", new RootBeanDefinition(NotNullConstrainedBean.class));
assertThatExceptionOfType(BeanCreationException.class).isThrownBy( assertThatExceptionOfType(BeanCreationException.class)
ac::refresh) .isThrownBy(ac::refresh)
.satisfies(ex -> assertThat(ex.getRootCause().getMessage()).contains("testBean").contains("invalid")); .havingRootCause()
.withMessageContainingAll("testBean", "invalid");
ac.close(); ac.close();
} }
@ -97,9 +98,10 @@ public class BeanValidationPostProcessorTests {
bd.getPropertyValues().add("testBean", new TestBean()); bd.getPropertyValues().add("testBean", new TestBean());
bd.getPropertyValues().add("stringValue", "s"); bd.getPropertyValues().add("stringValue", "s");
ac.registerBeanDefinition("bean", bd); ac.registerBeanDefinition("bean", bd);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> assertThatExceptionOfType(BeanCreationException.class)
ac.refresh()) .isThrownBy(() -> ac.refresh())
.satisfies(ex -> assertThat(ex.getRootCause().getMessage()).contains("stringValue").contains("invalid")); .havingRootCause()
.withMessageContainingAll("stringValue", "invalid");
ac.close(); ac.close();
} }

13
spring-core/src/test/java/org/springframework/core/testfixture/TestGroupTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,7 +25,6 @@ import org.junit.jupiter.api.Test;
import org.opentest4j.TestAbortedException; import org.opentest4j.TestAbortedException;
import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.joining;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
@ -104,11 +103,11 @@ class TestGroupTests {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> assumeGroup(LONG_RUNNING)) .isThrownBy(() -> assumeGroup(LONG_RUNNING))
.withMessageStartingWith("Failed to parse '" + TEST_GROUPS_SYSTEM_PROPERTY + "' system property: ") .withMessageStartingWith("Failed to parse '" + TEST_GROUPS_SYSTEM_PROPERTY + "' system property: ")
.withCauseInstanceOf(IllegalArgumentException.class) .havingCause()
.satisfies(ex -> .isInstanceOf(IllegalArgumentException.class)
assertThat(ex.getCause().getMessage()).isEqualTo( .withMessage(
"Unable to find test group 'bogus' when parsing testGroups value: '" + testGroups + "Unable to find test group 'bogus' when parsing testGroups value: '" + testGroups +
"'. Available groups include: [LONG_RUNNING,PERFORMANCE]")); "'. Available groups include: [LONG_RUNNING,PERFORMANCE]");
} }
private void setTestGroups(TestGroup... testGroups) { private void setTestGroups(TestGroup... testGroups) {

16
spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -79,12 +79,14 @@ class ListenableFutureTaskTests {
}); });
task.run(); task.run();
assertThatExceptionOfType(ExecutionException.class).isThrownBy( assertThatExceptionOfType(ExecutionException.class)
task::get) .isThrownBy(task::get)
.satisfies(ex -> assertThat(ex.getCause().getMessage()).isEqualTo(s)); .havingCause()
assertThatExceptionOfType(ExecutionException.class).isThrownBy( .withMessage(s);
task.completable()::get) assertThatExceptionOfType(ExecutionException.class)
.satisfies(ex -> assertThat(ex.getCause().getMessage()).isEqualTo(s)); .isThrownBy(task.completable()::get)
.havingCause()
.withMessage(s);
} }
@Test @Test

6
spring-expression/src/test/java/org/springframework/expression/spel/ConstructorInvocationTests.java

@ -139,9 +139,9 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
// 1 will make it throw a RuntimeException - SpEL will let this through // 1 will make it throw a RuntimeException - SpEL will let this through
eContext.setVariable("bar", 1); eContext.setVariable("bar", 1);
assertThatExceptionOfType(Exception.class).isThrownBy(() -> assertThatExceptionOfType(Exception.class)
expr.getValue(eContext)) .isThrownBy(() -> expr.getValue(eContext))
.satisfies(ex -> assertThat(ex).isNotInstanceOf(SpelEvaluationException.class)); .isNotInstanceOf(SpelEvaluationException.class);
// A problem occurred whilst attempting to construct an object of type // A problem occurred whilst attempting to construct an object of type
// 'org.springframework.expression.spel.ConstructorInvocationTests$Tester' // 'org.springframework.expression.spel.ConstructorInvocationTests$Tester'
// using arguments '(java.lang.Integer)' // using arguments '(java.lang.Integer)'

5
spring-expression/src/test/java/org/springframework/expression/spel/MethodInvocationTests.java

@ -148,8 +148,9 @@ public class MethodInvocationTests extends AbstractExpressionTests {
Expression expr = parser.parseExpression("throwException(#bar)"); Expression expr = parser.parseExpression("throwException(#bar)");
context.setVariable("bar", 2); context.setVariable("bar", 2);
assertThatExceptionOfType(Exception.class).isThrownBy(() -> expr.getValue(context)) assertThatExceptionOfType(Exception.class)
.satisfies(ex -> assertThat(ex).isNotInstanceOf(SpelEvaluationException.class)); .isThrownBy(() -> expr.getValue(context))
.isNotInstanceOf(SpelEvaluationException.class);
} }
@Test @Test

11
spring-jms/src/test/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapterTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -100,10 +100,11 @@ public class MessagingMessageListenerAdapterTests {
javax.jms.Message message = new StubTextMessage("foo"); javax.jms.Message message = new StubTextMessage("foo");
Session session = mock(Session.class); Session session = mock(Session.class);
MessagingMessageListenerAdapter listener = getSimpleInstance("fail", String.class); MessagingMessageListenerAdapter listener = getSimpleInstance("fail", String.class);
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() -> assertThatExceptionOfType(ListenerExecutionFailedException.class)
listener.onMessage(message, session)) .isThrownBy(() -> listener.onMessage(message, session))
.withCauseExactlyInstanceOf(IllegalArgumentException.class) .havingCause()
.satisfies(ex -> assertThat(ex.getCause().getMessage()).isEqualTo("Expected test exception")); .isExactlyInstanceOf(IllegalArgumentException.class)
.withMessage("Expected test exception");
} }
@Test @Test

10
spring-test/src/test/java/org/springframework/test/web/reactive/server/HeaderAssertionTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -154,10 +154,10 @@ public class HeaderAssertionTests {
assertions.contentTypeCompatibleWith(MediaType.parseMediaType("application/*")); assertions.contentTypeCompatibleWith(MediaType.parseMediaType("application/*"));
// MediaTypes not compatible // MediaTypes not compatible
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThatExceptionOfType(AssertionError.class)
assertions.contentTypeCompatibleWith(MediaType.TEXT_XML)) .isThrownBy(() -> assertions.contentTypeCompatibleWith(MediaType.TEXT_XML))
.satisfies(ex -> assertThat(ex.getCause()).hasMessage("Response header " + .havingCause()
"'Content-Type'=[application/xml] is not compatible with [text/xml]")); .withMessage("Response header 'Content-Type'=[application/xml] is not compatible with [text/xml]");
} }
@Test @Test

7
spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java

@ -74,8 +74,8 @@ public class DefaultResponseErrorHandlerTests {
assertThatExceptionOfType(HttpClientErrorException.class) assertThatExceptionOfType(HttpClientErrorException.class)
.isThrownBy(() -> handler.handleError(response)) .isThrownBy(() -> handler.handleError(response))
.satisfies(ex -> assertThat(ex.getResponseHeaders()).isSameAs(headers)) .withMessage("404 Not Found: [Hello World]")
.satisfies(ex -> assertThat(ex.getMessage()).isEqualTo("404 Not Found: [Hello World]")); .satisfies(ex -> assertThat(ex.getResponseHeaders()).isSameAs(headers));
} }
@Test @Test
@ -92,8 +92,7 @@ public class DefaultResponseErrorHandlerTests {
assertThatExceptionOfType(HttpClientErrorException.class) assertThatExceptionOfType(HttpClientErrorException.class)
.isThrownBy(() -> handler.handleError(response)) .isThrownBy(() -> handler.handleError(response))
.satisfies(ex -> assertThat(ex.getMessage()).isEqualTo( .withMessage("404 Not Found: [" + bodyGenerator.apply(200) + "... (500 bytes)]");
"404 Not Found: [" + bodyGenerator.apply(200) + "... (500 bytes)]"));
} }
@Test @Test

20
spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -273,20 +273,22 @@ public class ContextLoaderTests {
MockServletContext sc = new MockServletContext(""); MockServletContext sc = new MockServletContext("");
ServletContextListener listener = new ContextLoaderListener(); ServletContextListener listener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(sc); ServletContextEvent event = new ServletContextEvent(sc);
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> assertThatExceptionOfType(BeanDefinitionStoreException.class)
listener.contextInitialized(event)) .isThrownBy(() -> listener.contextInitialized(event))
.withCauseInstanceOf(IOException.class) .havingCause()
.satisfies(ex -> assertThat(ex.getCause()).hasMessageContaining("/WEB-INF/applicationContext.xml")); .isInstanceOf(IOException.class)
.withMessageContaining("/WEB-INF/applicationContext.xml");
} }
@Test @Test
public void testFrameworkServletWithDefaultLocation() throws Exception { public void testFrameworkServletWithDefaultLocation() throws Exception {
DispatcherServlet servlet = new DispatcherServlet(); DispatcherServlet servlet = new DispatcherServlet();
servlet.setContextClass(XmlWebApplicationContext.class); servlet.setContextClass(XmlWebApplicationContext.class);
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> assertThatExceptionOfType(BeanDefinitionStoreException.class)
servlet.init(new MockServletConfig(new MockServletContext(""), "test"))) .isThrownBy(() -> servlet.init(new MockServletConfig(new MockServletContext(""), "test")))
.withCauseInstanceOf(IOException.class) .havingCause()
.satisfies(ex -> assertThat(ex.getCause()).hasMessageContaining("/WEB-INF/test-servlet.xml")); .isInstanceOf(IOException.class)
.withMessageContaining("/WEB-INF/test-servlet.xml");
} }
@Test @Test

Loading…
Cancel
Save