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/06/02 23:21:40 UTC

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

Branch: refs/heads/master
Commit: cf48bba74bfa575c57ab8073d9bd2367886191ed
Parents: 82a3af9
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Fri Jun 1 18:09:43 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Fri Jun 1 18:09:43 2012 -0700

----------------------------------------------------------------------
 .../tapestry5/util/StrategyRegistrySpec.groovy     |  148 ++++++++++++
 .../tapestry5/ioc/util/StrategyRegistryTest.java   |  177 ---------------
 2 files changed, 148 insertions(+), 177 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cf48bba7/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/StrategyRegistrySpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/StrategyRegistrySpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/StrategyRegistrySpec.groovy
new file mode 100644
index 0000000..30ca282
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/StrategyRegistrySpec.groovy
@@ -0,0 +1,148 @@
+package org.apache.tapestry5.util
+
+import org.apache.tapestry5.ioc.util.StrategyRegistry
+import org.apache.tapestry5.ioc.util.UnknownValueException
+import spock.lang.Specification
+
+class StrategyRegistrySpec extends Specification {
+
+  def "check exception when an adaptor is not found"() {
+    Runnable r1 = Mock()
+    Runnable r2 = Mock()
+
+    StrategyRegistry reg = StrategyRegistry.newInstance(Runnable, [
+        (List): r1,
+        (Map): r2
+    ])
+
+    when:
+
+    reg.get(Set)
+
+    then:
+
+    UnknownValueException e = thrown()
+
+    e.message == "No adapter from type java.util.Set to type java.lang.Runnable is available."
+    e.availableValues.toString() == "AvailableValues[registered types: interface java.util.List, interface java.util.Map]"
+
+  }
+
+  def "access to types registered"() {
+    Runnable r1 = Mock()
+    Runnable r2 = Mock()
+
+    when:
+
+    StrategyRegistry sr = StrategyRegistry.newInstance(Runnable, [
+        (List): r1,
+        (Map): r2
+    ])
+
+    then:
+
+    sr.types.size == 2
+    sr.types.containsAll(List, Map)
+  }
+
+  def "locate an adapter based on interface inheritance"() {
+
+    Runnable r1 = Mock()
+    Runnable r2 = Mock()
+
+    when:
+
+    StrategyRegistry sr = StrategyRegistry.newInstance(Runnable, [
+        (List): r1,
+        (Map): r2
+    ])
+
+    def arrayListAdapter = sr.get(ArrayList)
+
+    then:
+
+    arrayListAdapter.is r1
+
+    when:
+
+    def adapter2 = sr.get(ArrayList)
+
+    then:
+
+    adapter2.is r1
+
+    when:
+
+    sr.clearCache()
+
+    def adapter3 = sr.get(ArrayList)
+
+    then:
+
+    adapter3.is r1
+  }
+
+  def "the registration map passed to the constructor is copied"() {
+
+    Runnable r1 = Mock()
+    Runnable r2 = Mock()
+
+    def registrations = [
+        (List): r1,
+        (Map): r2
+    ]
+
+    when:
+
+    StrategyRegistry sr = StrategyRegistry.newInstance(Runnable, registrations)
+
+    registrations.clear()
+
+    then:
+
+    sr.get(ArrayList).is(r1)
+  }
+
+  def "adapter found from an instance"() {
+
+    Runnable r1 = Mock()
+    Runnable r2 = Mock()
+
+    when:
+
+    StrategyRegistry sr = StrategyRegistry.newInstance(Runnable, [
+        (List): r1,
+        (Map): r2
+    ])
+
+    then:
+
+    sr.getByInstance([]).is(r1)
+    sr.getByInstance([:]).is(r2)
+
+    when:
+
+    sr.clearCache()
+
+    then:
+
+    sr.getByInstance([]).is(r1)
+  }
+
+  def "null instances matches against void.class"() {
+
+    Runnable r1 = Mock()
+    Runnable r2 = Mock()
+
+    when:
+
+    def sr = StrategyRegistry.newInstance(Runnable, [
+        (void): r1,
+        (Map): r2])
+
+
+    then:
+
+    sr.getByInstance(null).is(r1)
+  }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cf48bba7/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/StrategyRegistryTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/StrategyRegistryTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/StrategyRegistryTest.java
deleted file mode 100644
index 10aca83..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/StrategyRegistryTest.java
+++ /dev/null
@@ -1,177 +0,0 @@
-// Copyright 2006, 2007, 2012 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.util;
-
-import org.apache.tapestry5.ioc.test.IOCTestCase;
-import org.testng.annotations.Test;
-
-import java.util.*;
-
-import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newMap;
-
-public class StrategyRegistryTest extends IOCTestCase
-{
-    @Test
-    public void adapter_not_found()
-    {
-        Runnable r1 = mockRunnable();
-        Runnable r2 = mockRunnable();
-
-        replay();
-
-        Map<Class, Runnable> registrations = newMap();
-
-        registrations.put(List.class, r1);
-        registrations.put(Map.class, r2);
-
-        StrategyRegistry<Runnable> r = StrategyRegistry.newInstance(Runnable.class, registrations);
-
-        try
-        {
-            r.get(Set.class);
-            unreachable();
-        } catch (UnknownValueException ex)
-        {
-            assertEquals(
-                    ex.getMessage(),
-                    "No adapter from type java.util.Set to type java.lang.Runnable is available.");
-            assertEquals(ex.getAvailableValues().toString(), "AvailableValues[registered types: interface java.util.List, interface java.util.Map]");
-        }
-
-        verify();
-    }
-
-    @Test
-    public void get_types()
-    {
-
-        Runnable r1 = mockRunnable();
-        Runnable r2 = mockRunnable();
-
-        replay();
-        Map<Class, Runnable> registrations = newMap();
-
-        registrations.put(List.class, r1);
-        registrations.put(Map.class, r2);
-
-        StrategyRegistry<Runnable> r = StrategyRegistry.newInstance(Runnable.class, registrations);
-
-
-        Collection<Class> types = r.getTypes();
-
-        assertEquals(types.size(), 2);
-        assertTrue(types.contains(List.class));
-        assertTrue(types.contains(Map.class));
-
-        verify();
-    }
-
-    @Test
-    public void adapter_not_found_when_non_error()
-    {
-        Runnable r1 = mockRunnable();
-        Runnable r2 = mockRunnable();
-
-        replay();
-
-        Map<Class, Runnable> registrations = newMap();
-
-        registrations.put(List.class, r1);
-        registrations.put(Map.class, r2);
-
-        StrategyRegistry<Runnable> r = StrategyRegistry.newInstance(Runnable.class, registrations);
-
-        Runnable actual = r.get(ArrayList.class);
-
-        assertSame(actual, r1);
-
-        // The cache is almost impossible to "test", but we can at least collect some
-        // code coverage over those lines.
-
-        Runnable actual2 = r.get(ArrayList.class);
-        assertSame(actual2, r1);
-
-        r.clearCache();
-
-        Runnable actual3 = r.get(ArrayList.class);
-        assertSame(actual3, r1);
-
-        verify();
-    }
-
-    @Test
-    public void registration_map_is_copied_by_constructor()
-    {
-        Runnable r1 = mockRunnable();
-        Runnable r2 = mockRunnable();
-
-        replay();
-
-        Map<Class, Runnable> registrations = newMap();
-
-        registrations.put(List.class, r1);
-        registrations.put(Map.class, r2);
-
-        StrategyRegistry<Runnable> r = StrategyRegistry.newInstance(Runnable.class, registrations);
-
-        registrations.clear();
-
-        Runnable actual = r.get(ArrayList.class);
-
-        assertSame(actual, r1);
-    }
-
-    @Test
-    public void adapter_found_by_instance()
-    {
-        Runnable r1 = mockRunnable();
-        Runnable r2 = mockRunnable();
-
-        replay();
-
-        Map<Class, Runnable> registrations = newMap();
-
-        registrations.put(List.class, r1);
-        registrations.put(Map.class, r2);
-
-        StrategyRegistry<Runnable> r = StrategyRegistry.newInstance(Runnable.class, registrations);
-
-        assertSame(r.getByInstance(registrations), r2);
-
-        verify();
-    }
-
-    @Test
-    public void null_instance_matches_class_void()
-    {
-        Runnable r1 = mockRunnable();
-        Runnable r2 = mockRunnable();
-        Runnable r3 = mockRunnable();
-
-        replay();
-
-        Map<Class, Runnable> registrations = newMap();
-
-        registrations.put(List.class, r1);
-        registrations.put(Map.class, r2);
-        registrations.put(void.class, r3);
-
-        StrategyRegistry<Runnable> r = StrategyRegistry.newInstance(Runnable.class, registrations);
-
-        assertSame(r.getByInstance(null), r3);
-
-        verify();
-    }
-}