deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject [1/2] git commit: DELTASPIKE-342 improved support for @Before and @After
Date Thu, 30 Jan 2014 10:09:34 GMT
Updated Branches:
  refs/heads/master 2bfcd3130 -> 2d44e7d29


DELTASPIKE-342 improved support for @Before and @After


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/2d44e7d2
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/2d44e7d2
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/2d44e7d2

Branch: refs/heads/master
Commit: 2d44e7d2980f8ab0b0a2a388255c0f0944c85098
Parents: 9367a51
Author: gpetracek <gpetracek@apache.org>
Authored: Thu Jan 30 10:59:38 2014 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Thu Jan 30 11:09:21 2014 +0100

----------------------------------------------------------------------
 .../testcontrol/api/junit/CdiTestRunner.java         | 15 +++++++++++++--
 .../uc008/BeforeAndAfterInjectionTest.java           |  9 +++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2d44e7d2/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
index 33564a6..04c321f 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
@@ -21,6 +21,7 @@ package org.apache.deltaspike.testcontrol.api.junit;
 import org.apache.deltaspike.cdise.api.CdiContainer;
 import org.apache.deltaspike.cdise.api.CdiContainerLoader;
 import org.apache.deltaspike.cdise.api.ContextControl;
+import org.apache.deltaspike.core.api.config.ConfigResolver;
 import org.apache.deltaspike.core.api.projectstage.ProjectStage;
 import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
 import org.apache.deltaspike.core.api.provider.BeanProvider;
@@ -64,8 +65,18 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
 {
     private static final Logger LOGGER = Logger.getLogger(CdiTestRunner.class.getName());
 
+    private static final boolean USE_TEST_CLASS_AS_CDI_BEAN;
+
     private static Set<Integer> notifierIdentities = new CopyOnWriteArraySet<Integer>();
 
+    static
+    {
+        //default is false to improve the compatibility with @Before and @After
+        String useTestClassAsCdiBeanValue =
+                ConfigResolver.getPropertyValue("deltaspike.testcontrol.use_test_class_as_cdi_bean",
"false");
+        USE_TEST_CLASS_AS_CDI_BEAN = Boolean.parseBoolean(useTestClassAsCdiBeanValue);
+    }
+
     private List<TestStatementDecoratorFactory> statementDecoratorFactories;
 
     private ContainerAwareTestContext testContext;
@@ -163,7 +174,7 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
         Set<Bean<?>> beans = beanManager.getBeans(type);
 
         Object result;
-        if (beans == null || beans.isEmpty())
+        if (!USE_TEST_CLASS_AS_CDI_BEAN || beans == null || beans.isEmpty())
         {
             result = super.createTest();
             BeanProvider.injectFields(result); //fallback to simple injection
@@ -279,7 +290,7 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
             Class<?> type = this.method.getMethod().getDeclaringClass();
             Set<Bean<?>> beans = beanManager.getBeans(type);
 
-            if (beans == null || beans.isEmpty())
+            if (!USE_TEST_CLASS_AS_CDI_BEAN || beans == null || beans.isEmpty())
             {
                 BeanProvider.injectFields(this.originalTarget); //fallback to simple injection
                 invokeMethod(this.originalTarget);

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2d44e7d2/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc008/BeforeAndAfterInjectionTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc008/BeforeAndAfterInjectionTest.java
b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc008/BeforeAndAfterInjectionTest.java
index 007c6a2..fb215cf 100644
--- a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc008/BeforeAndAfterInjectionTest.java
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/uc008/BeforeAndAfterInjectionTest.java
@@ -41,6 +41,8 @@ public class BeforeAndAfterInjectionTest
     @Inject
     private ApplicationScopedBean applicationScopedBean;
 
+    private Integer foundValue;
+
     @Before
     public void before()
     {
@@ -48,12 +50,15 @@ public class BeforeAndAfterInjectionTest
         {
             throw new IllegalStateException("injection failed");
         }
+
+        this.foundValue = this.applicationScopedBean.getCount();
     }
 
     @Test
     public void injectionTest()
     {
         Assert.assertNotNull(this.applicationScopedBean);
+        Assert.assertNotNull(this.foundValue);
     }
 
     @After
@@ -63,5 +68,9 @@ public class BeforeAndAfterInjectionTest
         {
             throw new IllegalStateException("injection failed");
         }
+        if (this.foundValue == null)
+        {
+            throw new IllegalStateException("different instance without initialized value
found");
+        }
     }
 }


Mime
View raw message