You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2012/05/16 20:50:32 UTC

[37/44] 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/d76df134
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/d76df134
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/d76df134

Branch: refs/heads/master
Commit: d76df13494383d22b7f351957b796b1fc3f8710e
Parents: a548a76
Author: Howard M. Lewis Ship <hl...@gmail.com>
Authored: Fri Apr 20 17:20:38 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 16 11:49:41 2012 -0700

----------------------------------------------------------------------
 .../services/ClassNameLocatorImplSpec.groovy       |   74 ++++++++
 .../services/ClassNameLocatorImplTest.java         |  136 ---------------
 2 files changed, 74 insertions(+), 136 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d76df134/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ClassNameLocatorImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ClassNameLocatorImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ClassNameLocatorImplSpec.groovy
new file mode 100644
index 0000000..7744ae4
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ClassNameLocatorImplSpec.groovy
@@ -0,0 +1,74 @@
+package org.apache.tapestry5.ioc.internal.services
+
+import org.apache.tapestry5.ioc.services.ClassNameLocator
+import spock.lang.Specification
+
+class ClassNameLocatorImplSpec extends Specification {
+
+  ClassNameLocator locator = new ClassNameLocatorImpl(new ClasspathURLConverterImpl());
+
+  def assertInList(classNames, packageName, String... expectedNames) {
+
+    expectedNames.each { name ->
+      String qualifiedName = "${packageName}.${name}"
+
+      assert classNames.contains(qualifiedName), "[$qualifiedName] not present in ${classNames.join(', ')}."
+    }
+  }
+
+  def assertNotInList(classNames, packageName, String... expectedNames) {
+
+    expectedNames.each { name ->
+      String qualifiedName = "${packageName}.${name}"
+
+      assert !classNames.contains(qualifiedName), "[$qualifiedName] should not be present in ${classNames.join(', ')}."
+    }
+  }
+
+  def "locate classes inside a JAR file on the classpath"() {
+
+    expect:
+
+    assertInList locator.locateClassNames("javax.inject"),
+        "javax.inject",
+        "Inject", "Named", "Singleton"
+  }
+
+  def "can locate classes inside a subpackage, inside a classpath JAR file"() {
+
+    expect:
+
+    assertInList locator.locateClassNames("org.slf4j"),
+        "org.slf4j",
+        "spi.MDCAdapter"
+  }
+
+  def "can locate classes in local folder, but exclude inner classes"() {
+
+    def packageName = "org.apache.tapestry5.ioc.services"
+
+    when:
+
+    def names = locator.locateClassNames packageName
+
+    then:
+
+    assertInList names, packageName, "SymbolSource", "TapestryIOCModule"
+
+    assertNotInList names, packageName, 'TapestryIOCMOdules$1'
+  }
+
+  def "can locate classes in subpackage of local folders"() {
+    def packageName = "org.apache.tapestry5"
+
+    when:
+
+    def names = locator.locateClassNames packageName
+
+    then:
+
+    assertInList names, packageName, "ioc.Orderable", "ioc.services.ChainBuilder"
+    assertNotInList names, packageName, 'services.TapestryIOCModule$1'
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d76df134/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ClassNameLocatorImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ClassNameLocatorImplTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ClassNameLocatorImplTest.java
deleted file mode 100644
index 9fc33c6..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ClassNameLocatorImplTest.java
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright 2007, 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.services;
-
-import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
-import org.apache.tapestry5.ioc.internal.util.InternalUtils;
-import org.apache.tapestry5.ioc.services.ClassNameLocator;
-import org.apache.tapestry5.ioc.services.ClasspathURLConverter;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import java.util.Collection;
-import java.util.Set;
-
-/**
- * Tricky to test, since the code is literally hunting around inside its own brain. There's a lot of room for unintended
- * consequences here.
- */
-public class ClassNameLocatorImplTest extends Assert
-{
-    private final ClasspathURLConverter converter = new ClasspathURLConverterImpl();
-
-    /**
-     * Use various packages in javax.inject to test this, as those don't change unexpectedly(-ish) and we know they are in
-     * a JAR on the classpath.
-     */
-    @Test
-    public void classes_in_jar_file()
-    {
-        ClassNameLocator locator = new ClassNameLocatorImpl(converter);
-
-        Collection<String> names = locator
-                .locateClassNames("javax.inject");
-
-        // Assert a couple of the matched names
-        assertInList(
-                names,
-                "javax.inject", "Inject", "Named", "Singleton");
-    }
-
-    @Test
-    public void classes_in_subpackage_in_jar_file()
-    {
-        ClassNameLocator locator = new ClassNameLocatorImpl(converter);
-
-        Collection<String> names = locator.locateClassNames("org.slf4j");
-
-        assertInList(
-                names,
-                "org.slf4j",
-                "spi.MDCAdapter");
-
-    }
-
-    /**
-     * This time, we use a selection of classes from tapestry-ioc, since those will never be packaged inside a JAR at
-     * this time.
-     */
-
-    @Test
-    public void classes_in_local_folders()
-    {
-        ClassNameLocator locator = new ClassNameLocatorImpl(converter);
-
-        Collection<String> names = locator
-                .locateClassNames("org.apache.tapestry5.ioc.services");
-
-        assertInList(names, "org.apache.tapestry5.ioc.services", "SymbolSource", "TapestryIOCModule");
-
-        assertNotInList(names, "org.apache.tapestry5.ioc.services", "TapestryIOCModule$1");
-    }
-
-    @Test
-    public void classes_in_subpackages_in_local_folders()
-    {
-        ClassNameLocator locator = new ClassNameLocatorImpl(converter);
-
-        Collection<String> names = locator.locateClassNames("org.apache.tapestry5");
-
-        assertInList(
-                names,
-                "org.apache.tapestry5",
-                "ioc.Orderable",
-                "ioc.services.ChainBuilder");
-
-        assertNotInList(names, "org.apache.tapestry5.ioc", "services.TapestryIOCModule$1");
-    }
-
-    void assertInList(Collection<String> names, String packageName, String... classNames)
-    {
-        Set<String> classNameSet = CollectionFactory.newSet(names);
-
-        for (String className : classNames)
-        {
-            String fullName = packageName + "." + className;
-
-            if (classNameSet.contains(fullName))
-                continue;
-
-            String message = String.format("%s not found in %s.", fullName, InternalUtils
-                    .joinSorted(names));
-
-            throw new AssertionError(message);
-        }
-    }
-
-    void assertNotInList(Collection<String> names, String packageName, String... classNames)
-    {
-        Set<String> classNameSet = CollectionFactory.newSet(names);
-
-        for (String className : classNames)
-        {
-            String fullName = packageName + "." + className;
-
-            if (!classNameSet.contains(fullName))
-                continue;
-
-            String message = String.format("%s found in %s.", fullName, InternalUtils
-                    .joinSorted(names));
-
-            throw new AssertionError(message);
-        }
-    }
-}