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/05/16 20:50:31 UTC

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

Branch: refs/heads/master
Commit: aa452c70705ba512a8ef51be7ba3869238a31cdf
Parents: 31e9e9c
Author: Howard M. Lewis Ship <hl...@gmail.com>
Authored: Tue May 1 13:00:39 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 16 11:50:13 2012 -0700

----------------------------------------------------------------------
 .../DefaultImplementationBuilderImplSpec.groovy    |   44 ++++++++
 .../DefaultImplementationBuilderImplTest.java      |   81 ---------------
 2 files changed, 44 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/aa452c70/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy
new file mode 100644
index 0000000..ea2ed27
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy
@@ -0,0 +1,44 @@
+package org.apache.tapestry5.ioc.internal.services
+
+import org.apache.tapestry.ioc.AbstractSharedRegistrySpecification
+import org.apache.tapestry5.ioc.services.DefaultImplementationBuilder
+
+/** An interface that includes toString() */
+interface ToString {
+  String toString();
+}
+
+class DefaultImplementationBuilderImplSpec extends AbstractSharedRegistrySpecification {
+
+  DefaultImplementationBuilder builder = getService(DefaultImplementationBuilder)
+
+  def "default simple interface does nothing"() {
+    Runnable r = builder.createDefaultImplementation(Runnable)
+
+    when:
+
+    r.run()
+
+    then:
+
+    assert r.toString() == "<NoOp java.lang.Runnable>"
+  }
+
+  def "when toString() is part of interface, the default returns null"() {
+    ToString ts = builder.createDefaultImplementation(ToString)
+
+    expect:
+
+    ts.toString() == null
+  }
+
+  def "built instances are cached (by type)"() {
+    Runnable r1 = builder.createDefaultImplementation(Runnable)
+    Runnable r2 = builder.createDefaultImplementation(Runnable)
+
+    expect:
+
+    r1.is r2
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/aa452c70/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplTest.java
deleted file mode 100644
index 6ed7ba6..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2006, 2007 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.IOCInternalTestCase;
-import org.apache.tapestry5.ioc.services.DefaultImplementationBuilder;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-public class DefaultImplementationBuilderImplTest extends IOCInternalTestCase
-{
-    private DefaultImplementationBuilder builder;
-
-    @BeforeClass
-    public void setup_builder()
-    {
-        builder = getService("DefaultImplementationBuilder", DefaultImplementationBuilder.class);
-    }
-
-    @AfterClass
-    public void cleanup_builder()
-    {
-        builder = null;
-    }
-
-    @Test
-    public void simple_interface()
-    {
-        Runnable r = builder.createDefaultImplementation(Runnable.class);
-
-        r.run();
-
-        assertEquals(r.toString(), "<NoOp java.lang.Runnable>");
-    }
-
-    public interface ToString
-    {
-        String toString();
-    }
-
-    @Test
-    public void interface_has_toString()
-    {
-        ToString ts = builder.createDefaultImplementation(ToString.class);
-
-        assertNull(ts.toString());
-    }
-
-    @Test
-    public void instances_are_cached()
-    {
-        Runnable r1 = null;
-        Runnable r2 = null;
-
-        // With tests in parallel, there's a harmless race condition that can cause r1 != r2
-        // for one pass, so we give it a second chance to prove itself.
-
-        for (int i = 0; i < 2; i++)
-        {
-            r1 = builder.createDefaultImplementation(Runnable.class);
-            r2 = builder.createDefaultImplementation(Runnable.class);
-
-            if (r1 == r2) break;
-        }
-
-        assertSame(r2, r1);
-    }
-}