tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [1/2] git commit: Convert TestNG to Spock
Date Sat, 02 Jun 2012 22:50:23 GMT
Updated Branches:
  refs/heads/master ae5d15345 -> 1761c896d


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

Branch: refs/heads/master
Commit: 1761c896df9e5b5d7d30cdb932bf7b65723e5787
Parents: 121a9b6
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Sat Jun 2 15:50:14 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Sat Jun 2 15:50:14 2012 -0700

----------------------------------------------------------------------
 .../tapestry5/ioc/util/IdAllocatorSpec.groovy      |  163 +++++++++++++++
 .../apache/tapestry5/ioc/util/IdAllocatorTest.java |  147 -------------
 2 files changed, 163 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1761c896/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/IdAllocatorSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/IdAllocatorSpec.groovy
b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/IdAllocatorSpec.groovy
new file mode 100644
index 0000000..5802da7
--- /dev/null
+++ b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/IdAllocatorSpec.groovy
@@ -0,0 +1,163 @@
+package org.apache.tapestry5.ioc.util
+
+import spock.lang.Specification
+
+
+class IdAllocatorSpec extends Specification {
+
+  def "id is not allocated until it is allocated"() {
+    when:
+
+    IdAllocator a = new IdAllocator()
+
+    then:
+
+    !a.isAllocated("name")
+
+    when:
+
+    def actual = a.allocateId("name")
+
+    then:
+
+    actual == "name"
+    a.isAllocated("name")
+  }
+
+  def "repeatedly allocated ids are uniqued with a suffix"() {
+
+    IdAllocator a = new IdAllocator()
+
+    a.allocateId("name")
+
+    expect:
+
+    10.times {
+
+      def expected = "name_$it"
+
+      assert !a.isAllocated(expected)
+
+      assert a.allocateId("name") == expected
+    }
+  }
+
+  def "access to allocated ids"() {
+    IdAllocator a = new IdAllocator()
+
+    when:
+
+    a.allocateId("name")
+
+    then:
+
+    a.allocatedIds == ["name"]
+
+    when:
+
+    a.allocateId("name")
+
+    then:
+
+    a.allocatedIds == ["name", "name_0"]
+  }
+
+  def "allocation using a namespace"() {
+
+    IdAllocator a = new IdAllocator("_NS")
+
+    expect:
+
+    a.allocateId("name") == "name_NS"
+
+    a.allocateId("name") == "name_NS_0"
+
+    // This is current behavior, but is probably something
+    // that could be improved.
+
+    a.allocateId("name_NS") == "name_NS_NS"
+
+    a.allocateId("name_NS") == "name_NS_NS_0"
+  }
+
+  def "degenerate id allocation"() {
+    IdAllocator a = new IdAllocator()
+
+    expect:
+
+    a.allocateId("d_1") == "d_1"
+    a.allocateId("d") == "d"
+    a.allocateId("d") == "d_0"
+    a.allocateId("d") == "d_2"
+
+    a.allocateId("d") == "d_3"
+
+    // It's a collision, so a unique number is appended.
+    a.allocateId("d_1") == "d_1_0"
+  }
+
+  def "degenerate id allocation (with a namespace)"() {
+
+    IdAllocator a = new IdAllocator("_NS")
+
+    expect:
+
+    a.allocateId("d_1") == "d_1_NS"
+
+    a.allocateId("d") == "d_NS"
+    a.allocateId("d") == "d_NS_0"
+    a.allocateId("d") == "d_NS_1"
+    a.allocateId("d") == "d_NS_2"
+    a.allocateId("d") == "d_NS_3"
+
+    a.allocateId("d_1") == "d_1_NS_0"
+
+    // This is very degenerate, and maybe something that needs fixing.
+
+    a.allocateId("d_1_NS") == "d_1_NS_NS"
+  }
+
+  def "clearing an allocator forgets prior ids"() {
+    when:
+
+    IdAllocator a = new IdAllocator()
+
+
+    then:
+
+    a.allocateId("foo") == "foo"
+    a.allocateId("foo") == "foo_0"
+
+    when:
+
+    a.clear()
+
+    then:
+
+    a.allocateId("foo") == "foo"
+    a.allocateId("foo") == "foo_0"
+  }
+
+  def "cloning an id allocator does not share data with the new allocator"() {
+
+    when:
+
+    IdAllocator a = new IdAllocator();
+
+    then:
+
+    a.allocateId("foo") == "foo"
+    a.allocateId("foo") == "foo_0"
+
+    when:
+
+    IdAllocator b = a.clone()
+
+    then:
+
+    ["bar", "baz", "foo", "foo"].each {
+      assert a.allocateId(it) == b.allocateId(it)
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1761c896/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/IdAllocatorTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/IdAllocatorTest.java
b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/IdAllocatorTest.java
deleted file mode 100644
index b9cb02a..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/IdAllocatorTest.java
+++ /dev/null
@@ -1,147 +0,0 @@
-// Copyright 2004, 2005, 2006, 2010 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 static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList;
-
-import org.apache.tapestry5.ioc.util.IdAllocator;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import java.util.List;
-
-public class IdAllocatorTest extends Assert
-{
-
-    @Test
-    public void simple()
-    {
-        IdAllocator a = new IdAllocator();
-        List<String> ids = newList();
-
-        assertFalse(a.isAllocated("name"));
-
-        assertEquals(a.allocateId("name"), "name");
-        assertTrue(a.isAllocated("name"));
-
-        ids.add("name");
-
-        for (int i = 0; i < 10; i++)
-        {
-
-            String expected = "name_" + i;
-
-            assertFalse(a.isAllocated(expected));
-
-            String nextId = a.allocateId("name");
-
-            assertTrue(a.isAllocated(expected));
-
-            assertEquals(nextId, expected);
-
-            ids.add(nextId);
-        }
-
-        assertEquals(a.getAllocatedIds(), ids);
-    }
-
-    @Test
-    public void simple_with_namespace()
-    {
-        IdAllocator a = new IdAllocator("_NS");
-
-        assertEquals(a.allocateId("name"), "name_NS");
-
-        for (int i = 0; i < 10; i++)
-            assertEquals(a.allocateId("name"), "name_NS_" + i);
-
-        // This is current behavior, but is probably something
-        // that could be improved.
-
-        assertEquals(a.allocateId("foo_NS"), "foo_NS_NS");
-        assertEquals(a.allocateId("foo_NS"), "foo_NS_NS_0");
-    }
-
-    @Test
-    public void degenerate()
-    {
-        IdAllocator a = new IdAllocator();
-
-        assertEquals(a.allocateId("d_1"), "d_1");
-
-        assertEquals(a.allocateId("d"), "d");
-        assertEquals(a.allocateId("d"), "d_0");
-        assertEquals(a.allocateId("d"), "d_2");
-
-        assertEquals(a.allocateId("d"), "d_3");
-        assertEquals(a.allocateId("d_1"), "d_1_0");
-    }
-
-    @Test
-    public void degenerate_with_namespace()
-    {
-        IdAllocator a = new IdAllocator("_NS");
-
-        assertEquals(a.allocateId("d_1"), "d_1_NS");
-
-        assertEquals(a.allocateId("d"), "d_NS");
-        assertEquals(a.allocateId("d"), "d_NS_0");
-        assertEquals(a.allocateId("d"), "d_NS_1");
-        assertEquals(a.allocateId("d"), "d_NS_2");
-        assertEquals(a.allocateId("d"), "d_NS_3");
-
-        assertEquals(a.allocateId("d_1"), "d_1_NS_0");
-
-        // This is very degenerate, and maybe something that needs fixing.
-
-        assertEquals(a.allocateId("d_1_NS"), "d_1_NS_NS");
-    }
-
-    @Test
-    public void clear()
-    {
-        IdAllocator a = new IdAllocator();
-
-        assertEquals(a.allocateId("foo"), "foo");
-        assertEquals(a.allocateId("foo_0"), "foo_0");
-
-        a.clear();
-
-        assertEquals(a.allocateId("foo"), "foo");
-        assertEquals(a.allocateId("foo_0"), "foo_0");
-    }
-
-    @Test
-    public void clone_test()
-    {
-        IdAllocator a = new IdAllocator();
-
-        assertEquals(a.allocateId("foo"), "foo");
-        assertEquals(a.allocateId("foo_0"), "foo_0");
-        assertEquals(a.allocateId("foo"), "foo_1");
-
-        IdAllocator b = a.clone();
-
-        // After making a clone, parallel operations should return the same results.
-        // If anything under the covers was shared, then parallel operations would
-        // interfere with each other.
-
-        assertEquals(b.allocateId("bar"), a.allocateId("bar"));
-        assertEquals(b.allocateId("foo"), a.allocateId("foo"));
-        assertEquals(b.allocateId("foo_0"), a.allocateId("foo_0"));
-
-    }
-
-}


Mime
View raw message