tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [2/4] git commit: Convert TestNG to Spock
Date Mon, 11 Jun 2012 22:07:33 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/b6bc16c3
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/b6bc16c3
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/b6bc16c3

Branch: refs/heads/master
Commit: b6bc16c38bc9b7b08fd93bef4535a94eacaa0a52
Parents: 2fcbeef
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Mon Jun 11 14:49:49 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Mon Jun 11 14:49:49 2012 -0700

----------------------------------------------------------------------
 .../services/PropertyShadowBuilderImplSpec.groovy  |  122 ++++++++++
 .../services/PropertyShadowBuilderImplTest.java    |  183 ---------------
 2 files changed, 122 insertions(+), 183 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b6bc16c3/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PropertyShadowBuilderImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PropertyShadowBuilderImplSpec.groovy
b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PropertyShadowBuilderImplSpec.groovy
new file mode 100644
index 0000000..5a7bfaa
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PropertyShadowBuilderImplSpec.groovy
@@ -0,0 +1,122 @@
+package org.apache.tapestry5.ioc.internal.services
+
+import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
+import org.apache.tapestry5.ioc.services.PropertyShadowBuilder
+import spock.lang.Shared
+
+interface Foo {
+
+  void foo();
+}
+
+class FooHolder {
+
+  private Foo foo;
+
+  private int count = 0;
+
+  public Foo getFoo() {
+    count++;
+
+    return foo;
+  }
+
+  public int getCount() {
+    return count;
+  }
+
+  public void setFoo(Foo foo) {
+    this.foo = foo;
+  }
+
+  @Override
+  public String toString() {
+    return "[FooHolder]";
+  }
+
+  public void setWriteOnly(Foo foo) {
+
+  }
+}
+
+class PropertyShadowBuilderImplSpec extends AbstractSharedRegistrySpecification {
+
+  @Shared
+  PropertyShadowBuilder builder
+
+  Foo foo = Mock()
+  FooHolder holder = new FooHolder();
+
+  def setupSpec() {
+    builder = getService PropertyShadowBuilder
+  }
+
+
+  def "basic delegation from proxy to property"() {
+
+    Foo shadow = builder.build(holder, "foo", Foo)
+
+    holder.foo = foo
+
+
+    when:
+
+    shadow.foo()
+
+    then:
+
+    foo.foo()
+    holder.count == 1
+
+    shadow.toString() == "<Shadow: property foo of [FooHolder]>"
+
+    when:
+
+    shadow.foo()
+
+    then:
+
+    foo.foo()
+    holder.count == 2
+  }
+
+  def "verify exception when accessing the value when null"() {
+
+    Foo shadow = builder.build(holder, "foo", Foo)
+
+    when:
+
+    shadow.foo()
+
+    then:
+
+    NullPointerException e = thrown()
+
+    e.message == "Unable to delegate method invocation to property 'foo' of [FooHolder],
because the property is null."
+  }
+
+  def "property type mismatch"() {
+    when:
+
+    builder.build(holder, "count", Map)
+
+    then:
+
+    RuntimeException e = thrown()
+
+    e.message == "Property 'count' of class ${FooHolder.name} is of type int, which is not
assignable to type java.util.Map."
+  }
+
+  def "attempting to build for a write-only property is an exception"() {
+    when:
+
+    builder.build(holder, "writeOnly", Foo)
+
+    then:
+
+    RuntimeException e = thrown()
+
+    e.message == "Class ${FooHolder.name} does not provide an accessor ('getter') method
for property 'writeOnly'."
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b6bc16c3/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/services/PropertyShadowBuilderImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/services/PropertyShadowBuilderImplTest.java
b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/services/PropertyShadowBuilderImplTest.java
deleted file mode 100644
index fbae24c..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/services/PropertyShadowBuilderImplTest.java
+++ /dev/null
@@ -1,183 +0,0 @@
-// Copyright 2006, 2007, 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.services;
-
-import org.apache.tapestry5.ioc.Registry;
-import org.apache.tapestry5.ioc.test.IOCTestCase;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import java.util.Map;
-
-public class PropertyShadowBuilderImplTest extends IOCTestCase
-{
-    private Registry registry;
-    private PropertyShadowBuilder builder;
-
-    private final String CLASS_NAME = getClass().getName();
-
-    @BeforeClass
-    public void setup_registry()
-    {
-        registry = buildRegistry();
-
-        builder = registry.getService("PropertyShadowBuilder", PropertyShadowBuilder.class);
-    }
-
-    @AfterClass
-    public void shutdown_registry()
-    {
-        registry.shutdown();
-
-        registry = null;
-        builder = null;
-    }
-
-    public class FooHolder
-    {
-        private Foo foo;
-
-        private int count = 0;
-
-        public Foo getFoo()
-        {
-            count++;
-
-            return foo;
-        }
-
-        public int getCount()
-        {
-            return count;
-        }
-
-        public void setFoo(Foo foo)
-        {
-            this.foo = foo;
-        }
-
-        @Override
-        public String toString()
-        {
-            return "[FooHolder]";
-        }
-
-        public void setWriteOnly(Foo foo)
-        {
-
-        }
-    }
-
-    public interface Foo
-    {
-        void foo();
-    }
-
-    @Test
-    public void basic_delegation()
-    {
-        Foo foo = newMock(Foo.class);
-        FooHolder holder = new FooHolder();
-
-        holder.setFoo(foo);
-
-        Foo shadow = builder.build(holder, "foo", Foo.class);
-
-        for (int i = 0; i < 3; i++)
-        {
-            foo.foo();
-
-            replay();
-
-            shadow.foo();
-
-            verify();
-
-            assertEquals(holder.getCount(), i + 1);
-        }
-
-        assertEquals(shadow.toString(), "<Shadow: property foo of [FooHolder]>");
-    }
-
-    @Test
-    public void property_is_null()
-    {
-        FooHolder holder = new FooHolder();
-
-        Foo shadow = builder.build(holder, "foo", Foo.class);
-
-        try
-        {
-            shadow.foo();
-            unreachable();
-        }
-        catch (NullPointerException ex)
-        {
-            assertEquals(ex.getMessage(),
-                    "Unable to delegate method invocation to property 'foo' of [FooHolder],
because the property is null.");
-        }
-    }
-
-    @Test
-    public void property_does_not_exist()
-    {
-        FooHolder holder = new FooHolder();
-
-        try
-        {
-            builder.build(holder, "bar", Foo.class);
-            unreachable();
-        }
-        catch (RuntimeException ex)
-        {
-            assertEquals(ex.getMessage(), "Class " + CLASS_NAME + "$FooHolder does not contain
a property named 'bar'.");
-        }
-    }
-
-    @Test
-    public void property_type_mismatch()
-    {
-        FooHolder holder = new FooHolder();
-
-        try
-        {
-            builder.build(holder, "count", Map.class);
-            unreachable();
-        }
-        catch (RuntimeException ex)
-        {
-            assertEquals(ex.getMessage(), "Property 'count' of class " + CLASS_NAME
-                    + "$FooHolder is of type int, which is not assignable to type java.util.Map.");
-        }
-    }
-
-    @Test
-    public void property_write_only()
-    {
-        FooHolder holder = new FooHolder();
-
-        try
-        {
-            builder.build(holder, "writeOnly", Foo.class);
-            unreachable();
-        }
-        catch (RuntimeException ex)
-        {
-            assertEquals(ex.getMessage(), "Class " + CLASS_NAME
-                    + "$FooHolder does not provide an accessor ('getter') method for property
'writeOnly'.");
-        }
-    }
-}


Mime
View raw message