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/05/16 20:50:31 UTC
[12/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/ae71c0b2
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/ae71c0b2
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/ae71c0b2
Branch: refs/heads/master
Commit: ae71c0b2ff164e3aa94ebcced3c5bed1bfbe1dba
Parents: 32e20a2
Author: Howard M. Lewis Ship <hl...@gmail.com>
Authored: Tue May 8 13:10:01 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 16 11:50:14 2012 -0700
----------------------------------------------------------------------
.../DefaultImplementationBuilderImplSpec.groovy | 4 -
.../internal/services/MethodIteratorSpec.groovy | 109 +++++++++++
.../ioc/internal/services/ToString.groovy | 6 +
.../ioc/internal/services/MethodIteratorTest.java | 145 ---------------
4 files changed, 115 insertions(+), 149 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ae71c0b2/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy
index 9cdfa3d..3e7d8b5 100644
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/DefaultImplementationBuilderImplSpec.groovy
@@ -3,10 +3,6 @@ package org.apache.tapestry5.ioc.internal.services
import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
import org.apache.tapestry5.ioc.services.DefaultImplementationBuilder
-/** An interface that includes toString() */
-interface ToString {
- String toString();
-}
class DefaultImplementationBuilderImplSpec extends AbstractSharedRegistrySpecification {
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ae71c0b2/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MethodIteratorSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MethodIteratorSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MethodIteratorSpec.groovy
new file mode 100644
index 0000000..5bbf397
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MethodIteratorSpec.groovy
@@ -0,0 +1,109 @@
+package org.apache.tapestry5.ioc.internal.services
+
+import spock.lang.Specification
+import spock.lang.Unroll
+
+interface Play extends Runnable {
+ void jump()
+}
+
+interface Runnable2 {
+ void run()
+}
+
+interface Runnable3 extends Runnable, Runnable2 {
+
+}
+
+interface Openable {
+ public void open();
+}
+
+interface OpenableWithError {
+ public void open() throws IOException;
+}
+
+interface CombinedOpeneable extends Openable, OpenableWithError {
+}
+
+class MethodIteratorSpec extends Specification {
+
+ def "iterate a simple (single-method) interface"() {
+
+ MethodIterator mi = new MethodIterator(Runnable)
+
+ expect:
+
+ mi.hasNext()
+
+ when: "iterate to first method"
+
+ def actual = mi.next()
+
+ then: "first method signature returned"
+
+ actual == new MethodSignature(void, "run", null, null)
+
+ !mi.hasNext()
+
+ when: "iterating when no method signatures left"
+
+ mi.next()
+
+ then: "throws exception"
+
+ thrown(NoSuchElementException)
+ }
+
+ def "method inherited from super interface are visible"() {
+
+ MethodIterator mi = new MethodIterator(Play)
+
+ expect:
+
+ mi.hasNext()
+
+ mi.next() == new MethodSignature(void, "jump", null, null)
+
+ mi.hasNext()
+
+ mi.next() == new MethodSignature(void, "run", null, null)
+
+ !mi.hasNext()
+ }
+
+ @Unroll
+ def "getToString() on #interfaceType.name should be #expected"() {
+
+ expect:
+
+ new MethodIterator(interfaceType).getToString() == expected
+
+ where:
+
+ interfaceType | expected
+ Runnable | false
+ Play | false
+ ToString | true
+ }
+
+ def "method duplicated from a base interface into a sub interface are filtered out"() {
+ MethodIterator mi = new MethodIterator(Runnable3)
+
+ expect:
+
+ mi.next() == new MethodSignature(void, "run", null, null)
+ !mi.hasNext()
+ }
+
+ def "inherited methods are filtered out if less specific"() {
+ MethodIterator mi = new MethodIterator(CombinedOpeneable)
+
+ expect:
+
+ mi.next() == new MethodSignature(void, "open", null, [IOException] as Class[])
+
+ !mi.hasNext()
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ae71c0b2/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ToString.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ToString.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ToString.groovy
new file mode 100644
index 0000000..f2b0301
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ToString.groovy
@@ -0,0 +1,6 @@
+package org.apache.tapestry5.ioc.internal.services
+
+/** An interface that includes toString() */
+interface ToString {
+ String toString();
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ae71c0b2/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/MethodIteratorTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/MethodIteratorTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/MethodIteratorTest.java
deleted file mode 100644
index c035a01..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/MethodIteratorTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright 2006, 2012 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.services;
-
-import org.apache.tapestry5.ioc.test.IOCTestCase;
-import org.testng.annotations.Test;
-
-import java.io.IOException;
-import java.util.NoSuchElementException;
-
-public class MethodIteratorTest extends IOCTestCase
-{
- static interface Play extends Runnable
- {
- public void jump();
- }
-
- static interface Runnable2
- {
- public void run();
- }
-
- static interface Runnable3 extends Runnable, Runnable2
- {
- }
-
- static interface ToString
- {
- public String toString();
- }
-
- static interface Openable
- {
- public void open();
- }
-
- static interface OpenableWithError
- {
- public void open() throws IOException;
- }
-
- static interface CombinedOpeneable extends Openable, OpenableWithError
- {
- }
-
- @Test
- public void simple_interface()
- {
- MethodIterator mi = new MethodIterator(Runnable.class);
-
- assertTrue(mi.hasNext());
-
- MethodSignature actual = mi.next();
-
- assertEquals(new MethodSignature(void.class, "run", null, null), actual);
-
- assertFalse(mi.hasNext());
-
- try
- {
- mi.next();
- } catch (NoSuchElementException ex)
- {
- //
- }
-
- assertEquals(false, mi.getToString());
- }
-
- @Test
- public void inherited_methods_from_super_interface()
- {
- MethodIterator mi = new MethodIterator(Play.class);
-
- assertTrue(mi.hasNext());
-
- // Problematic because the order in which they are returned is
- // JDK specific and not defined! Perhaps we should sort by alpha?
-
- MethodSignature actual = mi.next();
-
- assertEquals(new MethodSignature(void.class, "jump", null, null), actual);
-
- assertTrue(mi.hasNext());
-
- actual = mi.next();
-
- assertEquals(new MethodSignature(void.class, "run", null, null), actual);
-
- assertFalse(mi.hasNext());
-
- assertEquals(false, mi.getToString());
- }
-
- @Test
- public void duplicate_methods_filtered_out()
- {
- MethodIterator mi = new MethodIterator(Runnable3.class);
-
- MethodSignature actual = mi.next();
-
- assertEquals(new MethodSignature(void.class, "run", null, null), actual);
-
- assertEquals(false, mi.getToString());
- }
-
- @Test
- public void to_string_method_identified()
- {
- MethodIterator mi = new MethodIterator(ToString.class);
-
- // Show that this is known immediately.
-
- assertEquals(true, mi.getToString());
-
- MethodSignature actual = mi.next();
-
- assertEquals(new MethodSignature(String.class, "toString", null, null), actual);
-
- }
-
- @Test
- public void inherited_methods_filtered_if_less_specific()
- {
- MethodIterator mi = new MethodIterator(CombinedOpeneable.class);
-
- MethodSignature actual = mi.next();
-
- assertEquals(new MethodSignature(void.class, "open", null, new Class[]{IOException.class}), actual);
-
- assertEquals(false, mi.hasNext());
- }
-}