Repository: incubator-tamaya-extensions
Updated Branches:
  refs/heads/master 9bdbac3ed -> 22c0faaf9


[TAMAYA-291] Implemented ConfiguredMethod#getSignature(). Tests included.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/22c0faaf
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/22c0faaf
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/22c0faaf

Branch: refs/heads/master
Commit: 22c0faaf94fade8abf926803153a0f9a54c3a134
Parents: 9bdbac3
Author: Oliver B. Fischer <[email protected]>
Authored: Sun Oct 1 22:12:08 2017 +0200
Committer: Oliver B. Fischer <[email protected]>
Committed: Sun Oct 1 22:12:08 2017 +0200

----------------------------------------------------------------------
 .../apache/tamaya/cdi/CDIConfiguredMethod.java  |  15 ++-
 .../tamaya/cdi/CDIConfiguredMethodTest.java     | 130 +++++++++++++++++--
 .../test/java/org/apache/tamaya/cdi/Klazz.java  |  59 +++++++++
 .../java/org/apache/tamaya/cdi/OtherKlazz.java  |  21 +++
 .../tamaya/inject/spi/ConfiguredMethod.java     |   2 +-
 5 files changed, 216 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/22c0faaf/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/CDIConfiguredMethod.java
----------------------------------------------------------------------
diff --git 
a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/CDIConfiguredMethod.java
 
b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/CDIConfiguredMethod.java
index e7f30f5..c38fc23 100644
--- 
a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/CDIConfiguredMethod.java
+++ 
b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/CDIConfiguredMethod.java
@@ -26,6 +26,8 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
+import static java.lang.String.format;
+
 /**
  * Implementation of a configured methods for CDI module.
  */
@@ -62,7 +64,18 @@ public class CDIConfiguredMethod implements ConfiguredMethod{
 
     @Override
     public String getSignature() {
-        return null;
+        String className = getAnnotatedMethod().getDeclaringClass().getName();
+        String methodName = getAnnotatedMethod().getName();
+        String anchor = format(".%s(", methodName);
+
+        StringBuilder sb = new StringBuilder();
+        sb.append(getAnnotatedMethod().toGenericString());
+
+        int anchorStart = sb.indexOf(anchor);
+
+        sb.delete(anchorStart - className.length(), anchorStart + 1);
+
+        return sb.toString();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/22c0faaf/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredMethodTest.java
----------------------------------------------------------------------
diff --git 
a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredMethodTest.java
 
b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredMethodTest.java
index 1818c5b..27d1a5c 100644
--- 
a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredMethodTest.java
+++ 
b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredMethodTest.java
@@ -23,7 +23,9 @@ import org.junit.Test;
 import org.mockito.Mockito;
 
 import javax.enterprise.inject.spi.InjectionPoint;
+import java.io.File;
 import java.lang.reflect.Method;
+import java.util.Collection;
 import java.util.List;
 
 import static java.util.Arrays.asList;
@@ -56,19 +58,129 @@ public class CDIConfiguredMethodTest {
         assertThat(ccm.getName(), equalTo("getValue"));
     }
 
-    public static class Klazz {
-        private OtherKlazz<String> value;
+    @Test
+    public void returnsCorrectSignatureOfTheGivenMethod1() throws Exception {
+        String expectedSignature = "public 
org.apache.tamaya.cdi.OtherKlazz<java.lang.String> getValue()";
+
+        Method method = Klazz.class.getMethod("getValue");
+        List<String> keys = asList("rate", "weight");
+        InjectionPoint ip = Mockito.mock(InjectionPoint.class);
+
+        when(ip.getMember()).thenReturn(method);
+
+        CDIConfiguredMethod ccm = new CDIConfiguredMethod(ip, keys);
+
+        assertThat(ccm.getSignature(), equalTo(expectedSignature));
+    }
+
+    @Test
+    public void returnsCorrectSignatureOfTheGivenMethod2() throws Exception {
+        String expectedSignature = "public int getPrimitiveIntValue()";
+
+        Method method = Klazz.class.getMethod("getPrimitiveIntValue");
+        List<String> keys = asList("rate", "weight");
+        InjectionPoint ip = Mockito.mock(InjectionPoint.class);
+
+        when(ip.getMember()).thenReturn(method);
+
+        CDIConfiguredMethod ccm = new CDIConfiguredMethod(ip, keys);
+
+        assertThat(ccm.getSignature(), equalTo(expectedSignature));
+    }
+
+    @Test
+    public void returnsCorrectSignatureOfTheGivenMethodReturnTypeIsVoid() 
throws Exception {
+        String expectedSignature = "public void voidMethod()";
+
+        Method method = Klazz.class.getMethod("voidMethod");
+        List<String> keys = asList("rate", "weight");
+        InjectionPoint ip = Mockito.mock(InjectionPoint.class);
+
+        when(ip.getMember()).thenReturn(method);
+
+        CDIConfiguredMethod ccm = new CDIConfiguredMethod(ip, keys);
+
+        assertThat(ccm.getSignature(), equalTo(expectedSignature));
+    }
+
+    @Test
+    public void returnsCorrectSignatureOfTheGivenMethodWithExceptions() throws 
Exception {
+        String expectedSignature = "public void methodWithExceptions() " +
+                                   "throws java.io.FileNotFoundException," +
+                                   "java.nio.file.AccessDeniedException";
+
+        Method method = Klazz.class.getMethod("methodWithExceptions");
+        List<String> keys = asList("rate", "weight");
+        InjectionPoint ip = Mockito.mock(InjectionPoint.class);
+
+        when(ip.getMember()).thenReturn(method);
+
+        CDIConfiguredMethod ccm = new CDIConfiguredMethod(ip, keys);
 
-        public OtherKlazz<String> getValue() {
-            return value;
-        }
+        assertThat(ccm.getSignature(), equalTo(expectedSignature));
+    }
+
+    @Test
+    public void returnsCorrectSignatureOfTheGivenMethodWithOneException() 
throws Exception {
+        String expectedSignature = "public void methodWithException() " +
+                                   "throws java.io.FileNotFoundException";
+
+        Method method = Klazz.class.getMethod("methodWithException");
+        List<String> keys = asList("rate", "weight");
+        InjectionPoint ip = Mockito.mock(InjectionPoint.class);
+
+        when(ip.getMember()).thenReturn(method);
+
+        CDIConfiguredMethod ccm = new CDIConfiguredMethod(ip, keys);
+
+        assertThat(ccm.getSignature(), equalTo(expectedSignature));
+    }
+
+    @Test
+    public void returnsCorrectSignatureOfTheGivenMethodWithOneParameter() 
throws Exception {
+        String expectedSignature = "public void 
methodWithOneParameter(java.lang.String)";
+
+        Method method = Klazz.class.getMethod("methodWithOneParameter", 
String.class);
+        List<String> keys = asList("rate", "weight");
+        InjectionPoint ip = Mockito.mock(InjectionPoint.class);
+
+        when(ip.getMember()).thenReturn(method);
+
+        CDIConfiguredMethod ccm = new CDIConfiguredMethod(ip, keys);
 
-        public void setValue(OtherKlazz<String> value) {
-            this.value = value;
-        }
+        assertThat(ccm.getSignature(), equalTo(expectedSignature));
     }
 
-    public static class OtherKlazz<T> {
+    @Test
+    public void returnsCorrectSignatureOfTheGivenMethodWithTwoParameters() 
throws Exception {
+        String expectedSignature = "public void 
methodWithTwoParameters(java.lang.String,java.io.File)";
+
+        Method method = Klazz.class.getMethod("methodWithTwoParameters", 
String.class, File.class);
+        List<String> keys = asList("rate", "weight");
+        InjectionPoint ip = Mockito.mock(InjectionPoint.class);
+
+        when(ip.getMember()).thenReturn(method);
 
+        CDIConfiguredMethod ccm = new CDIConfiguredMethod(ip, keys);
+
+        assertThat(ccm.getSignature(), equalTo(expectedSignature));
     }
+
+    @Test
+    public void returnsCorrectSignatureOfTheGivenMethodWithOneTypeParameter() 
throws Exception {
+        String expectedSignature = "public <T> java.util.Collection<T> 
methodWithTypeParameter" +
+                                   "(java.util.Collection<T>)";
+
+        Method method = Klazz.class.getMethod("methodWithTypeParameter", 
Collection.class);
+
+        List<String> keys = asList("rate", "weight");
+        InjectionPoint ip = Mockito.mock(InjectionPoint.class);
+
+        when(ip.getMember()).thenReturn(method);
+
+        CDIConfiguredMethod ccm = new CDIConfiguredMethod(ip, keys);
+
+        assertThat(ccm.getSignature(), equalTo(expectedSignature));
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/22c0faaf/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/Klazz.java
----------------------------------------------------------------------
diff --git 
a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/Klazz.java 
b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/Klazz.java
new file mode 100644
index 0000000..c597547
--- /dev/null
+++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/Klazz.java
@@ -0,0 +1,59 @@
+/*
+ * 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.tamaya.cdi;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.nio.file.AccessDeniedException;
+import java.util.Collection;
+import java.util.Collections;
+
+public class Klazz {
+    private OtherKlazz<String> value;
+
+    public <T> Collection<T> methodWithTypeParameter(Collection<T> in) {
+        return Collections.emptyList();
+    }
+
+    public void methodWithOneParameter(String p) {
+    }
+
+    public void methodWithTwoParameters(String p, File f) {
+    }
+
+    public void voidMethod() {
+    }
+
+    public int getPrimitiveIntValue() {
+        return 1;
+    }
+
+    public OtherKlazz<String> getValue() {
+        return value;
+    }
+
+    public void setValue(OtherKlazz<String> value) {
+        this.value = value;
+    }
+
+    public void methodWithExceptions() throws FileNotFoundException, 
AccessDeniedException {
+    }
+
+    public void methodWithException() throws FileNotFoundException {
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/22c0faaf/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/OtherKlazz.java
----------------------------------------------------------------------
diff --git 
a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/OtherKlazz.java 
b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/OtherKlazz.java
new file mode 100644
index 0000000..6777be1
--- /dev/null
+++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/OtherKlazz.java
@@ -0,0 +1,21 @@
+/*
+ * 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.tamaya.cdi;
+
+public class OtherKlazz<T> {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/22c0faaf/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java
----------------------------------------------------------------------
diff --git 
a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java
 
b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java
index 128946e..d8b0d09 100644
--- 
a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java
+++ 
b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java
@@ -54,7 +54,7 @@ public interface ConfiguredMethod {
 
     /**
      * Get the methods signature, e.g. {@code void setName(String)}.
-     * @return he signature, never null.
+     * @return the signature, never {@code null}.
      */
     String getSignature();
 

Reply via email to