From 0955f541cbcff9dc45adfd696069779992f49d80 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 6 Mar 2024 18:03:36 +0100 Subject: [PATCH] Polishing --- .../EnableTransactionManagementTests.java | 17 +++++++++++++---- .../TransactionInterceptorTests.java | 18 +++++++----------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java b/spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java index b4216ed8b282..7b97794a869c 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test; import org.springframework.aop.support.AopUtils; +import org.springframework.beans.factory.NoUniqueBeanDefinitionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AdviceMode; @@ -46,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatException; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; /** * Tests demonstrating use of @EnableTransactionManagement @Configuration classes. @@ -226,8 +228,8 @@ void proxyTypeAspectJCausesRegistrationOfAnnotationTransactionAspect() { // should throw CNFE when trying to load AnnotationTransactionAspect. // Do you actually have org.springframework.aspects on the classpath? assertThatException() - .isThrownBy(() -> new AnnotationConfigApplicationContext(EnableAspectjTxConfig.class, TxManagerConfig.class)) - .withMessageContaining("AspectJJtaTransactionManagementConfiguration"); + .isThrownBy(() -> new AnnotationConfigApplicationContext(EnableAspectjTxConfig.class, TxManagerConfig.class)) + .withMessageContaining("AspectJJtaTransactionManagementConfiguration"); } @Test @@ -254,11 +256,13 @@ void spr11915TransactionManagerAsManualSingleton() { assertThat(txManager.commits).isEqualTo(2); assertThat(txManager.rollbacks).isEqualTo(0); + assertThatExceptionOfType(NoUniqueBeanDefinitionException.class).isThrownBy(bean::findAllFoos); + ctx.close(); } @Test - void spr14322FindsOnInterfaceWithInterfaceProxy() { + void spr14322AnnotationOnInterfaceWithInterfaceProxy() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigA.class); TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.class); CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class); @@ -273,7 +277,7 @@ void spr14322FindsOnInterfaceWithInterfaceProxy() { } @Test - void spr14322FindsOnInterfaceWithCglibProxy() { + void spr14322AnnotationOnInterfaceWithCglibProxy() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigB.class); TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.class); CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class); @@ -504,6 +508,11 @@ public void initializeApp(ConfigurableApplicationContext applicationContext) { public TransactionalTestBean testBean() { return new TransactionalTestBean(); } + + @Bean + public CallCountingTransactionManager otherTxManager() { + return new CallCountingTransactionManager(); + } } diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java index 6cacda657e33..3c7c352bba3c 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java @@ -116,15 +116,11 @@ void serializableWithCompositeSource() throws Exception { ti.setTransactionManager(ptm); ti = SerializationTestUtils.serializeAndDeserialize(ti); - boolean condition3 = ti.getTransactionManager() instanceof SerializableTransactionManager; - assertThat(condition3).isTrue(); - boolean condition2 = ti.getTransactionAttributeSource() instanceof CompositeTransactionAttributeSource; - assertThat(condition2).isTrue(); + assertThat(ti.getTransactionManager() instanceof SerializableTransactionManager).isTrue(); + assertThat(ti.getTransactionAttributeSource() instanceof CompositeTransactionAttributeSource).isTrue(); CompositeTransactionAttributeSource ctas = (CompositeTransactionAttributeSource) ti.getTransactionAttributeSource(); - boolean condition1 = ctas.getTransactionAttributeSources()[0] instanceof NameMatchTransactionAttributeSource; - assertThat(condition1).isTrue(); - boolean condition = ctas.getTransactionAttributeSources()[1] instanceof NameMatchTransactionAttributeSource; - assertThat(condition).isTrue(); + assertThat(ctas.getTransactionAttributeSources()[0] instanceof NameMatchTransactionAttributeSource).isTrue(); + assertThat(ctas.getTransactionAttributeSources()[1] instanceof NameMatchTransactionAttributeSource).isTrue(); } @Test @@ -158,9 +154,9 @@ void determineTransactionManagerWithQualifierUnknown() { DefaultTransactionAttribute attribute = new DefaultTransactionAttribute(); attribute.setQualifier("fooTransactionManager"); - assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> - ti.determineTransactionManager(attribute)) - .withMessageContaining("'fooTransactionManager'"); + assertThatExceptionOfType(NoSuchBeanDefinitionException.class) + .isThrownBy(() -> ti.determineTransactionManager(attribute)) + .withMessageContaining("'fooTransactionManager'"); } @Test