Permalink
Browse files

Add main method proving that JUnit is the root cause

  • Loading branch information...
1 parent 8e0c537 commit 69ce19a2f5c299d203627dcd2bd75f0093fa14a4 @cbeams cbeams committed Jul 21, 2011
Showing with 31 additions and 0 deletions.
  1. +2 −0 SPR-8502/README.markdown
  2. +29 −0 SPR-8502/src/test/java/poc/configurable/ServiceInjectionMain.java
View
2 SPR-8502/README.markdown
@@ -9,3 +9,5 @@ You'll notice in the pom that tests are being run with
-javaagent:/path/to/org.springframework.instrument.jar
Examine the small application and the assertion in ServiceInjectionTests and you'll see that Entity is a @Configurable and uses @Autowired to receive injection of a Service. The assertion shows that this injection fails when `someMethod(Entity)` is present in ServiceInjectionTests. If this method is commented out or placed within any other type in the application, the injection occurs as expected and the test passes.
+
+See https://jira.springsource.org/browse/SPR-8502 for analysis of the causes of this problem
View
29 SPR-8502/src/test/java/poc/configurable/ServiceInjectionMain.java
@@ -0,0 +1,29 @@
+package poc.configurable;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import org.springframework.context.support.GenericXmlApplicationContext;
+
+/**
+ * For comparison with {@link ServiceInjectionTests}, proving that the same
+ * code run from a main method does not exhibit the weaving failure that
+ * occurrs when running from a JUnit @Test method.
+ */
+public class ServiceInjectionMain {
+
+ public static void main(String... args) {
+ new GenericXmlApplicationContext("/application-context.xml");
+
+ // Entity should now be enhanced
+ Entity entity = new Entity();
+ assertThat("service was not injected into @Configurable entity",
+ entity.getService(), notNullValue());
+ }
+
+ /**
+ * When uncommented, this method interferes with weaving such that Entity does not
+ * get injected with its @Autowired Service.
+ */
+ void someMethod(Entity entity) { }
+}

0 comments on commit 69ce19a

Please sign in to comment.