Merge branch '5.3.x'

# Conflicts:
#	spring-beans/src/test/java/org/springframework/beans/factory/support/security/CallbacksSecurityTests.java
#	spring-context/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java
#	spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java
#	spring-web/src/test/java/org/springframework/remoting/jaxws/JaxWsSupportTests.java
#	spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java
This commit is contained in:
Sam Brannen
2022-05-31 14:15:36 +02:00
42 changed files with 533 additions and 780 deletions

View File

@@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatRuntimeException;
/**
* @author Adrian Colyer
@@ -35,12 +35,12 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
class SPR3064Tests {
@Test
void testServiceIsAdvised() {
void serviceIsAdvised() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
Service service = ctx.getBean(Service.class);
assertThatExceptionOfType(RuntimeException.class)
assertThatRuntimeException()
.isThrownBy(service::serveMe)
.withMessage("advice invoked");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 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.
@@ -74,9 +74,11 @@ import org.springframework.core.testfixture.io.SerializationTestUtils;
import org.springframework.lang.Nullable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatException;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatRuntimeException;
/**
* @author Rod Johnson
@@ -431,7 +433,7 @@ public abstract class AbstractAopProxyTests {
pc.setTargetSource(mockTargetSource);
AopProxy aop = createAopProxy(pc);
assertThatExceptionOfType(Exception.class).isThrownBy(() -> {
assertThatException().isThrownBy(() -> {
ITestBean tb = (ITestBean) aop.getProxy();
// Note: exception param below isn't used
tb.exceptional(expectedException);
@@ -459,8 +461,7 @@ public abstract class AbstractAopProxyTests {
AopProxy aop = createAopProxy(pc);
ITestBean tb = (ITestBean) aop.getProxy();
assertThatExceptionOfType(UndeclaredThrowableException.class).isThrownBy(
tb::getAge)
assertThatExceptionOfType(UndeclaredThrowableException.class).isThrownBy(tb::getAge)
.satisfies(ex -> assertThat(ex.getUndeclaredThrowable()).isEqualTo(unexpectedException));
}
@@ -480,8 +481,8 @@ public abstract class AbstractAopProxyTests {
AopProxy aop = createAopProxy(pc);
ITestBean tb = (ITestBean) aop.getProxy();
assertThatExceptionOfType(RuntimeException.class).isThrownBy(
tb::getAge)
assertThatRuntimeException()
.isThrownBy(tb::getAge)
.matches(unexpectedException::equals);
}
@@ -571,8 +572,7 @@ public abstract class AbstractAopProxyTests {
lockable.lock();
assertThat(itb.getAge()).isEqualTo(newAge);
assertThatExceptionOfType(LockedException.class).isThrownBy(() ->
itb.setAge(1));
assertThatExceptionOfType(LockedException.class).isThrownBy(() -> itb.setAge(1));
assertThat(itb.getAge()).isEqualTo(newAge);
// Unlock
@@ -675,7 +675,7 @@ public abstract class AbstractAopProxyTests {
target.setAge(21);
ProxyFactory pc = new ProxyFactory(target);
pc.addAdvisor(new DefaultIntroductionAdvisor(new DummyIntroductionAdviceImpl(), Comparable.class));
assertThatExceptionOfType(Exception.class).isThrownBy(() -> {
assertThatException().isThrownBy(() -> {
// TODO May fail on either call: may want to tighten up definition
ITestBean proxied = (ITestBean) createProxy(pc);
proxied.getName();
@@ -725,8 +725,7 @@ public abstract class AbstractAopProxyTests {
pc.addAdvisor(new DefaultIntroductionAdvisor(new MyDi()));
TimeStamped ts = (TimeStamped) createProxy(pc);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(
ts::getTimeStamp);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(ts::getTimeStamp);
}
/**
@@ -754,8 +753,8 @@ public abstract class AbstractAopProxyTests {
pc.addAdvice(new NopInterceptor());
ITestBean proxied = (ITestBean) createProxy(pc);
pc.setFrozen(true);
assertThatExceptionOfType(AopConfigException.class).as("Shouldn't be able to add interceptor when frozen").isThrownBy(() ->
pc.addAdvice(0, new NopInterceptor()))
assertThatExceptionOfType(AopConfigException.class).as("Shouldn't be able to add interceptor when frozen")
.isThrownBy(() -> pc.addAdvice(0, new NopInterceptor()))
.withMessageContaining("frozen");
// Check it still works: proxy factory state shouldn't have been corrupted
assertThat(proxied.getAge()).isEqualTo(target.getAge());
@@ -777,8 +776,8 @@ public abstract class AbstractAopProxyTests {
Advised advised = (Advised) proxied;
assertThat(pc.isFrozen()).isTrue();
assertThatExceptionOfType(AopConfigException.class).as("Shouldn't be able to add Advisor when frozen").isThrownBy(() ->
advised.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor())))
assertThatExceptionOfType(AopConfigException.class).as("Shouldn't be able to add Advisor when frozen")
.isThrownBy(() -> advised.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor())))
.withMessageContaining("frozen");
// Check it still works: proxy factory state shouldn't have been corrupted
assertThat(proxied.getAge()).isEqualTo(target.getAge());
@@ -797,8 +796,8 @@ public abstract class AbstractAopProxyTests {
Advised advised = (Advised) proxied;
assertThat(pc.isFrozen()).isTrue();
assertThatExceptionOfType(AopConfigException.class).as("Shouldn't be able to remove Advisor when frozen").isThrownBy(() ->
advised.removeAdvisor(0))
assertThatExceptionOfType(AopConfigException.class).as("Shouldn't be able to remove Advisor when frozen")
.isThrownBy(() -> advised.removeAdvisor(0))
.withMessageContaining("frozen");
// Didn't get removed
assertThat(advised.getAdvisors().length).isEqualTo(1);
@@ -1311,8 +1310,8 @@ public abstract class AbstractAopProxyTests {
assertThat(cca.getCalls()).isEqualTo(2);
assertThat(proxied.getAge()).isEqualTo(26);
assertThat(cca.getCalls()).isEqualTo(4);
assertThatExceptionOfType(SpecializedUncheckedException.class).as("Should have thrown CannotGetJdbcConnectionException").isThrownBy(() ->
proxied.exceptional(new SpecializedUncheckedException("foo", (SQLException)null)));
assertThatExceptionOfType(SpecializedUncheckedException.class).as("Should have thrown CannotGetJdbcConnectionException")
.isThrownBy(() -> proxied.exceptional(new SpecializedUncheckedException("foo", (SQLException)null)));
assertThat(cca.getCalls()).isEqualTo(6);
}
@@ -1346,8 +1345,8 @@ public abstract class AbstractAopProxyTests {
assertThat(nop1.getCount()).isEqualTo(1);
assertThat(nop2.getCount()).isEqualTo(1);
// Will fail, after invoking Nop1
assertThatExceptionOfType(RuntimeException.class).as("before advice should have ended chain").isThrownBy(() ->
proxied.setAge(26))
assertThatRuntimeException().as("before advice should have ended chain")
.isThrownBy(() -> proxied.setAge(26))
.matches(rex::equals);
assertThat(ba.getCalls()).isEqualTo(2);
assertThat(nop1.getCount()).isEqualTo(2);
@@ -1411,8 +1410,7 @@ public abstract class AbstractAopProxyTests {
assertThat(car.getCalls()).isEqualTo(2);
Exception exc = new Exception();
// On exception it won't be invoked
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
proxied.exceptional(exc))
assertThatExceptionOfType(Throwable.class).isThrownBy(() -> proxied.exceptional(exc))
.satisfies(ex -> assertThat(ex).isSameAs(exc));
assertThat(car.getCalls()).isEqualTo(2);
}
@@ -1442,12 +1440,11 @@ public abstract class AbstractAopProxyTests {
assertThat(th.getCalls()).isEqualTo(0);
Exception ex = new Exception();
// Will be advised but doesn't match
assertThatExceptionOfType(Exception.class).isThrownBy(() ->
proxied.echoException(1, ex))
assertThatException().isThrownBy(() -> proxied.echoException(1, ex))
.matches(ex::equals);
FileNotFoundException fex = new FileNotFoundException();
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(() ->
proxied.echoException(1, fex))
assertThatExceptionOfType(FileNotFoundException.class)
.isThrownBy(() -> proxied.echoException(1, fex))
.matches(fex::equals);
assertThat(th.getCalls("ioException")).isEqualTo(1);
}
@@ -1468,14 +1465,12 @@ public abstract class AbstractAopProxyTests {
assertThat(th.getCalls()).isEqualTo(0);
Exception ex = new Exception();
// Will be advised but doesn't match
assertThatExceptionOfType(Exception.class).isThrownBy(() ->
proxied.echoException(1, ex))
assertThatException().isThrownBy(() -> proxied.echoException(1, ex))
.matches(ex::equals);
// Subclass of RemoteException
MarshalException mex = new MarshalException("");
assertThatExceptionOfType(MarshalException.class).isThrownBy(() ->
proxied.echoException(1, mex))
assertThatExceptionOfType(MarshalException.class).isThrownBy(() -> proxied.echoException(1, mex))
.matches(mex::equals);
assertThat(th.getCalls("remoteException")).isEqualTo(1);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -61,6 +61,7 @@ import org.springframework.core.testfixture.io.SerializationTestUtils;
import org.springframework.lang.Nullable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatException;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIOException;
@@ -310,7 +311,7 @@ public class ProxyFactoryBeanTests {
assertThat(config.getAdvisors().length).as("Have correct advisor count").isEqualTo(2);
ITestBean tb1 = (ITestBean) factory.getBean("test1");
assertThatExceptionOfType(Exception.class)
assertThatException()
.isThrownBy(tb1::toString)
.isSameAs(ex);
}
@@ -438,8 +439,7 @@ public class ProxyFactoryBeanTests {
assertThat(cba.getCalls()).isEqualTo(2);
assertThat(th.getCalls()).isEqualTo(0);
Exception expected = new Exception();
assertThatExceptionOfType(Exception.class).isThrownBy(() ->
echo.echoException(1, expected))
assertThatException().isThrownBy(() -> echo.echoException(1, expected))
.matches(expected::equals);
// No throws handler method: count should still be 0
assertThat(th.getCalls()).isEqualTo(0);
@@ -586,8 +586,7 @@ public class ProxyFactoryBeanTests {
((Lockable) bean1).lock();
assertThatExceptionOfType(LockedException.class).isThrownBy(() ->
bean1.setAge(5));
assertThatExceptionOfType(LockedException.class).isThrownBy(() -> bean1.setAge(5));
bean2.setAge(6); //do not expect LockedException"
}
@@ -607,8 +606,7 @@ public class ProxyFactoryBeanTests {
((Lockable) bean1).lock();
assertThatExceptionOfType(LockedException.class).isThrownBy(() ->
bean1.setAge(5));
assertThatExceptionOfType(LockedException.class).isThrownBy(() -> bean1.setAge(5));
// do not expect LockedException
bean2.setAge(6);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@@ -37,7 +37,7 @@ import org.springframework.context.testfixture.cache.beans.CacheableService;
import org.springframework.context.testfixture.cache.beans.DefaultCacheableService;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatRuntimeException;
/**
* @author Stephane Nicoll
@@ -76,8 +76,8 @@ public class CustomInterceptorTests {
@Test
public void customInterceptorAppliesWithCheckedException() {
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() ->
this.cs.throwChecked(0L))
assertThatRuntimeException()
.isThrownBy(() -> this.cs.throwChecked(0L))
.withCauseExactlyInstanceOf(IOException.class);
}

View File

@@ -52,7 +52,7 @@ import org.springframework.scheduling.support.TaskUtils;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatRuntimeException;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willThrow;
@@ -161,8 +161,8 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
RuntimeException thrown = new RuntimeException();
willThrow(thrown).given(listener).onApplicationEvent(evt);
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() ->
smc.multicastEvent(evt))
assertThatRuntimeException()
.isThrownBy(() -> smc.multicastEvent(evt))
.satisfies(ex -> assertThat(ex).isSameAs(thrown));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -59,6 +59,7 @@ import org.springframework.jmx.support.RegistrationPolicy;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatRuntimeException;
/**
* Integration tests for the {@link MBeanExporter} class.
@@ -589,8 +590,8 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
exporter.setBeans(beansToExport);
exporter.setBeanFactory(factory);
assertThatExceptionOfType(RuntimeException.class).as("failed during creation of RuntimeExceptionThrowingConstructorBean").isThrownBy(() ->
start(exporter));
assertThatRuntimeException().as("failed during creation of RuntimeExceptionThrowingConstructorBean")
.isThrownBy(() -> start(exporter));
assertIsNotRegistered("Must have unregistered all previously registered MBeans due to RuntimeException",
ObjectNameManager.getInstance(objectName1));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@@ -22,51 +22,50 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.support.GenericXmlApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatRuntimeException;
/**
* @author Dave Syer
*/
public class GroovyAspectIntegrationTests {
class GroovyAspectIntegrationTests {
private GenericXmlApplicationContext context;
@Test
public void testJavaBean() {
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-java-context.xml");
void javaBean() {
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName() + "-java-context.xml");
TestService bean = context.getBean("javaBean", TestService.class);
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class);
assertThat(logAdvice.getCountThrows()).isEqualTo(0);
assertThatExceptionOfType(RuntimeException.class).isThrownBy(
bean::sayHello)
assertThatRuntimeException()
.isThrownBy(bean::sayHello)
.withMessage("TestServiceImpl");
assertThat(logAdvice.getCountThrows()).isEqualTo(1);
}
@Test
public void testGroovyBeanInterface() {
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-interface-context.xml");
void groovyBeanInterface() {
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName() + "-groovy-interface-context.xml");
TestService bean = context.getBean("groovyBean", TestService.class);
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class);
assertThat(logAdvice.getCountThrows()).isEqualTo(0);
assertThatExceptionOfType(RuntimeException.class).isThrownBy(
bean::sayHello)
assertThatRuntimeException()
.isThrownBy(bean::sayHello)
.withMessage("GroovyServiceImpl");
assertThat(logAdvice.getCountThrows()).isEqualTo(1);
}
@Test
public void testGroovyBeanDynamic() {
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-dynamic-context.xml");
void groovyBeanDynamic() {
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName() + "-groovy-dynamic-context.xml");
TestService bean = context.getBean("groovyBean", TestService.class);
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class);
assertThat(logAdvice.getCountThrows()).isEqualTo(0);
assertThatExceptionOfType(RuntimeException.class).isThrownBy(
bean::sayHello)
assertThatRuntimeException()
.isThrownBy(bean::sayHello)
.withMessage("GroovyServiceImpl");
// No proxy here because the pointcut only applies to the concrete class, not the interface
assertThat(logAdvice.getCountThrows()).isEqualTo(0);
@@ -74,21 +73,21 @@ public class GroovyAspectIntegrationTests {
}
@Test
public void testGroovyBeanProxyTargetClass() {
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-proxy-target-class-context.xml");
void groovyBeanProxyTargetClass() {
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName() + "-groovy-proxy-target-class-context.xml");
TestService bean = context.getBean("groovyBean", TestService.class);
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class);
assertThat(logAdvice.getCountThrows()).isEqualTo(0);
assertThatExceptionOfType(RuntimeException.class).isThrownBy(
bean::sayHello)
assertThatRuntimeException()
.isThrownBy(bean::sayHello)
.withMessage("GroovyServiceImpl");
assertThat(logAdvice.getCountBefore()).isEqualTo(1);
assertThat(logAdvice.getCountThrows()).isEqualTo(1);
}
@AfterEach
public void close() {
void close() {
if (context != null) {
context.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@@ -46,6 +46,7 @@ import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatException;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
@@ -318,7 +319,7 @@ public class GroovyScriptFactoryTests {
@Test
public void testWithTwoClassesDefinedInTheOneGroovyFile_WrongClassFirst() throws Exception {
assertThatExceptionOfType(Exception.class).as("two classes defined in GroovyScriptFactory source, non-Messenger class defined first").isThrownBy(() -> {
assertThatException().as("two classes defined in GroovyScriptFactory source, non-Messenger class defined first").isThrownBy(() -> {
ApplicationContext ctx = new ClassPathXmlApplicationContext("twoClassesWrongOneFirst.xml", getClass());
ctx.getBean("messenger", Messenger.class);
});