Upgrade to AssertJ 3.16

This commit is contained in:
Sam Brannen
2020-05-06 14:34:13 +02:00
parent b1c1a232ca
commit 12e05280ad
20 changed files with 110 additions and 97 deletions

View File

@@ -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);
}
/**

View File

@@ -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

View File

@@ -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

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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();
}