From 2358468f84d1d8740b56531cec4a165ec04ca135 Mon Sep 17 00:00:00 2001 From: David Erickson Date: Tue, 24 Feb 2015 01:06:31 -0800 Subject: [PATCH] Add repro for SPR-12749 --- SPR-12749/pom.xml | 90 +++++++++++++++++++ SPR-12749/src/main/resources/.gitignore | 0 .../issues/MyMetaAnnotation.java | 16 ++++ .../issues/MyTestExecutionListener.java | 42 +++++++++ .../springframework/issues/ReproTests.java | 26 ++++++ .../springframework/issues/SpringConfig.java | 8 ++ SPR-12749/src/test/resources/log4j.properties | 7 ++ 7 files changed, 189 insertions(+) create mode 100644 SPR-12749/pom.xml create mode 100644 SPR-12749/src/main/resources/.gitignore create mode 100644 SPR-12749/src/test/java/org/springframework/issues/MyMetaAnnotation.java create mode 100644 SPR-12749/src/test/java/org/springframework/issues/MyTestExecutionListener.java create mode 100644 SPR-12749/src/test/java/org/springframework/issues/ReproTests.java create mode 100644 SPR-12749/src/test/java/org/springframework/issues/SpringConfig.java create mode 100644 SPR-12749/src/test/resources/log4j.properties diff --git a/SPR-12749/pom.xml b/SPR-12749/pom.xml new file mode 100644 index 00000000..b5ec433f --- /dev/null +++ b/SPR-12749/pom.xml @@ -0,0 +1,90 @@ + + 4.0.0 + org.springframework.issues + SPR-12749 + 1.0-SNAPSHOT + jar + + + UTF-8 + + 1.6 + 4.1.4.RELEASE + 1.7.5 + + + + + org.springframework + spring-context + ${spring.version} + + + + org.springframework + spring-test + ${spring.version} + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + runtime + + + + junit + junit + 4.11 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + + **/*Tests.java + **/*Test.java + + + **/*Abstract*.java + + + + + + + + + spring-maven-snapshot + Springframework Maven Snapshot Repository + http://repo.spring.io/snapshot + + true + + + + + + diff --git a/SPR-12749/src/main/resources/.gitignore b/SPR-12749/src/main/resources/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/SPR-12749/src/test/java/org/springframework/issues/MyMetaAnnotation.java b/SPR-12749/src/test/java/org/springframework/issues/MyMetaAnnotation.java new file mode 100644 index 00000000..11e9b9e5 --- /dev/null +++ b/SPR-12749/src/test/java/org/springframework/issues/MyMetaAnnotation.java @@ -0,0 +1,16 @@ +package org.springframework.issues; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestExecutionListeners; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@ContextConfiguration(classes = {SpringConfig.class}) +@TestExecutionListeners({MyTestExecutionListener.class}) +public @interface MyMetaAnnotation { +} diff --git a/SPR-12749/src/test/java/org/springframework/issues/MyTestExecutionListener.java b/SPR-12749/src/test/java/org/springframework/issues/MyTestExecutionListener.java new file mode 100644 index 00000000..ba373021 --- /dev/null +++ b/SPR-12749/src/test/java/org/springframework/issues/MyTestExecutionListener.java @@ -0,0 +1,42 @@ +/** + * + */ +package org.springframework.issues; + +import org.springframework.test.context.TestContext; +import org.springframework.test.context.TestExecutionListener; + +/** + * @author derickso + * + */ +public class MyTestExecutionListener implements TestExecutionListener { + protected static volatile boolean listenerRun = false; + + @Override + public void beforeTestClass(TestContext testContext) throws Exception { + listenerRun = true; + } + + @Override + public void prepareTestInstance(TestContext testContext) throws Exception { + listenerRun = true; + } + + @Override + public void beforeTestMethod(TestContext testContext) throws Exception { + listenerRun = true; + } + + @Override + public void afterTestMethod(TestContext testContext) throws Exception { + } + + @Override + public void afterTestClass(TestContext testContext) throws Exception { + } + + public static boolean isListenerRun() { + return listenerRun; + } +} diff --git a/SPR-12749/src/test/java/org/springframework/issues/ReproTests.java b/SPR-12749/src/test/java/org/springframework/issues/ReproTests.java new file mode 100644 index 00000000..3673af17 --- /dev/null +++ b/SPR-12749/src/test/java/org/springframework/issues/ReproTests.java @@ -0,0 +1,26 @@ +package org.springframework.issues; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.test.context.TestExecutionListeners; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; +import org.springframework.test.util.MetaAnnotationUtils; +import org.springframework.test.util.MetaAnnotationUtils.AnnotationDescriptor; + +/** + * Unit test that reproduces an issue reported against SPR JIRA. @Test methods within + * need not pass with the green bar! Rather they should fail in such a way that + * demonstrates the reported issue. + */ +@MyMetaAnnotation +public class ReproTests extends AbstractJUnit4SpringContextTests { + @Test + public void repro() { + AnnotationDescriptor descriptor = MetaAnnotationUtils.findAnnotationDescriptor(ReproTests.class, + TestExecutionListeners.class); + Assert.assertTrue(MyTestExecutionListener.isListenerRun()); + Class[] classes = (Class[]) descriptor.getAnnotationAttributes().get("value"); + Assert.assertEquals(1, classes.length); + Assert.assertEquals(MyTestExecutionListener.class, classes[0]); + } +} diff --git a/SPR-12749/src/test/java/org/springframework/issues/SpringConfig.java b/SPR-12749/src/test/java/org/springframework/issues/SpringConfig.java new file mode 100644 index 00000000..870546aa --- /dev/null +++ b/SPR-12749/src/test/java/org/springframework/issues/SpringConfig.java @@ -0,0 +1,8 @@ +package org.springframework.issues; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SpringConfig { +} diff --git a/SPR-12749/src/test/resources/log4j.properties b/SPR-12749/src/test/resources/log4j.properties new file mode 100644 index 00000000..82776b7b --- /dev/null +++ b/SPR-12749/src/test/resources/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootCategory=ERROR, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n + +log4j.category.org.springframework=WARN \ No newline at end of file