Skip to content
Browse files

Merge branch 'SPR-9155'

  • Loading branch information...
2 parents 4a9d255 + 6c32b91 commit d2ca86436a478253b998879d56dfe93bed7294b8 @wilkinsona committed
View
62 SPR-9155/pom.xml
@@ -0,0 +1,62 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.springframework.issues</groupId>
+ <artifactId>SPR-9155</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>3.2.0.BUILD-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.16</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <repositories>
+ <repository>
+ <id>spring-maven-snapshot</id>
+ <name>Springframework Maven Snapshot Repository</name>
+ <url>http://repo.springsource.org/snapshot</url>
+ <snapshots><enabled>true</enabled></snapshots>
+ </repository>
+ </repositories>
+ <properties>
+ <project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.7.2</version>
+ <configuration>
+ <includes>
+ <include>**/*Tests.java</include>
+ </includes>
+ <excludes>
+ <exclude>**/*Abstract*.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
+
View
30 SPR-9155/src/main/java/org/springframework/issues/Alpha.java
@@ -0,0 +1,30 @@
+package org.springframework.issues;
+
+import java.util.Set;
+
+public abstract class Alpha {
+
+ private final Bravo bravo;
+
+ private final Set<Charlie> charlie;
+
+ private final Set<Delta> delta;
+
+ protected Alpha(Bravo bravo, Set<Charlie> charlie, Set<Delta> delta) {
+ this.bravo = bravo;
+ this.charlie = charlie;
+ this.delta = delta;
+ }
+
+ public final Bravo getBravo() {
+ return bravo;
+ }
+
+ public final Set<Charlie> getCharlie() {
+ return charlie;
+ }
+
+ public final Set<Delta> getDelta() {
+ return delta;
+ }
+}
View
5 SPR-9155/src/main/java/org/springframework/issues/Bravo.java
@@ -0,0 +1,5 @@
+package org.springframework.issues;
+
+public class Bravo {
+
+}
View
5 SPR-9155/src/main/java/org/springframework/issues/Charlie.java
@@ -0,0 +1,5 @@
+package org.springframework.issues;
+
+public class Charlie {
+
+}
View
5 SPR-9155/src/main/java/org/springframework/issues/Delta.java
@@ -0,0 +1,5 @@
+package org.springframework.issues;
+
+public class Delta {
+
+}
View
29 SPR-9155/src/main/java/org/springframework/issues/FourConstructorsAlpha.java
@@ -0,0 +1,29 @@
+package org.springframework.issues;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+public final class FourConstructorsAlpha extends Alpha {
+
+ @Autowired(required=false)
+ public FourConstructorsAlpha(Bravo bravo) {
+ this(bravo, Collections.<Charlie>emptySet(), Collections.<Delta>emptySet());
+ }
+
+ @Autowired(required=false)
+ public FourConstructorsAlpha(Bravo bravo, Set<Charlie> charlies) {
+ this(bravo, charlies, Collections.<Delta>emptySet());
+ }
+
+ @Autowired(required=false)
+ public FourConstructorsAlpha(Set<Delta> deltas, Bravo bravo) {
+ this(bravo, Collections.<Charlie>emptySet(), deltas);
+ }
+
+ @Autowired(required=false)
+ public FourConstructorsAlpha(Bravo bravo, Set<Charlie> charlies, Set<Delta> deltas) {
+ super(bravo, charlies, deltas);
+ }
+}
View
13 SPR-9155/src/main/java/org/springframework/issues/OneConstructorAlpha.java
@@ -0,0 +1,13 @@
+package org.springframework.issues;
+
+import java.util.Set;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+public final class OneConstructorAlpha extends Alpha {
+
+ @Autowired(required=false)
+ public OneConstructorAlpha(Bravo bravo, Set<Charlie> charlies, Set<Delta> deltas) {
+ super(bravo, charlies, deltas);
+ }
+}
View
19 SPR-9155/src/main/java/org/springframework/issues/TwoConstructorsAlpha.java
@@ -0,0 +1,19 @@
+package org.springframework.issues;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+public final class TwoConstructorsAlpha extends Alpha {
+
+ @Autowired(required=false)
+ public TwoConstructorsAlpha(Bravo bravo) {
+ this(bravo, Collections.<Charlie>emptySet(), Collections.<Delta>emptySet());
+ }
+
+ @Autowired(required=false)
+ public TwoConstructorsAlpha(Bravo bravo, Set<Charlie> charlies, Set<Delta> deltas) {
+ super(bravo, charlies, deltas);
+ }
+}
View
0 SPR-9155/src/main/resources/.gitignore
No changes.
View
114 SPR-9155/src/test/java/org/springframework/issues/ReproTests.java
@@ -0,0 +1,114 @@
+package org.springframework.issues;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.springframework.context.support.GenericXmlApplicationContext;
+
+/**
+ * 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.
+ */
+public class ReproTests {
+
+ @Test
+ public void singleConstructorNoCharlieNoDelta() {
+ Alpha alpha = createAndRefreshApplicationContext("one-constructor");
+ assertNotNull(alpha.getBravo());
+ }
+
+ @Test
+ public void singleConstructorJustCharlie() {
+ Alpha alpha = createAndRefreshApplicationContext("one-constructor", "charlie");
+ assertJustCharlie(alpha);
+ }
+
+ @Test
+ public void singleConstructorJustDelta() {
+ Alpha alpha = createAndRefreshApplicationContext("one-constructor", "delta");
+ assertJustDelta(alpha);
+ }
+
+ @Test
+ public void singleConstructorCharlieAndDelta() {
+ Alpha alpha = createAndRefreshApplicationContext("one-constructor", "charlie", "delta");
+ assertCharlieAndDelta(alpha);
+ }
+
+ @Test
+ public void twoConstructorsNoCharlieNoDelta() {
+ Alpha alpha = createAndRefreshApplicationContext("two-constructors");
+ assertNotNull(alpha.getBravo());
+ }
+
+ @Test
+ public void twoConstructorsJustCharlie() {
+ Alpha alpha = createAndRefreshApplicationContext("two-constructors", "charlie");
+ assertJustCharlie(alpha);
+ }
+
+ @Test
+ public void twoConstructorsJustDelta() {
+ Alpha alpha = createAndRefreshApplicationContext("two-constructors", "delta");
+ assertJustDelta(alpha);
+ }
+
+ @Test
+ public void twoConstructorsCharlieAndDelta() {
+ Alpha alpha = createAndRefreshApplicationContext("two-constructors", "charlie", "delta");
+ assertCharlieAndDelta(alpha);
+ }
+
+ @Test
+ public void fourConstructorsNoCharlieNoDelta() {
+ Alpha alpha = createAndRefreshApplicationContext("four-constructors");
+ assertNotNull(alpha.getBravo());
+ }
+
+ @Test
+ public void fourConstructorsJustCharlie() {
+ Alpha alpha = createAndRefreshApplicationContext("four-constructors", "charlie");
+ assertJustCharlie(alpha);
+ }
+
+ @Test
+ public void fourConstructorsJustDelta() {
+ Alpha alpha = createAndRefreshApplicationContext("four-constructors", "delta");
+ assertJustDelta(alpha);
+ }
+
+ @Test
+ public void fourConstructorsCharlieAndDelta() {
+ Alpha alpha = createAndRefreshApplicationContext("four-constructors", "charlie", "delta");
+ assertCharlieAndDelta(alpha);
+ }
+
+ private void assertJustDelta(Alpha alpha) {
+ assertNotNull(alpha.getBravo());
+ assertNotNull(alpha.getDelta());
+ assertEquals(1, alpha.getDelta().size());
+ }
+
+ private void assertJustCharlie(Alpha alpha) {
+ assertNotNull(alpha.getBravo());
+ assertNotNull(alpha.getCharlie());
+ assertEquals(1, alpha.getCharlie().size());
+ }
+
+ private void assertCharlieAndDelta(Alpha alpha) {
+ assertJustCharlie(alpha);
+ assertNotNull(alpha.getDelta());
+ assertEquals(1, alpha.getDelta().size());
+ }
+
+ private Alpha createAndRefreshApplicationContext(String... profiles) {
+ GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
+ ctx.getEnvironment().setActiveProfiles(profiles);
+ ctx.load("classpath:org/springframework/issues/ReproTests-context.xml");
+ ctx.refresh();
+
+ return ctx.getBean(Alpha.class);
+ }
+}
View
7 SPR-9155/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
View
32 SPR-9155/src/test/resources/org/springframework/issues/ReproTests-context.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
+
+ <context:annotation-config/>
+
+ <bean class="org.springframework.issues.Bravo"/>
+
+ <beans profile="one-constructor">
+ <bean class="org.springframework.issues.OneConstructorAlpha"/>
+ </beans>
+
+ <beans profile="two-constructors">
+ <bean class="org.springframework.issues.TwoConstructorsAlpha"/>
+ </beans>
+
+ <beans profile="four-constructors">
+ <bean class="org.springframework.issues.FourConstructorsAlpha"/>
+ </beans>
+
+ <beans profile="charlie">
+ <bean class="org.springframework.issues.Charlie"/>
+ </beans>
+
+ <beans profile="delta">
+ <bean class="org.springframework.issues.Delta"/>
+ </beans>
+
+</beans>

0 comments on commit d2ca864

Please sign in to comment.
Something went wrong with that request. Please try again.