diff --git a/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java b/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java index 003491f0b0..ce346859d1 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -18,11 +18,10 @@ package org.springframework.transaction.annotation; import java.io.IOException; import java.io.Serializable; -import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; import java.lang.reflect.Method; + import javax.ejb.TransactionAttributeType; import org.junit.Test; @@ -48,7 +47,7 @@ import static org.junit.Assert.*; public class AnnotationTransactionAttributeSourceTests { @Test - public void testSerializable() throws Exception { + public void serializable() throws Exception { TestBean1 tb = new TestBean1(); CallCountingTransactionManager ptm = new CallCountingTransactionManager(); AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource(); @@ -72,8 +71,8 @@ public class AnnotationTransactionAttributeSourceTests { } @Test - public void testNullOrEmpty() throws Exception { - Method method = Empty.class.getMethod("getAge", (Class[]) null); + public void nullOrEmpty() throws Exception { + Method method = Empty.class.getMethod("getAge"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); assertNull(atas.getTransactionAttribute(method, null)); @@ -87,8 +86,8 @@ public class AnnotationTransactionAttributeSourceTests { * but the attribute is defined on the target class. */ @Test - public void testTransactionAttributeDeclaredOnClassMethod() throws Exception { - Method classMethod = ITestBean.class.getMethod("getAge", (Class[]) null); + public void transactionAttributeDeclaredOnClassMethod() throws Exception { + Method classMethod = ITestBean.class.getMethod("getAge"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute actual = atas.getTransactionAttribute(classMethod, TestBean1.class); @@ -103,8 +102,8 @@ public class AnnotationTransactionAttributeSourceTests { * but the attribute is defined on the target class. */ @Test - public void testTransactionAttributeDeclaredOnCglibClassMethod() throws Exception { - Method classMethod = ITestBean.class.getMethod("getAge", (Class[]) null); + public void transactionAttributeDeclaredOnCglibClassMethod() throws Exception { + Method classMethod = ITestBean.class.getMethod("getAge"); TestBean1 tb = new TestBean1(); ProxyFactory pf = new ProxyFactory(tb); pf.setProxyTargetClass(true); @@ -122,8 +121,8 @@ public class AnnotationTransactionAttributeSourceTests { * Test case where attribute is on the interface method. */ @Test - public void testTransactionAttributeDeclaredOnInterfaceMethodOnly() throws Exception { - Method interfaceMethod = ITestBean2.class.getMethod("getAge", (Class[]) null); + public void transactionAttributeDeclaredOnInterfaceMethodOnly() throws Exception { + Method interfaceMethod = ITestBean2.class.getMethod("getAge"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute actual = atas.getTransactionAttribute(interfaceMethod, TestBean2.class); @@ -136,9 +135,9 @@ public class AnnotationTransactionAttributeSourceTests { * Test that when an attribute exists on both class and interface, class takes precedence. */ @Test - public void testTransactionAttributeOnTargetClassMethodOverridesAttributeOnInterfaceMethod() throws Exception { - Method interfaceMethod = ITestBean3.class.getMethod("getAge", (Class[]) null); - Method interfaceMethod2 = ITestBean3.class.getMethod("getName", (Class[]) null); + public void transactionAttributeOnTargetClassMethodOverridesAttributeOnInterfaceMethod() throws Exception { + Method interfaceMethod = ITestBean3.class.getMethod("getAge"); + Method interfaceMethod2 = ITestBean3.class.getMethod("getName"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute actual = atas.getTransactionAttribute(interfaceMethod, TestBean3.class); @@ -157,8 +156,8 @@ public class AnnotationTransactionAttributeSourceTests { } @Test - public void testRollbackRulesAreApplied() throws Exception { - Method method = TestBean3.class.getMethod("getAge", (Class[]) null); + public void rollbackRulesAreApplied() throws Exception { + Method method = TestBean3.class.getMethod("getAge"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean3.class); @@ -187,8 +186,8 @@ public class AnnotationTransactionAttributeSourceTests { * if not specified on method. */ @Test - public void testDefaultsToClassTransactionAttribute() throws Exception { - Method method = TestBean4.class.getMethod("getAge", (Class[]) null); + public void defaultsToClassTransactionAttribute() throws Exception { + Method method = TestBean4.class.getMethod("getAge"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean4.class); @@ -200,8 +199,8 @@ public class AnnotationTransactionAttributeSourceTests { } @Test - public void testCustomClassAttributeDetected() throws Exception { - Method method = TestBean5.class.getMethod("getAge", (Class[]) null); + public void customClassAttributeDetected() throws Exception { + Method method = TestBean5.class.getMethod("getAge"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean5.class); @@ -213,8 +212,8 @@ public class AnnotationTransactionAttributeSourceTests { } @Test - public void testCustomMethodAttributeDetected() throws Exception { - Method method = TestBean6.class.getMethod("getAge", (Class[]) null); + public void customMethodAttributeDetected() throws Exception { + Method method = TestBean6.class.getMethod("getAge"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean6.class); @@ -226,8 +225,8 @@ public class AnnotationTransactionAttributeSourceTests { } @Test - public void testCustomClassAttributeWithReadOnlyOverrideDetected() throws Exception { - Method method = TestBean7.class.getMethod("getAge", (Class[]) null); + public void customClassAttributeWithReadOnlyOverrideDetected() throws Exception { + Method method = TestBean7.class.getMethod("getAge"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean7.class); @@ -241,8 +240,8 @@ public class AnnotationTransactionAttributeSourceTests { } @Test - public void testCustomMethodAttributeWithReadOnlyOverrideDetected() throws Exception { - Method method = TestBean8.class.getMethod("getAge", (Class[]) null); + public void customMethodAttributeWithReadOnlyOverrideDetected() throws Exception { + Method method = TestBean8.class.getMethod("getAge"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean8.class); @@ -257,7 +256,7 @@ public class AnnotationTransactionAttributeSourceTests { @Test public void customClassAttributeWithReadOnlyOverrideOnInterface() throws Exception { - Method method = TestInterface9.class.getMethod("getAge", (Class[]) null); + Method method = TestInterface9.class.getMethod("getAge"); Transactional annotation = AnnotationUtils.findAnnotation(method, Transactional.class); assertNull("AnnotationUtils.findAnnotation should not find @Transactional for TestBean9.getAge()", annotation); @@ -266,7 +265,7 @@ public class AnnotationTransactionAttributeSourceTests { AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean9.class); - assertNotNull("Retrieved TransactionAttribute for TestBean9", actual); + assertNotNull("Failed to retrieve TransactionAttribute for TestBean9.getAge()", actual); RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute(); rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class)); @@ -278,7 +277,7 @@ public class AnnotationTransactionAttributeSourceTests { @Test public void customMethodAttributeWithReadOnlyOverrideOnInterface() throws Exception { - Method method = TestInterface10.class.getMethod("getAge", (Class[]) null); + Method method = TestInterface10.class.getMethod("getAge"); Transactional annotation = AnnotationUtils.findAnnotation(method, Transactional.class); assertNotNull("AnnotationUtils.findAnnotation failed to find @Transactional for TestBean10.getAge()", @@ -288,7 +287,7 @@ public class AnnotationTransactionAttributeSourceTests { AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean10.class); - assertNotNull("Retrieved TransactionAttribute for TestBean10", actual); + assertNotNull("Failed to retrieve TransactionAttribute for TestBean10.getAge()", actual); RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute(); rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class)); @@ -299,9 +298,9 @@ public class AnnotationTransactionAttributeSourceTests { } @Test - public void testTransactionAttributeDeclaredOnClassMethodWithEjb3() throws Exception { - Method getAgeMethod = ITestBean.class.getMethod("getAge", (Class[]) null); - Method getNameMethod = ITestBean.class.getMethod("getName", (Class[]) null); + public void transactionAttributeDeclaredOnClassMethodWithEjb3() throws Exception { + Method getAgeMethod = ITestBean.class.getMethod("getAge"); + Method getNameMethod = ITestBean.class.getMethod("getName"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, Ejb3AnnotatedBean1.class); @@ -311,9 +310,9 @@ public class AnnotationTransactionAttributeSourceTests { } @Test - public void testTransactionAttributeDeclaredOnClassWithEjb3() throws Exception { - Method getAgeMethod = ITestBean.class.getMethod("getAge", (Class[]) null); - Method getNameMethod = ITestBean.class.getMethod("getName", (Class[]) null); + public void transactionAttributeDeclaredOnClassWithEjb3() throws Exception { + Method getAgeMethod = ITestBean.class.getMethod("getAge"); + Method getNameMethod = ITestBean.class.getMethod("getName"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, Ejb3AnnotatedBean2.class); @@ -323,9 +322,9 @@ public class AnnotationTransactionAttributeSourceTests { } @Test - public void testTransactionAttributeDeclaredOnInterfaceWithEjb3() throws Exception { - Method getAgeMethod = ITestEjb.class.getMethod("getAge", (Class[]) null); - Method getNameMethod = ITestEjb.class.getMethod("getName", (Class[]) null); + public void transactionAttributeDeclaredOnInterfaceWithEjb3() throws Exception { + Method getAgeMethod = ITestEjb.class.getMethod("getAge"); + Method getNameMethod = ITestEjb.class.getMethod("getName"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, Ejb3AnnotatedBean3.class); @@ -335,9 +334,9 @@ public class AnnotationTransactionAttributeSourceTests { } @Test - public void testTransactionAttributeDeclaredOnClassMethodWithJta() throws Exception { - Method getAgeMethod = ITestBean.class.getMethod("getAge", (Class[]) null); - Method getNameMethod = ITestBean.class.getMethod("getName", (Class[]) null); + public void transactionAttributeDeclaredOnClassMethodWithJta() throws Exception { + Method getAgeMethod = ITestBean.class.getMethod("getAge"); + Method getNameMethod = ITestBean.class.getMethod("getName"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, JtaAnnotatedBean1.class); @@ -347,9 +346,9 @@ public class AnnotationTransactionAttributeSourceTests { } @Test - public void testTransactionAttributeDeclaredOnClassWithJta() throws Exception { - Method getAgeMethod = ITestBean.class.getMethod("getAge", (Class[]) null); - Method getNameMethod = ITestBean.class.getMethod("getName", (Class[]) null); + public void transactionAttributeDeclaredOnClassWithJta() throws Exception { + Method getAgeMethod = ITestBean.class.getMethod("getAge"); + Method getNameMethod = ITestBean.class.getMethod("getName"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, JtaAnnotatedBean2.class); @@ -359,9 +358,9 @@ public class AnnotationTransactionAttributeSourceTests { } @Test - public void testTransactionAttributeDeclaredOnInterfaceWithJta() throws Exception { - Method getAgeMethod = ITestEjb.class.getMethod("getAge", (Class[]) null); - Method getNameMethod = ITestEjb.class.getMethod("getName", (Class[]) null); + public void transactionAttributeDeclaredOnInterfaceWithJta() throws Exception { + Method getAgeMethod = ITestEjb.class.getMethod("getAge"); + Method getNameMethod = ITestEjb.class.getMethod("getName"); AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, JtaAnnotatedBean3.class); @@ -371,7 +370,7 @@ public class AnnotationTransactionAttributeSourceTests { } - public interface ITestBean { + interface ITestBean { int getAge(); @@ -383,7 +382,7 @@ public class AnnotationTransactionAttributeSourceTests { } - public interface ITestBean2 { + interface ITestBean2 { @Transactional int getAge(); @@ -397,7 +396,7 @@ public class AnnotationTransactionAttributeSourceTests { @Transactional - public interface ITestBean3 { + interface ITestBean3 { int getAge(); @@ -409,7 +408,7 @@ public class AnnotationTransactionAttributeSourceTests { } - public static class Empty implements ITestBean { + static class Empty implements ITestBean { private String name; @@ -446,7 +445,7 @@ public class AnnotationTransactionAttributeSourceTests { @SuppressWarnings("serial") - public static class TestBean1 implements ITestBean, Serializable { + static class TestBean1 implements ITestBean, Serializable { private String name; @@ -483,7 +482,7 @@ public class AnnotationTransactionAttributeSourceTests { } - public static class TestBean2 implements ITestBean2 { + static class TestBean2 implements ITestBean2 { private String name; @@ -519,7 +518,7 @@ public class AnnotationTransactionAttributeSourceTests { } - public static class TestBean3 implements ITestBean3 { + static class TestBean3 implements ITestBean3 { private String name; @@ -558,7 +557,7 @@ public class AnnotationTransactionAttributeSourceTests { @Transactional(rollbackFor=Exception.class, noRollbackFor={IOException.class}) - public static class TestBean4 implements ITestBean3 { + static class TestBean4 implements ITestBean3 { private String name; @@ -594,15 +593,14 @@ public class AnnotationTransactionAttributeSourceTests { } - @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Transactional(rollbackFor=Exception.class, noRollbackFor={IOException.class}) - public @interface Tx { + @interface Tx { } @Tx - public static class TestBean5 { + static class TestBean5 { public int getAge() { return 10; @@ -610,7 +608,7 @@ public class AnnotationTransactionAttributeSourceTests { } - public static class TestBean6 { + static class TestBean6 { @Tx public int getAge() { @@ -619,17 +617,15 @@ public class AnnotationTransactionAttributeSourceTests { } - @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Transactional(rollbackFor=Exception.class, noRollbackFor={IOException.class}) - public @interface TxWithAttribute { - + @interface TxWithAttribute { boolean readOnly(); } @TxWithAttribute(readOnly=true) - public static class TestBean7 { + static class TestBean7 { public int getAge() { return 10; @@ -637,7 +633,7 @@ public class AnnotationTransactionAttributeSourceTests { } - public static class TestBean8 { + static class TestBean8 { @TxWithAttribute(readOnly = true) public int getAge() { @@ -646,12 +642,11 @@ public class AnnotationTransactionAttributeSourceTests { } @TxWithAttribute(readOnly = true) - public static interface TestInterface9 { - - public int getAge(); + interface TestInterface9 { + int getAge(); } - public static class TestBean9 implements TestInterface9 { + static class TestBean9 implements TestInterface9 { @Override public int getAge() { @@ -659,13 +654,13 @@ public class AnnotationTransactionAttributeSourceTests { } } - public static interface TestInterface10 { + interface TestInterface10 { @TxWithAttribute(readOnly=true) - public int getAge(); + int getAge(); } - public static class TestBean10 implements TestInterface10 { + static class TestBean10 implements TestInterface10 { @Override public int getAge() { @@ -674,13 +669,13 @@ public class AnnotationTransactionAttributeSourceTests { } - public static interface Foo { + interface Foo { void doSomething(T theArgument); } - public static class MyFoo implements Foo { + static class MyFoo implements Foo { @Override @Transactional @@ -690,7 +685,7 @@ public class AnnotationTransactionAttributeSourceTests { } - public static class Ejb3AnnotatedBean1 implements ITestBean { + static class Ejb3AnnotatedBean1 implements ITestBean { private String name; @@ -721,7 +716,7 @@ public class AnnotationTransactionAttributeSourceTests { @javax.ejb.TransactionAttribute(TransactionAttributeType.SUPPORTS) - public static class Ejb3AnnotatedBean2 implements ITestBean { + static class Ejb3AnnotatedBean2 implements ITestBean { private String name; @@ -751,7 +746,7 @@ public class AnnotationTransactionAttributeSourceTests { @javax.ejb.TransactionAttribute(TransactionAttributeType.SUPPORTS) - public interface ITestEjb { + interface ITestEjb { @javax.ejb.TransactionAttribute int getAge(); @@ -764,7 +759,7 @@ public class AnnotationTransactionAttributeSourceTests { } - public static class Ejb3AnnotatedBean3 implements ITestEjb { + static class Ejb3AnnotatedBean3 implements ITestEjb { private String name; @@ -792,7 +787,7 @@ public class AnnotationTransactionAttributeSourceTests { } - public static class JtaAnnotatedBean1 implements ITestBean { + static class JtaAnnotatedBean1 implements ITestBean { private String name; @@ -823,7 +818,7 @@ public class AnnotationTransactionAttributeSourceTests { @javax.transaction.Transactional(javax.transaction.Transactional.TxType.SUPPORTS) - public static class JtaAnnotatedBean2 implements ITestBean { + static class JtaAnnotatedBean2 implements ITestBean { private String name; @@ -853,7 +848,7 @@ public class AnnotationTransactionAttributeSourceTests { @javax.transaction.Transactional(javax.transaction.Transactional.TxType.SUPPORTS) - public interface ITestJta { + interface ITestJta { @javax.transaction.Transactional int getAge(); @@ -866,7 +861,7 @@ public class AnnotationTransactionAttributeSourceTests { } - public static class JtaAnnotatedBean3 implements ITestEjb { + static class JtaAnnotatedBean3 implements ITestEjb { private String name;