You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2012/06/21 02:34:12 UTC

[3/4] git commit: Convert TestNG to Spock`

Convert TestNG to Spock`


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/73e4d969
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/73e4d969
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/73e4d969

Branch: refs/heads/master
Commit: 73e4d969f5f0837dbf578baff6e7ced06d6202c0
Parents: 57ce245
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed Jun 20 16:52:34 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed Jun 20 16:52:34 2012 -0700

----------------------------------------------------------------------
 .../tapestry5/ioc/util/GenericUtilsSpec.groovy     |   40 ++++++++++
 .../ioc/internal/util/GenericUtilsTest.java        |   61 ---------------
 2 files changed, 40 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/73e4d969/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/GenericUtilsSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/GenericUtilsSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/GenericUtilsSpec.groovy
new file mode 100644
index 0000000..1f279c8
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/GenericUtilsSpec.groovy
@@ -0,0 +1,40 @@
+package org.apache.tapestry5.ioc.util
+
+import org.apache.tapestry5.ioc.internal.util.GenericsUtils
+import org.apache.tapestry5.ioc.internal.util.NonGenericBean
+import org.apache.tapestry5.ioc.internal.util.StringBean
+import org.apache.tapestry5.ioc.internal.util.StringLongPair
+import spock.lang.Specification
+import spock.lang.Unroll
+
+class GenericUtilsSpec extends Specification {
+
+  def find(clazz, name) {
+    def method = clazz.methods.find { it.name.equalsIgnoreCase(name) }
+
+    if (method == null) {
+      throw new IllegalArgumentException("Unable to find method '$name' of ${clazz.name}.")
+    }
+
+    return method
+  }
+
+  @Unroll
+  def "generic return type for #method is #expected"() {
+
+    expect:
+
+    GenericsUtils.extractGenericReturnType(clazz, method).is(expected)
+
+    where:
+
+    clazz          | name       | expected
+    NonGenericBean | "getvalue" | String
+    StringBean     | "getvalue" | String
+    StringLongPair | "getkey"   | String
+    StringLongPair | "getvalue" | Long
+
+    method = find(clazz, name)
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/73e4d969/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/GenericUtilsTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/GenericUtilsTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/GenericUtilsTest.java
deleted file mode 100644
index 5223868..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/GenericUtilsTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2008 The Apache Software Foundation
-//
-// Licensed 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.tapestry5.ioc.internal.util;
-
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import java.lang.reflect.Method;
-
-public class GenericUtilsTest extends Assert
-{
-    protected Method find(Class clazz, String name)
-    {
-        for (Method m : clazz.getMethods())
-        {
-            if (m.getName().equalsIgnoreCase(name)) return m;
-        }
-
-        throw new IllegalArgumentException(
-                String.format("Could not locate a public method named '%s' in %s.", name, clazz));
-
-    }
-
-    @Test
-    public void generic_return_type_of_non_generic_type()
-    {
-        Method m = find(NonGenericBean.class, "getvalue");
-
-        assertSame(GenericsUtils.extractGenericReturnType(NonGenericBean.class, m), String.class);
-    }
-
-    @Test
-    public void generic_return_type_of_parameterized_bean()
-    {
-        Method m = find(StringBean.class, "getvalue");
-
-        assertSame(GenericsUtils.extractGenericReturnType(StringBean.class, m), String.class);
-    }
-
-    @Test
-    public void generic_bean_with_multiple_parameters()
-    {
-        Method getKey = find(StringLongPair.class, "getkey");
-        Method getValue = find(StringLongPair.class, "getvalue");
-
-        assertSame(GenericsUtils.extractGenericReturnType(StringLongPair.class, getKey), String.class);
-        assertSame(GenericsUtils.extractGenericReturnType(StringLongPair.class, getValue), Long.class);
-    }
-}