polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject polygene-java git commit: POLYGENE-251 - Testcase for Generic Concerns and Generic SideEffects.
Date Mon, 15 May 2017 12:59:10 GMT
Repository: polygene-java
Updated Branches:
  refs/heads/develop 49555b45c -> 339784cf4


POLYGENE-251 - Testcase for Generic Concerns and Generic SideEffects.

Signed-off-by: niclas <niclas@hedhman.org>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/339784cf
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/339784cf
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/339784cf

Branch: refs/heads/develop
Commit: 339784cf4efdb60431de1831cf6b43835056670a
Parents: 49555b4
Author: niclas <niclas@hedhman.org>
Authored: Mon May 15 20:58:54 2017 +0800
Committer: niclas <niclas@hedhman.org>
Committed: Mon May 15 20:59:06 2017 +0800

----------------------------------------------------------------------
 .../api/composite/DefaultMethodsFilter.java     | 17 ++++
 .../composite/InterfaceDefaultMethodsMixin.java | 17 +---
 .../composite/InterfaceDefaultMethodsTest.java  | 82 +++++++++++++++++++-
 3 files changed, 100 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/339784cf/core/api/src/main/java/org/apache/polygene/api/composite/DefaultMethodsFilter.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/composite/DefaultMethodsFilter.java
b/core/api/src/main/java/org/apache/polygene/api/composite/DefaultMethodsFilter.java
new file mode 100644
index 0000000..e7c0b2e
--- /dev/null
+++ b/core/api/src/main/java/org/apache/polygene/api/composite/DefaultMethodsFilter.java
@@ -0,0 +1,17 @@
+package org.apache.polygene.api.composite;
+
+import java.lang.reflect.Method;
+import org.apache.polygene.api.common.AppliesToFilter;
+
+/**
+ * Filter Default Interface Methods to apply a generic fragment.
+ */
+public class DefaultMethodsFilter
+    implements AppliesToFilter
+{
+    @Override
+    public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType,
Class<?> modifierClass )
+    {
+        return method.isDefault();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/339784cf/core/runtime/src/main/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsMixin.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsMixin.java
b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsMixin.java
index b150a86..cb2875f 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsMixin.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsMixin.java
@@ -26,11 +26,11 @@ import java.lang.reflect.Method;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import org.apache.polygene.api.common.AppliesTo;
-import org.apache.polygene.api.common.AppliesToFilter;
 import org.apache.polygene.api.composite.Composite;
+import org.apache.polygene.api.composite.DefaultMethodsFilter;
 import org.apache.polygene.api.injection.scope.This;
 
-@AppliesTo( { InterfaceDefaultMethodsMixin.DefaultMethodsFilter.class } )
+@AppliesTo( { DefaultMethodsFilter.class } )
 public class InterfaceDefaultMethodsMixin
     implements InvocationHandler
 {
@@ -54,19 +54,6 @@ public class InterfaceDefaultMethodsMixin
         return method.invoke( me, args );
     }
 
-    /**
-     * Filter Default Interface Methods to apply generic Mixin.
-     */
-    public static class DefaultMethodsFilter
-        implements AppliesToFilter
-    {
-        @Override
-        public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType,
Class<?> modifierClass )
-        {
-            return method.isDefault();
-        }
-    }
-
     private MethodCallHandler forMethod( Method method )
     {
         return methodHandleCache.computeIfAbsent( method, this::createMethodCallHandler );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/339784cf/core/runtime/src/test/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsTest.java
b/core/runtime/src/test/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsTest.java
index 5a57a82..806f981 100644
--- a/core/runtime/src/test/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsTest.java
+++ b/core/runtime/src/test/java/org/apache/polygene/runtime/composite/InterfaceDefaultMethodsTest.java
@@ -17,7 +17,11 @@
  */
 package org.apache.polygene.runtime.composite;
 
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import org.apache.polygene.api.common.AppliesTo;
 import org.apache.polygene.api.common.UseDefaults;
+import org.apache.polygene.api.composite.DefaultMethodsFilter;
 import org.apache.polygene.api.concern.ConcernOf;
 import org.apache.polygene.api.concern.Concerns;
 import org.apache.polygene.api.constraint.ConstraintViolationException;
@@ -102,6 +106,36 @@ public class InterfaceDefaultMethodsTest extends AbstractPolygeneTest
         }
     }
 
+    @Concerns( DefaultMethodsGenericConcern.class )
+    public interface DefaultMethodsGenericConcerns extends DefaultMethods
+    {
+        @Override
+        default String sayHello( String name )
+        {
+            return greeting().get() + ", " + name + '!';
+        }
+
+        default String sayGoodBye( String name )
+        {
+            return "Good Bye, " + name + '!';
+        }
+    }
+
+    @AppliesTo( DefaultMethodsFilter.class )
+    public static class DefaultMethodsGenericConcern extends ConcernOf<InvocationHandler>
+        implements InvocationHandler
+    {
+        static int count = 0;
+
+        @Override
+        public Object invoke( Object o, Method method, Object[] objects )
+            throws Throwable
+        {
+            count++;
+            return next.invoke( o, method, objects );
+        }
+    }
+
     @SideEffects( DefaultMethodsSideEffect.class )
     public interface DefaultMethodsSideEffects extends DefaultMethods
     {
@@ -125,6 +159,31 @@ public class InterfaceDefaultMethodsTest extends AbstractPolygeneTest
         }
     }
 
+    @SideEffects( DefaultMethodsGenericSideEffect.class )
+    public interface DefaultMethodsGenericSideEffects extends DefaultMethods
+    {
+        @Override
+        default String sayHello( String name )
+        {
+            return greeting().get() + ", " + name + '!';
+        }
+    }
+
+    @AppliesTo( DefaultMethodsFilter.class )
+    public static class DefaultMethodsGenericSideEffect extends SideEffectOf<InvocationHandler>
+        implements InvocationHandler
+    {
+        static int count = 0;
+
+        @Override
+        public Object invoke( Object o, Method method, Object[] objects )
+            throws Throwable
+        {
+            count++;
+            return null;
+        }
+    }
+
     @Override
     public void assemble( final ModuleAssembly module )
         throws AssemblyException
@@ -134,7 +193,9 @@ public class InterfaceDefaultMethodsTest extends AbstractPolygeneTest
                            MixinDefaultMethods.class,
                            DefaultMethodsConstraints.class,
                            DefaultMethodsConcerns.class,
-                           DefaultMethodsSideEffects.class
+                           DefaultMethodsSideEffects.class,
+                           DefaultMethodsGenericConcerns.class,
+                           DefaultMethodsGenericSideEffects.class
                          );
     }
 
@@ -182,6 +243,15 @@ public class InterfaceDefaultMethodsTest extends AbstractPolygeneTest
     }
 
     @Test
+    public void defaultMethodsGenericConcerns()
+    {
+        DefaultMethodsGenericConcerns composite = transientBuilderFactory.newTransient( DefaultMethodsGenericConcerns.class
);
+        assertThat( composite.sayHello( "John" ), equalTo( "Hello, John!" ) );
+        assertThat( composite.sayGoodBye( "John" ), equalTo( "Good Bye, John!" ) );
+        assertThat( DefaultMethodsGenericConcern.count, equalTo( 2 ) );
+    }
+
+    @Test
     public void defaultMethodsSideEffects()
     {
         DefaultMethodsSideEffects composite = transientBuilderFactory.newTransient( DefaultMethodsSideEffects.class
);
@@ -190,4 +260,14 @@ public class InterfaceDefaultMethodsTest extends AbstractPolygeneTest
         assertThat( composite.sayHello( "John" ), equalTo( "Hello, John!" ) );
         assertThat( DefaultMethodsSideEffect.count, equalTo( 3 ) );
     }
+
+    @Test
+    public void defaultMethodsGenericSideEffects()
+    {
+        DefaultMethodsGenericSideEffects composite = transientBuilderFactory.newTransient(
DefaultMethodsGenericSideEffects.class );
+        assertThat( composite.sayHello( "John" ), equalTo( "Hello, John!" ) );
+        assertThat( composite.sayHello( "John" ), equalTo( "Hello, John!" ) );
+        assertThat( composite.sayHello( "John" ), equalTo( "Hello, John!" ) );
+        assertThat( DefaultMethodsGenericSideEffect.count, equalTo( 3 ) );
+    }
 }


Mime
View raw message