deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject deltaspike git commit: DELTASPIKE-1297 added test with a customized DynamicMockManager
Date Tue, 31 Oct 2017 18:28:35 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master edeff80a2 -> 38bc9c3d3


DELTASPIKE-1297 added test with a customized DynamicMockManager


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

Branch: refs/heads/master
Commit: 38bc9c3d340b17410b4fc2a1ce45d77981b366e5
Parents: edeff80
Author: gpetracek <gpetracek@apache.org>
Authored: Tue Oct 31 19:27:20 2017 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Tue Oct 31 19:27:20 2017 +0100

----------------------------------------------------------------------
 .../test/testcontrol/CustomMockManager.java     | 36 ++++++++
 .../testcontrol/InternalTestMockFilter.java     |  4 +-
 .../mock/uc016/CustomMockManagerTest.java       | 87 ++++++++++++++++++++
 .../impl/src/test/resources/META-INF/beans.xml  |  4 +
 4 files changed, 130 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/38bc9c3d/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/CustomMockManager.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/CustomMockManager.java
b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/CustomMockManager.java
new file mode 100644
index 0000000..3817870
--- /dev/null
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/CustomMockManager.java
@@ -0,0 +1,36 @@
+package org.apache.deltaspike.test.testcontrol;
+
+import org.apache.deltaspike.testcontrol.api.mock.DynamicMockManager;
+import org.apache.deltaspike.testcontrol.impl.mock.SimpleMockManager;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.Typed;
+import java.lang.annotation.Annotation;
+
+@Alternative
+
+@RequestScoped
+@Typed(DynamicMockManager.class)
+public class CustomMockManager extends SimpleMockManager
+{
+    private static boolean isCalled;
+
+    @Override
+    public <T> T getMock(Class<T> beanClass, Annotation... qualifiers)
+    {
+        isCalled = true;
+
+        return super.getMock(beanClass, qualifiers);
+    }
+
+    public static boolean isIsCalled()
+    {
+        return isCalled;
+    }
+
+    public static void resetInternals()
+    {
+        isCalled = false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/38bc9c3d/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/InternalTestMockFilter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/InternalTestMockFilter.java
b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/InternalTestMockFilter.java
index 242fbcf..f333bfd 100644
--- a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/InternalTestMockFilter.java
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/InternalTestMockFilter.java
@@ -26,6 +26,8 @@ public class InternalTestMockFilter extends DefaultMockFilter
 
     protected boolean isInternalPackage(String packageName)
     {
-        return super.isInternalPackage(packageName) && !packageName.startsWith(DS_TEST_BASE_PACKAGE);
+        return super.isInternalPackage(packageName) &&
+                (!packageName.startsWith(DS_TEST_BASE_PACKAGE) ||
+                    packageName.equals(CustomMockManager.class.getPackage().getName()));
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/38bc9c3d/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/mock/uc016/CustomMockManagerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/mock/uc016/CustomMockManagerTest.java
b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/mock/uc016/CustomMockManagerTest.java
new file mode 100644
index 0000000..1f94f37
--- /dev/null
+++ b/deltaspike/modules/test-control/impl/src/test/java/org/apache/deltaspike/test/testcontrol/mock/uc016/CustomMockManagerTest.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.testcontrol.mock.uc016;
+
+import org.apache.deltaspike.test.category.SeCategory;
+import org.apache.deltaspike.test.testcontrol.CustomMockManager;
+import org.apache.deltaspike.test.testcontrol.mock.shared.RequestScopedBean;
+import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner;
+import org.apache.deltaspike.testcontrol.api.mock.DynamicMockManager;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import javax.inject.Inject;
+
+//Usually NOT needed! Currently only needed due to our arquillian-setup
+@Category(SeCategory.class)
+
+@RunWith(CdiTestRunner.class)
+//same base logic as uc001 + a manual check of CustomMockManager
+public class CustomMockManagerTest
+{
+    @Inject
+    private RequestScopedBean requestScopedBean;
+
+    @Inject
+    private DynamicMockManager mockManager;
+
+    @Test
+    public void manualMock1()
+    {
+        CustomMockManager.resetInternals();
+
+        mockManager.addMock(new RequestScopedBean()
+        {
+            @Override
+            public int getCount()
+            {
+                return 7;
+            }
+        });
+
+        Assert.assertEquals(7, requestScopedBean.getCount());
+        requestScopedBean.increaseCount();
+        Assert.assertEquals(7, requestScopedBean.getCount());
+
+        Assert.assertTrue(CustomMockManager.isIsCalled());
+    }
+
+    @Test
+    public void manualMock2() //same test with different mock
+    {
+        CustomMockManager.resetInternals();
+
+        mockManager.addMock(new RequestScopedBean()
+        {
+            @Override
+            public int getCount()
+            {
+                return 14;
+            }
+        });
+
+        Assert.assertEquals(14, requestScopedBean.getCount());
+        requestScopedBean.increaseCount();
+        Assert.assertEquals(14, requestScopedBean.getCount());
+
+        Assert.assertTrue(CustomMockManager.isIsCalled());
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/38bc9c3d/deltaspike/modules/test-control/impl/src/test/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/test/resources/META-INF/beans.xml b/deltaspike/modules/test-control/impl/src/test/resources/META-INF/beans.xml
index e7b84c7..2b5d7ba 100644
--- a/deltaspike/modules/test-control/impl/src/test/resources/META-INF/beans.xml
+++ b/deltaspike/modules/test-control/impl/src/test/resources/META-INF/beans.xml
@@ -24,4 +24,8 @@
         <class>org.apache.deltaspike.test.testcontrol.uc011.TestInterceptorImplementation</class>
         <class>org.apache.deltaspike.test.testcontrol.mock.uc015.TestInterceptorImplementation</class>
     </interceptors>
+
+    <alternatives>
+        <class>org.apache.deltaspike.test.testcontrol.CustomMockManager</class>
+    </alternatives>
 </beans>


Mime
View raw message