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/12 23:37:22 UTC

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

Branch: refs/heads/master
Commit: b34f11121c9b55bb8617857c36a9d87d9fa3a1a5
Parents: bd1da98
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Jun 11 16:47:20 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Jun 11 16:47:20 2012 -0700

----------------------------------------------------------------------
 .../ValidatingConfigurationWrapperSpec.groovy      |   78 ++++++++
 .../ValidatingConfigurationWrapperTest.java        |  137 ---------------
 2 files changed, 78 insertions(+), 137 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b34f1112/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperSpec.groovy
new file mode 100644
index 0000000..fdc1363
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperSpec.groovy
@@ -0,0 +1,78 @@
+package org.apache.tapestry5.ioc.internal
+
+import org.apache.tapestry5.ioc.Configuration
+import org.apache.tapestry5.ioc.ObjectLocator
+import spock.lang.Specification
+
+class ValidatingConfigurationWrapperSpec extends Specification {
+
+  TypeCoercerProxy tc = Mock()
+  ObjectLocator locator = Mock()
+
+  def collection = []
+
+  def "valid contribution"() {
+    Runnable value = Mock()
+
+    Configuration config = new ValidatingConfigurationWrapper(Runnable, null, tc, collection, "Baz")
+
+    when:
+
+    config.add(value)
+
+    then:
+
+    tc.coerce(value, Runnable) >> value
+
+    collection == [value]
+  }
+
+  def "contributed value may be coerced"() {
+    Runnable value = Mock()
+    Runnable coerced = Mock()
+
+    Configuration config = new ValidatingConfigurationWrapper(Runnable, null, tc, collection, "Baz")
+
+    when:
+
+    config.add(value)
+
+    then:
+
+    tc.coerce(value, Runnable) >> coerced
+
+    collection == [coerced]
+  }
+
+  def "an instance of a class may be contributed"() {
+    HashMap contributed = new HashMap()
+    Map coerced = Mock()
+
+    Configuration config = new ValidatingConfigurationWrapper(Map, locator, tc, collection, "Baz")
+
+    when:
+
+    config.addInstance(HashMap)
+
+    then:
+
+    locator.autobuild(HashMap) >> contributed
+    tc.coerce(contributed, Map) >> coerced
+
+    collection == [coerced]
+  }
+
+  def "null may not be contributed"() {
+    Configuration config = new ValidatingConfigurationWrapper(Runnable, null, tc, collection, "Baz")
+
+    when:
+
+    config.add(null)
+
+    then:
+
+    NullPointerException e = thrown()
+
+    e.message == "Service contribution (to service 'Baz') was null."
+  }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b34f1112/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperTest.java
deleted file mode 100644
index e7a2d6e..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperTest.java
+++ /dev/null
@@ -1,137 +0,0 @@
-// Copyright 2006, 2007, 2008, 2009, 2011 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;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.tapestry5.ioc.Configuration;
-import org.apache.tapestry5.ioc.ObjectLocator;
-import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
-import org.testng.annotations.Test;
-
-@SuppressWarnings(
-{ "rawtypes", "unchecked" })
-public class ValidatingConfigurationWrapperTest extends IOCInternalTestCase
-{
-    @Test
-    public void valid_contribution()
-    {
-        List<Runnable> collection = CollectionFactory.newList();
-        Runnable value = mockRunnable();
-        TypeCoercerProxy tc = mockTypeCoercerProxy();
-
-        expect(tc.coerce(value, Runnable.class)).andReturn(value);
-
-        replay();
-
-        Configuration wrapper = new ValidatingConfigurationWrapper(Runnable.class, null, tc, collection, "foo.Bar");
-
-        wrapper.add(value);
-
-        verify();
-
-        assertListsEquals(collection, value);
-    }
-
-    @Test
-    public void coerced_contribution()
-    {
-        List<Runnable> collection = CollectionFactory.newList();
-        Runnable value = mockRunnable();
-        TypeCoercerProxy tc = mockTypeCoercerProxy();
-        String contributed = "coerceme";
-
-        expect(tc.coerce(contributed, Runnable.class)).andReturn(value);
-
-        replay();
-
-        Configuration wrapper = new ValidatingConfigurationWrapper(Runnable.class, null, tc, collection, "foo.Bar");
-
-        wrapper.add(contributed);
-
-        verify();
-
-        assertListsEquals(collection, value);
-    }
-
-    @Test
-    public void valid_class_contribution()
-    {
-        ObjectLocator locator = mockObjectLocator();
-        HashMap contributedValue = new HashMap();
-        train_autobuild(locator, HashMap.class, contributedValue);
-        List<Map> collection = CollectionFactory.newList();
-        TypeCoercerProxy tc = mockTypeCoercerProxy();
-
-        expect(tc.coerce(contributedValue, Map.class)).andReturn(contributedValue);
-
-        replay();
-
-        Configuration wrapper = new ValidatingConfigurationWrapper(Map.class, locator, tc, collection, "foo.Bar");
-
-        wrapper.addInstance(HashMap.class);
-
-        verify();
-
-        assertListsEquals(collection, contributedValue);
-    }
-
-    @Test
-    public void null_contribution()
-    {
-        List<Runnable> collection = CollectionFactory.newList();
-
-        Configuration wrapper = new ValidatingConfigurationWrapper(Runnable.class, null, null, collection, "Bar");
-
-        try
-        {
-            wrapper.add(null);
-            unreachable();
-        }
-        catch (NullPointerException ex)
-        {
-            assertEquals(ex.getMessage(), "Service contribution (to service 'Bar') was null.");
-        }
-    }
-
-    @Test
-    public void wrong_type_of_contribution()
-    {
-        List<Runnable> collection = CollectionFactory.newList();
-        Throwable e = new RuntimeException("No go");
-        TypeCoercerProxy tc = mockTypeCoercerProxy();
-        String contributedValue = "runnable";
-
-        expect(tc.coerce(contributedValue, Runnable.class)).andThrow(e);
-
-        Configuration wrapper = new ValidatingConfigurationWrapper(Runnable.class, null, tc, collection, "Bar");
-
-        replay();
-
-        try
-        {
-            wrapper.add(contributedValue);
-            unreachable();
-        }
-        catch (RuntimeException ex)
-        {
-            assertSame(ex, e);
-        }
-
-        verify();
-    }
-}