Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Mar 6, 2024
1 parent e5e61df commit 0955f54
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -504,6 +508,11 @@ public void initializeApp(ConfigurableApplicationContext applicationContext) {
public TransactionalTestBean testBean() {
return new TransactionalTestBean();
}

@Bean
public CallCountingTransactionManager otherTxManager() {
return new CallCountingTransactionManager();
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0955f54

Please sign in to comment.