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:31 UTC

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

Branch: refs/heads/master
Commit: e57bd92dc5594be5294f1c52feb2a5d1635202fd
Parents: df6e407
Author: Howard M. Lewis Ship <hl...@gmail.com>
Authored: Mon May 14 11:12:53 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 16 11:50:14 2012 -0700

----------------------------------------------------------------------
 .../tapestry5/util/StringToEnumCoercionSpec.groovy |   57 +++++++++++++
 .../tapestry5/util/StringToEnumCoercionTest.java   |   64 ---------------
 2 files changed, 57 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e57bd92d/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/StringToEnumCoercionSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/StringToEnumCoercionSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/StringToEnumCoercionSpec.groovy
new file mode 100644
index 0000000..d7ddd79
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/StringToEnumCoercionSpec.groovy
@@ -0,0 +1,57 @@
+package org.apache.tapestry5.util
+
+import spock.lang.Specification
+
+
+class StringToEnumCoercionSpec extends Specification
+{
+
+    def "searches are case-insensitive"()
+    {
+        def coercion = new StringToEnumCoercion(Stooge)
+
+        expect:
+
+        coercion.coerce("moe").is(Stooge.MOE)
+        coercion.coerce("MOE").is(Stooge.MOE)
+        coercion.coerce("CURLY_Joe").is(Stooge.CURLY_JOE)
+    }
+
+    def "blank input returns null"()
+    {
+        def coercion = new StringToEnumCoercion(Stooge)
+
+        expect:
+
+        coercion.coerce("") == null
+        coercion.coerce("\t\n") == null
+    }
+
+    def "enum value can be found by an added alias"()
+    {
+        def coercion = new StringToEnumCoercion(Stooge)
+
+        coercion.addAlias("shemp", Stooge.CURLY_JOE)
+
+        expect:
+
+        coercion.coerce("curly_joe").is(Stooge.CURLY_JOE)
+        coercion.coerce("shemp").is(Stooge.CURLY_JOE)
+        coercion.coerce("Shemp").is(Stooge.CURLY_JOE)
+    }
+
+    def "a failed search by name throws an exception"()
+    {
+        def coercion = new StringToEnumCoercion(Stooge)
+
+        when:
+
+        coercion.coerce("shemp")
+
+        then:
+
+        RuntimeException e = thrown()
+
+        e.message == /Input 'shemp' does not identify a value from enumerated type ${Stooge.name}./
+    }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e57bd92d/tapestry-ioc/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java
deleted file mode 100644
index 83d795b..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/util/StringToEnumCoercionTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2007, 2010, 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.util;
-
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-public class StringToEnumCoercionTest extends Assert
-{
-    @Test
-    public void value_found()
-    {
-        StringToEnumCoercion<Stooge> coercion = new StringToEnumCoercion<Stooge>(Stooge.class);
-
-        assertSame(coercion.coerce("moe"), Stooge.MOE);
-        assertSame(coercion.coerce("curly_joe"), Stooge.CURLY_JOE);
-    }
-
-    @Test
-    public void value_found_by_alias()
-    {
-        StringToEnumCoercion<Stooge> coercion = new StringToEnumCoercion<Stooge>(Stooge.class);
-
-        assertSame(coercion.addAlias("Shemp", Stooge.CURLY_JOE).coerce("shemp"), Stooge.CURLY_JOE);
-    }
-
-    @Test
-    public void blank_is_null()
-    {
-        StringToEnumCoercion<Stooge> coercion = new StringToEnumCoercion<Stooge>(Stooge.class);
-
-        assertNull(coercion.coerce(""));
-    }
-
-    @Test
-    public void value_not_found()
-    {
-        StringToEnumCoercion<Stooge> coercion = new StringToEnumCoercion<Stooge>(Stooge.class);
-
-        try
-        {
-            coercion.coerce("shemp");
-
-            fail("Unreachable");
-        }
-        catch (RuntimeException ex)
-        {
-            assertEquals(ex.getMessage(),
-                    "Input \'shemp\' does not identify a value from enumerated type org.apache.tapestry5.util.Stooge.");
-        }
-    }
-}