From 12e05280adef6a9fadd1c782bab832f8c10b0bfc Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 6 May 2020 14:34:13 +0200 Subject: [PATCH] Upgrade to AssertJ 3.16 --- build.gradle | 2 +- ...ansactionalAnnotationIntegrationTests.java | 2 +- .../security/CallbacksSecurityTests.java | 6 ++--- .../BeanValidationPostProcessorTests.java | 14 ++++++----- .../aop/framework/ProxyFactoryBeanTests.java | 24 ++++++++++--------- .../support/CustomNamespaceHandlerTests.java | 3 ++- .../config/ContextNamespaceHandlerTests.java | 6 ++--- .../LocalSlsbInvokerInterceptorTests.java | 12 +++++----- ...mpleRemoteSlsbInvokerInterceptorTests.java | 14 +++++------ ...StatelessSessionProxyFactoryBeanTests.java | 6 ++--- .../validation/DataBinderTests.java | 14 ++++++----- .../BeanValidationPostProcessorTests.java | 16 +++++++------ .../core/testfixture/TestGroupTests.java | 13 +++++----- .../concurrent/ListenableFutureTaskTests.java | 16 +++++++------ .../spel/ConstructorInvocationTests.java | 6 ++--- .../spel/MethodInvocationTests.java | 5 ++-- .../MessagingMessageListenerAdapterTests.java | 11 +++++---- .../reactive/server/HeaderAssertionTests.java | 10 ++++---- .../DefaultResponseErrorHandlerTests.java | 7 +++--- .../web/context/ContextLoaderTests.java | 20 +++++++++------- 20 files changed, 110 insertions(+), 97 deletions(-) diff --git a/build.gradle b/build.gradle index 64018275c31..15d4bf9cbec 100644 --- a/build.gradle +++ b/build.gradle @@ -178,7 +178,7 @@ configure(allprojects) { project -> dependency "org.testng:testng:7.1.0" dependency "org.hamcrest:hamcrest:2.1" 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') { entry 'xmlunit-assertj' entry('xmlunit-matchers') { diff --git a/integration-tests/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java b/integration-tests/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java index 8b49193b863..fe0c23a74a7 100644 --- a/integration-tests/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java +++ b/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); assertThatExceptionOfType(BeanCreationException.class) .isThrownBy(ctx::refresh) - .satisfies(ex -> assertThat(ex.getRootCause()).isInstanceOf(IllegalStateException.class)); + .withCauseInstanceOf(IllegalStateException.class); } @Test diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/security/CallbacksSecurityTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/security/CallbacksSecurityTests.java index 84cb04da599..368e0b66472 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/security/CallbacksSecurityTests.java +++ b/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"); * you may not use this file except in compliance with the License. @@ -360,14 +360,14 @@ public class CallbacksSecurityTests { public void testCustomStaticFactoryMethod() throws Exception { assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> beanFactory.getBean("custom-static-factory-method")) - .satisfies(ex -> assertThat(ex.getMostSpecificCause()).isInstanceOf(SecurityException.class)); + .satisfies(mostSpecificCauseOf(SecurityException.class)); } @Test public void testCustomInstanceFactoryMethod() throws Exception { assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> beanFactory.getBean("custom-factory-method")) - .satisfies(ex -> assertThat(ex.getMostSpecificCause()).isInstanceOf(SecurityException.class)); + .satisfies(mostSpecificCauseOf(SecurityException.class)); } @Test diff --git a/spring-context-support/src/test/java/org/springframework/validation/beanvalidation2/BeanValidationPostProcessorTests.java b/spring-context-support/src/test/java/org/springframework/validation/beanvalidation2/BeanValidationPostProcessorTests.java index 4d014707077..c5da1e4b152 100644 --- a/spring-context-support/src/test/java/org/springframework/validation/beanvalidation2/BeanValidationPostProcessorTests.java +++ b/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("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ac.registerBeanDefinition("bean", new RootBeanDefinition(NotNullConstrainedBean.class)); - assertThatExceptionOfType(BeanCreationException.class).isThrownBy( - ac::refresh) - .satisfies(ex -> assertThat(ex.getRootCause().getMessage()).contains("testBean", "invalid")); + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(ac::refresh) + .havingRootCause() + .withMessageContainingAll("testBean", "invalid"); ac.close(); } @@ -81,9 +82,10 @@ public class BeanValidationPostProcessorTests { bd.getPropertyValues().add("testBean", new TestBean()); bd.getPropertyValues().add("stringValue", "s"); ac.registerBeanDefinition("bean", bd); - assertThatExceptionOfType(BeanCreationException.class).isThrownBy( - ac::refresh) - .satisfies(ex -> assertThat(ex.getRootCause().getMessage()).contains("stringValue", "invalid")); + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(ac::refresh) + .havingRootCause() + .withMessageContainingAll("stringValue", "invalid"); ac.close(); } diff --git a/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java index f527b6019ed..021a8a70eee 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java @@ -138,20 +138,22 @@ public class ProxyFactoryBeanTests { private void testDoubleTargetSourceIsRejected(String name) { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); 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(() -> - bf.getBean(name)) - .withCauseInstanceOf(AopConfigException.class) - .satisfies(ex -> assertThat(ex.getCause().getMessage()).contains("TargetSource")); + assertThatExceptionOfType(BeanCreationException.class).as("Should not allow TargetSource to be specified in interceptorNames as well as targetSource property") + .isThrownBy(() -> bf.getBean(name)) + .havingCause() + .isInstanceOf(AopConfigException.class) + .withMessageContaining("TargetSource"); } @Test public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); 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(() -> - bf.getBean("targetSourceNotLast")) - .withCauseInstanceOf(AopConfigException.class) - .satisfies(ex -> assertThat(ex.getCause().getMessage()).contains("interceptorNames")); + assertThatExceptionOfType(BeanCreationException.class).as("TargetSource or non-advised object must be last in interceptorNames") + .isThrownBy(() -> bf.getBean("targetSourceNotLast")) + .havingCause() + .isInstanceOf(AopConfigException.class) + .withMessageContaining("interceptorNames"); } @Test @@ -311,9 +313,9 @@ public class ProxyFactoryBeanTests { assertThat(config.getAdvisors().length).as("Have correct advisor count").isEqualTo(2); ITestBean tb1 = (ITestBean) factory.getBean("test1"); - assertThatExceptionOfType(Exception.class).isThrownBy( - tb1::toString) - .satisfies(thrown -> assertThat(thrown).isSameAs(ex)); + assertThatExceptionOfType(Exception.class) + .isThrownBy(tb1::toString) + .isSameAs(ex); } /** diff --git a/spring-context/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java b/spring-context/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java index b3306e23010..7b03b3706fd 100644 --- a/spring-context/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java +++ b/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); assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> this.beanFactory.getBean("debuggingTestBeanNoInstance")) - .satisfies(ex -> assertThat(ex.getRootCause()).isInstanceOf(BeanInstantiationException.class)); + .havingRootCause() + .isInstanceOf(BeanInstantiationException.class); } @Test diff --git a/spring-context/src/test/java/org/springframework/context/config/ContextNamespaceHandlerTests.java b/spring-context/src/test/java/org/springframework/context/config/ContextNamespaceHandlerTests.java index b6949845a99..c7e6f173fb9 100644 --- a/spring-context/src/test/java/org/springframework/context/config/ContextNamespaceHandlerTests.java +++ b/spring-context/src/test/java/org/springframework/context/config/ContextNamespaceHandlerTests.java @@ -129,9 +129,9 @@ public class ContextNamespaceHandlerTests { public void propertyPlaceholderLocationWithSystemPropertyMissing() { assertThatExceptionOfType(FatalBeanException.class).isThrownBy(() -> new ClassPathXmlApplicationContext("contextNamespaceHandlerTests-location-placeholder.xml", getClass())) - .satisfies(ex -> assertThat(ex.getRootCause()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Could not resolve placeholder 'foo' in value \"${foo}\"")); + .havingRootCause() + .isInstanceOf(IllegalArgumentException.class) + .withMessage("Could not resolve placeholder 'foo' in value \"${foo}\""); } @Test diff --git a/spring-context/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java b/spring-context/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java index 127dd832779..f3489771175 100644 --- a/spring-context/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java +++ b/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 // automatically be added si.setJndiTemplate(jt); - assertThatExceptionOfType(NamingException.class).isThrownBy( - si::afterPropertiesSet) - .satisfies(ex -> assertThat(ex).isSameAs(nex)); + assertThatExceptionOfType(NamingException.class) + .isThrownBy(si::afterPropertiesSet) + .isSameAs(nex); } @Test @@ -132,9 +132,9 @@ public class LocalSlsbInvokerInterceptorTests { pf.addAdvice(si); LocalInterfaceWithBusinessMethods target = (LocalInterfaceWithBusinessMethods) pf.getProxy(); - assertThatExceptionOfType(Exception.class).isThrownBy( - target::targetMethod) - .satisfies(ex -> assertThat(ex).isSameAs(expected)); + assertThatExceptionOfType(Exception.class) + .isThrownBy(target::targetMethod) + .isSameAs(expected); verify(mockContext).close(); } diff --git a/spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java b/spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java index f6289ad2b5e..3397cb05ee0 100644 --- a/spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java +++ b/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"); * 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 // automatically be added si.setJndiTemplate(jt); - assertThatExceptionOfType(NamingException.class).isThrownBy( - si::afterPropertiesSet) - .satisfies(ex -> assertThat(ex).isSameAs(nex)); + assertThatExceptionOfType(NamingException.class) + .isThrownBy(si::afterPropertiesSet) + .isSameAs(nex); } @Test @@ -308,9 +308,9 @@ public class SimpleRemoteSlsbInvokerInterceptorTests { SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName); RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class); - assertThatExceptionOfType(Exception.class).isThrownBy( - target::targetMethod) - .satisfies(ex -> assertThat(ex).isSameAs(expected)); + assertThatExceptionOfType(Exception.class) + .isThrownBy(target::targetMethod) + .isSameAs(expected); verify(mockContext).close(); verify(ejb).remove(); } diff --git a/spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java index 38c5f9de350..cc5dd44b693 100644 --- a/spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java +++ b/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(); assertThat(Proxy.isProxyClass(mbm.getClass())).isTrue(); - assertThatExceptionOfType(RemoteException.class).isThrownBy( - mbm::getValue) - .satisfies(ex -> assertThat(ex).isSameAs(rex)); + assertThatExceptionOfType(RemoteException.class) + .isThrownBy(mbm::getValue) + .isSameAs(rex); verify(myEjb).remove(); } diff --git a/spring-context/src/test/java/org/springframework/validation/DataBinderTests.java b/spring-context/src/test/java/org/springframework/validation/DataBinderTests.java index 9f38af21371..6c24ef22d2b 100644 --- a/spring-context/src/test/java/org/springframework/validation/DataBinderTests.java +++ b/spring-context/src/test/java/org/springframework/validation/DataBinderTests.java @@ -1887,9 +1887,10 @@ public class DataBinderTests { MutablePropertyValues mpvs = new MutablePropertyValues(); mpvs.add("friends[256]", ""); - assertThatExceptionOfType(InvalidPropertyException.class).isThrownBy(() -> - binder.bind(mpvs)) - .satisfies(ex -> assertThat(ex.getRootCause()).isInstanceOf(IndexOutOfBoundsException.class)); + assertThatExceptionOfType(InvalidPropertyException.class) + .isThrownBy(() -> binder.bind(mpvs)) + .havingRootCause() + .isInstanceOf(IndexOutOfBoundsException.class); } @Test @@ -1913,9 +1914,10 @@ public class DataBinderTests { MutablePropertyValues mpvs = new MutablePropertyValues(); mpvs.add("friends[16]", ""); - assertThatExceptionOfType(InvalidPropertyException.class).isThrownBy(() -> - binder.bind(mpvs)) - .satisfies(ex -> assertThat(ex.getRootCause()).isInstanceOf(IndexOutOfBoundsException.class)); + assertThatExceptionOfType(InvalidPropertyException.class) + .isThrownBy(() -> binder.bind(mpvs)) + .havingRootCause() + .isInstanceOf(IndexOutOfBoundsException.class); } @Test diff --git a/spring-context/src/test/java/org/springframework/validation/beanvalidation/BeanValidationPostProcessorTests.java b/spring-context/src/test/java/org/springframework/validation/beanvalidation/BeanValidationPostProcessorTests.java index 1af2d6dd3ba..4ec8ce0c59d 100644 --- a/spring-context/src/test/java/org/springframework/validation/beanvalidation/BeanValidationPostProcessorTests.java +++ b/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"); * 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("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ac.registerBeanDefinition("bean", new RootBeanDefinition(NotNullConstrainedBean.class)); - assertThatExceptionOfType(BeanCreationException.class).isThrownBy( - ac::refresh) - .satisfies(ex -> assertThat(ex.getRootCause().getMessage()).contains("testBean").contains("invalid")); + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(ac::refresh) + .havingRootCause() + .withMessageContainingAll("testBean", "invalid"); ac.close(); } @@ -97,9 +98,10 @@ public class BeanValidationPostProcessorTests { bd.getPropertyValues().add("testBean", new TestBean()); bd.getPropertyValues().add("stringValue", "s"); ac.registerBeanDefinition("bean", bd); - assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> - ac.refresh()) - .satisfies(ex -> assertThat(ex.getRootCause().getMessage()).contains("stringValue").contains("invalid")); + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> ac.refresh()) + .havingRootCause() + .withMessageContainingAll("stringValue", "invalid"); ac.close(); } diff --git a/spring-core/src/test/java/org/springframework/core/testfixture/TestGroupTests.java b/spring-core/src/test/java/org/springframework/core/testfixture/TestGroupTests.java index af9d829dae7..d9efa4fc430 100644 --- a/spring-core/src/test/java/org/springframework/core/testfixture/TestGroupTests.java +++ b/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"); * 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 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.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; @@ -104,11 +103,11 @@ class TestGroupTests { assertThatIllegalStateException() .isThrownBy(() -> assumeGroup(LONG_RUNNING)) .withMessageStartingWith("Failed to parse '" + TEST_GROUPS_SYSTEM_PROPERTY + "' system property: ") - .withCauseInstanceOf(IllegalArgumentException.class) - .satisfies(ex -> - assertThat(ex.getCause().getMessage()).isEqualTo( - "Unable to find test group 'bogus' when parsing testGroups value: '" + testGroups + - "'. Available groups include: [LONG_RUNNING,PERFORMANCE]")); + .havingCause() + .isInstanceOf(IllegalArgumentException.class) + .withMessage( + "Unable to find test group 'bogus' when parsing testGroups value: '" + testGroups + + "'. Available groups include: [LONG_RUNNING,PERFORMANCE]"); } private void setTestGroups(TestGroup... testGroups) { diff --git a/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java b/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java index 4b832148508..469a355c151 100644 --- a/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java +++ b/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"); * you may not use this file except in compliance with the License. @@ -79,12 +79,14 @@ class ListenableFutureTaskTests { }); task.run(); - assertThatExceptionOfType(ExecutionException.class).isThrownBy( - task::get) - .satisfies(ex -> assertThat(ex.getCause().getMessage()).isEqualTo(s)); - assertThatExceptionOfType(ExecutionException.class).isThrownBy( - task.completable()::get) - .satisfies(ex -> assertThat(ex.getCause().getMessage()).isEqualTo(s)); + assertThatExceptionOfType(ExecutionException.class) + .isThrownBy(task::get) + .havingCause() + .withMessage(s); + assertThatExceptionOfType(ExecutionException.class) + .isThrownBy(task.completable()::get) + .havingCause() + .withMessage(s); } @Test diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/ConstructorInvocationTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/ConstructorInvocationTests.java index a37364afc8d..89ea09bdc64 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/ConstructorInvocationTests.java +++ b/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 eContext.setVariable("bar", 1); - assertThatExceptionOfType(Exception.class).isThrownBy(() -> - expr.getValue(eContext)) - .satisfies(ex -> assertThat(ex).isNotInstanceOf(SpelEvaluationException.class)); + assertThatExceptionOfType(Exception.class) + .isThrownBy(() -> expr.getValue(eContext)) + .isNotInstanceOf(SpelEvaluationException.class); // A problem occurred whilst attempting to construct an object of type // 'org.springframework.expression.spel.ConstructorInvocationTests$Tester' // using arguments '(java.lang.Integer)' diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/MethodInvocationTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/MethodInvocationTests.java index e2dd8fc6ff1..0a025acf723 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/MethodInvocationTests.java +++ b/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)"); context.setVariable("bar", 2); - assertThatExceptionOfType(Exception.class).isThrownBy(() -> expr.getValue(context)) - .satisfies(ex -> assertThat(ex).isNotInstanceOf(SpelEvaluationException.class)); + assertThatExceptionOfType(Exception.class) + .isThrownBy(() -> expr.getValue(context)) + .isNotInstanceOf(SpelEvaluationException.class); } @Test diff --git a/spring-jms/src/test/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapterTests.java b/spring-jms/src/test/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapterTests.java index 35ace619bdf..4d0011efffc 100644 --- a/spring-jms/src/test/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapterTests.java +++ b/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"); * 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"); Session session = mock(Session.class); MessagingMessageListenerAdapter listener = getSimpleInstance("fail", String.class); - assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() -> - listener.onMessage(message, session)) - .withCauseExactlyInstanceOf(IllegalArgumentException.class) - .satisfies(ex -> assertThat(ex.getCause().getMessage()).isEqualTo("Expected test exception")); + assertThatExceptionOfType(ListenerExecutionFailedException.class) + .isThrownBy(() -> listener.onMessage(message, session)) + .havingCause() + .isExactlyInstanceOf(IllegalArgumentException.class) + .withMessage("Expected test exception"); } @Test diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/HeaderAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/HeaderAssertionTests.java index 70ea4d63aff..d77fffae4ab 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/HeaderAssertionTests.java +++ b/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"); * you may not use this file except in compliance with the License. @@ -154,10 +154,10 @@ public class HeaderAssertionTests { assertions.contentTypeCompatibleWith(MediaType.parseMediaType("application/*")); // MediaTypes not compatible - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> - assertions.contentTypeCompatibleWith(MediaType.TEXT_XML)) - .satisfies(ex -> assertThat(ex.getCause()).hasMessage("Response header " + - "'Content-Type'=[application/xml] is not compatible with [text/xml]")); + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertions.contentTypeCompatibleWith(MediaType.TEXT_XML)) + .havingCause() + .withMessage("Response header 'Content-Type'=[application/xml] is not compatible with [text/xml]"); } @Test diff --git a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java index 1cb23587d7a..cea2263411e 100644 --- a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java @@ -74,8 +74,8 @@ public class DefaultResponseErrorHandlerTests { assertThatExceptionOfType(HttpClientErrorException.class) .isThrownBy(() -> handler.handleError(response)) - .satisfies(ex -> assertThat(ex.getResponseHeaders()).isSameAs(headers)) - .satisfies(ex -> assertThat(ex.getMessage()).isEqualTo("404 Not Found: [Hello World]")); + .withMessage("404 Not Found: [Hello World]") + .satisfies(ex -> assertThat(ex.getResponseHeaders()).isSameAs(headers)); } @Test @@ -92,8 +92,7 @@ public class DefaultResponseErrorHandlerTests { assertThatExceptionOfType(HttpClientErrorException.class) .isThrownBy(() -> handler.handleError(response)) - .satisfies(ex -> assertThat(ex.getMessage()).isEqualTo( - "404 Not Found: [" + bodyGenerator.apply(200) + "... (500 bytes)]")); + .withMessage("404 Not Found: [" + bodyGenerator.apply(200) + "... (500 bytes)]"); } @Test diff --git a/spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java b/spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java index 6cde4e39313..961ec8bd5e7 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java +++ b/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"); * you may not use this file except in compliance with the License. @@ -273,20 +273,22 @@ public class ContextLoaderTests { MockServletContext sc = new MockServletContext(""); ServletContextListener listener = new ContextLoaderListener(); ServletContextEvent event = new ServletContextEvent(sc); - assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> - listener.contextInitialized(event)) - .withCauseInstanceOf(IOException.class) - .satisfies(ex -> assertThat(ex.getCause()).hasMessageContaining("/WEB-INF/applicationContext.xml")); + assertThatExceptionOfType(BeanDefinitionStoreException.class) + .isThrownBy(() -> listener.contextInitialized(event)) + .havingCause() + .isInstanceOf(IOException.class) + .withMessageContaining("/WEB-INF/applicationContext.xml"); } @Test public void testFrameworkServletWithDefaultLocation() throws Exception { DispatcherServlet servlet = new DispatcherServlet(); servlet.setContextClass(XmlWebApplicationContext.class); - assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> - servlet.init(new MockServletConfig(new MockServletContext(""), "test"))) - .withCauseInstanceOf(IOException.class) - .satisfies(ex -> assertThat(ex.getCause()).hasMessageContaining("/WEB-INF/test-servlet.xml")); + assertThatExceptionOfType(BeanDefinitionStoreException.class) + .isThrownBy(() -> servlet.init(new MockServletConfig(new MockServletContext(""), "test"))) + .havingCause() + .isInstanceOf(IOException.class) + .withMessageContaining("/WEB-INF/test-servlet.xml"); } @Test