tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [2/2] git commit: Convert TestNG to Spock
Date Thu, 14 Jun 2012 18:51:24 GMT
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/a825d2cf
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/a825d2cf
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/a825d2cf

Branch: refs/heads/master
Commit: a825d2cfbe315bd7b69f96ee311efd5fb67b1f9b
Parents: 3e255ab
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Wed Jun 13 09:28:47 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Wed Jun 13 09:28:47 2012 -0700

----------------------------------------------------------------------
 .../apache/tapestry5/ioc/util/OrdererSpec.groovy   |  114 +++++
 .../tapestry5/ioc/internal/util/OrdererTest.java   |  379 ---------------
 2 files changed, 114 insertions(+), 379 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a825d2cf/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/OrdererSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/OrdererSpec.groovy
b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/OrdererSpec.groovy
index 49e5095..317913a 100644
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/OrdererSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/OrdererSpec.groovy
@@ -1,5 +1,6 @@
 package org.apache.tapestry5.ioc.util
 
+import org.apache.tapestry5.ioc.Orderable
 import org.apache.tapestry5.ioc.internal.util.Orderer
 import org.apache.tapestry5.ioc.internal.util.UtilMessages
 import org.slf4j.Logger
@@ -168,4 +169,117 @@ class OrdererSpec extends Specification {
 
     orderer.ordered == ["BARNEY", "FRED", "WILMA", "BETTY"]
   }
+
+  def "the special after:* moves the value to the end of the list"() {
+    def orderer = new Orderer(logger)
+
+    when:
+
+    orderer.with {
+      add "fred", "FRED"
+      add "barney", "BARNEY", "after:*"
+      add "wilma", "WILMA"
+      add "betty", "BETTY"
+    }
+
+    then:
+
+    // A number of factors can twiddle the order of the other elements, so we just check
the last
+    orderer.ordered[3] == "BARNEY"
+  }
+
+  def "use lists of pre-requisites (after:)"() {
+
+    def orderer = new Orderer(logger)
+
+    when:
+
+    orderer.with {
+      add "fred", "FRED", "after:wilma"
+      add "barney", "BARNEY", "after:fred,betty"
+      add "wilma", "WILMA"
+      add "betty", "BETTY"
+    }
+
+    then:
+
+    orderer.ordered == ["WILMA", "FRED", "BETTY", "BARNEY"]
+  }
+
+  def "use both pre- and post-requisites (before: and after:)"() {
+
+    def orderer = new Orderer(logger)
+
+    when:
+
+    orderer.with {
+      add "fred", "FRED", "after:wilma"
+      add "barney", "BARNEY", "after:fred,betty"
+      add "wilma", "WILMA"
+      add "betty", "BETTY", "before:wilma"
+    }
+
+    then:
+
+    orderer.ordered == ["BETTY", "WILMA", "FRED", "BARNEY"]
+  }
+
+  def "pre- and post-requisites are case-insensitive"() {
+    def orderer = new Orderer(logger)
+
+    when:
+
+    orderer.with {
+      add "fred", "FRED", "after:WILMA"
+      add "barney", "BARNEY", "after:fred,BETTY"
+      add "wilma", "WILMA"
+      add "betty", "BETTY", "before:Wilma"
+    }
+
+    then:
+
+    orderer.ordered == ["BETTY", "WILMA", "FRED", "BARNEY"]
+  }
+
+  def "dependency cycles are identified and logged as warnings"() {
+
+    def orderer = new Orderer(logger)
+
+    when:
+
+    orderer.with {
+      add "fred", "FRED", "after:wilma"
+      add "barney", "BARNEY", "after:fred,betty"
+      add "wilma", "WILMA"
+      add "betty", "BETTY", "before:Wilma", "after:barney"
+    }
+
+    def ordered = orderer.ordered
+
+    then:
+
+    1 * logger.warn("Unable to add 'barney' as a dependency of 'betty', as that forms a dependency
cycle ('betty' depends on itself via 'barney'). The dependency has been ignored.")
+
+
+    ordered == ["BETTY", "WILMA", "FRED", "BARNEY"]
+  }
+
+  def "Orderable has a useful toString()"() {
+
+    when:
+
+    def simple = new Orderable("simple", "SIMPLE")
+
+    then:
+
+    simple.toString() == "Orderable[simple SIMPLE]"
+
+    when:
+
+    def complex = new Orderable("complex", "COMPLEX", "after:foo", "before:bar")
+
+    then:
+
+    complex.toString() == "Orderable[complex after:foo before:bar COMPLEX]"
+  }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a825d2cf/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/OrdererTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/OrdererTest.java
b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/OrdererTest.java
deleted file mode 100644
index 05d3a48..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/OrdererTest.java
+++ /dev/null
@@ -1,379 +0,0 @@
-// Copyright 2006, 2007, 2009 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.util;
-
-import org.apache.tapestry5.ioc.Orderable;
-import org.apache.tapestry5.ioc.internal.IOCInternalTestCase;
-import org.slf4j.Logger;
-import org.testng.annotations.Test;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class OrdererTest extends IOCInternalTestCase
-{
-    @Test
-    public void no_dependencies()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED");
-        o.add("barney", "BARNEY");
-        o.add("wilma", "WILMA");
-        o.add("betty", "BETTY");
-
-        List<String> ordered = o.getOrdered();
-
-        assertEquals(ordered, Arrays.asList("FRED", "BARNEY", "WILMA", "BETTY"));
-
-        verify();
-    }
-
-    @Test
-    public void override()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED");
-        o.add("barney", "BARNEY");
-        o.add("wilma", "WILMA");
-        o.add("betty", "BETTY");
-
-        o.override("barney", "Mr. Rubble", "before:*");
-
-        List<String> ordered = o.getOrdered();
-
-        assertEquals(ordered, Arrays.asList("Mr. Rubble", "FRED", "WILMA", "BETTY"));
-
-        verify();
-    }
-
-    @Test
-    public void failed_override()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED");
-        o.add("barney", "BARNEY");
-        o.add("wilma", "WILMA");
-        o.add("betty", "BETTY");
-
-        try
-        {
-            o.override("bambam", "Mr. Rubble JR.", "before:*");
-            unreachable();
-        }
-        catch (IllegalArgumentException ex)
-        {
-            assertEquals(ex.getMessage(),
-                         "Override for object 'bambam' is invalid as it does not match an
existing object.");
-        }
-
-        verify();
-    }
-
-    @Test
-    public void missing_constraint_type()
-    {
-        Logger logger = mockLogger();
-
-        logger.warn(UtilMessages.constraintFormat("fred", "barney"));
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED");
-        o.add("barney", "BARNEY", "fred");
-        o.add("wilma", "WILMA");
-        o.add("betty", "BETTY");
-
-        List<String> ordered = o.getOrdered();
-
-        assertEquals(ordered, Arrays.asList("FRED", "BARNEY", "WILMA", "BETTY"));
-
-        verify();
-    }
-
-    @Test
-    public void unknown_constraint_type()
-    {
-        Logger logger = mockLogger();
-
-        logger.warn(UtilMessages.constraintFormat("nearby:fred", "barney"));
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED");
-        o.add("barney", "BARNEY", "nearby:fred");
-        o.add("wilma", "WILMA");
-        o.add("betty", "BETTY");
-
-        List<String> ordered = o.getOrdered();
-
-        assertEquals(ordered, Arrays.asList("FRED", "BARNEY", "WILMA", "BETTY"));
-
-        verify();
-    }
-
-    @Test
-    public void nulls_not_included_in_result()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED");
-        o.add("barney", "BARNEY");
-        o.add("zippo", null);
-        o.add("wilma", "WILMA");
-        o.add("groucho", null);
-        o.add("betty", "BETTY");
-
-        List<String> ordered = o.getOrdered();
-
-        assertEquals(ordered, Arrays.asList("FRED", "BARNEY", "WILMA", "BETTY"));
-
-        verify();
-    }
-
-    @Test
-    public void duplicate_id()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED");
-        o.add("barney", "BARNEY");
-        o.add("wilma", "WILMA");
-
-        verify();
-
-        logger.warn(UtilMessages.duplicateOrderer("fred"));
-
-        replay();
-
-        o.add("fred", "FRED2");
-
-        verify();
-
-        replay();
-
-        o.add("betty", "BETTY");
-
-        List<String> ordered = o.getOrdered();
-
-        assertEquals(ordered, Arrays.asList("FRED", "BARNEY", "WILMA", "BETTY"));
-
-        verify();
-    }
-
-    @Test
-    public void leader()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED");
-        o.add("barney", "BARNEY", "before:*");
-        o.add("wilma", "WILMA");
-        o.add("betty", "BETTY");
-
-        List<String> ordered = o.getOrdered();
-
-        assertEquals(ordered, Arrays.asList("BARNEY", "FRED", "WILMA", "BETTY"));
-
-        verify();
-    }
-
-    @Test
-    public void trailer()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED");
-        o.add("barney", "BARNEY", "after:*");
-        o.add("wilma", "WILMA");
-        o.add("betty", "BETTY");
-
-        List<String> ordered = o.getOrdered();
-
-        assertEquals(ordered.get(3), "BARNEY");
-
-        verify();
-    }
-
-    @Test
-    public void prereqs()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED", "after:wilma");
-        o.add("barney", "BARNEY", "after:fred,betty");
-        o.add("wilma", "WILMA");
-        o.add("betty", "BETTY");
-
-        List<String> ordered = o.getOrdered();
-
-        assertEquals(ordered, Arrays.asList("WILMA", "FRED", "BETTY", "BARNEY"));
-
-        verify();
-    }
-
-    @Test
-    public void pre_and_post_reqs()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED", "after:wilma");
-        o.add("barney", "BARNEY", "after:fred,betty");
-        o.add("wilma", "WILMA");
-        o.add("betty", "BETTY", "before:wilma");
-
-        List<String> ordered = o.getOrdered();
-
-        assertEquals(ordered, Arrays.asList("BETTY", "WILMA", "FRED", "BARNEY"));
-
-        verify();
-    }
-
-    @Test
-    public void case_insensitivity()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED", "after:Wilma");
-        o.add("barney", "BARNEY", "after:Fred,BETTY");
-        o.add("wilma", "WILMA");
-        o.add("betty", "BETTY", "before:Wilma");
-
-        List<String> ordered = o.getOrdered();
-
-        assertEquals(ordered, Arrays.asList("BETTY", "WILMA", "FRED", "BARNEY"));
-
-        verify();
-    }
-
-    @Test
-    public void dependency_cycle()
-    {
-        Logger logger = mockLogger();
-
-        logger.warn("Unable to add 'barney' as a dependency of 'betty', as that forms a "
-                + "dependency cycle ('betty' depends on itself via 'barney'). "
-                + "The dependency has been ignored.");
-
-        replay();
-
-        Orderer<String> o = new Orderer<String>(logger);
-
-        o.add("fred", "FRED", "after:wilma");
-        o.add("barney", "BARNEY", "after:fred,betty");
-        o.add("wilma", "WILMA");
-        o.add("betty", "BETTY", "after:barney", "before:wilma");
-
-        List<String> ordered = o.getOrdered();
-
-        assertEquals(ordered, Arrays.asList("BETTY", "WILMA", "FRED", "BARNEY"));
-
-        verify();
-    }
-
-    @Test
-    public void toString_Orderable()
-    {
-        Orderable<String> simple = new Orderable<String>("simple", "SIMPLE");
-
-        assertEquals(simple.toString(), "Orderable[simple SIMPLE]");
-
-        Orderable<String> complex = new Orderable<String>("complex", "COMPLEX",
"after:foo",
-                                                          "before:bar");
-
-        assertEquals(complex.toString(), "Orderable[complex after:foo before:bar COMPLEX]");
-    }
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void toString_DependencyNode()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        DependencyNode<String> node1 = new DependencyNode<String>(logger, new
Orderable("node1",
-                                                                                        "NODE1"));
-
-        assertEquals(node1.toString(), "[node1]");
-
-        DependencyNode<String> node2 = new DependencyNode<String>(logger, new
Orderable("node2",
-                                                                                        "NODE2"));
-
-        DependencyNode<String> node3 = new DependencyNode<String>(logger, new
Orderable("node3",
-                                                                                        "NODE3"));
-
-        DependencyNode<String> node4 = new DependencyNode<String>(logger, new
Orderable("node4",
-                                                                                        "NODE4"));
-
-        DependencyNode<String> node5 = new DependencyNode<String>(logger, new
Orderable("node5",
-                                                                                        "NODE5"));
-
-        node2.addDependency(node1);
-        node1.addDependency(node3);
-        node1.addDependency(node4);
-        node5.addDependency(node1);
-
-        assertEquals(node5.toString(), "[node5: [node1: [node3], [node4]]]");
-
-        verify();
-    }
-}


Mime
View raw message