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:32 UTC
[35/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/64b1b184
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/64b1b184
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/64b1b184
Branch: refs/heads/master
Commit: 64b1b1846b4e89e1ed83620b864c97c32c70cd3f
Parents: d76df13
Author: Howard M. Lewis Ship <hl...@gmail.com>
Authored: Tue May 1 09:42:37 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 16 11:49:41 2012 -0700
----------------------------------------------------------------------
.../internal/services/ChainBuilderImplSpec.groovy | 121 +++++++++++
.../internal/services/ChainBuilderImplTest.java | 159 ---------------
.../ioc/internal/services/ChainCommand.java | 29 ---
3 files changed, 121 insertions(+), 188 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/64b1b184/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ChainBuilderImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ChainBuilderImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ChainBuilderImplSpec.groovy
new file mode 100644
index 0000000..a2b5a3a
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ChainBuilderImplSpec.groovy
@@ -0,0 +1,121 @@
+package org.apache.tapestry5.ioc.internal.services
+
+import org.apache.tapestry.ioc.AbstractSharedRegistrySpecification
+import org.apache.tapestry5.ioc.services.ChainBuilder
+
+interface ChainCommand {
+ void run();
+
+ int workInt(int input);
+
+ boolean workBoolean(boolean input);
+
+ double workDouble(double input);
+
+ String workString(String input);
+}
+
+class ChainBuilderImplSpec extends AbstractSharedRegistrySpecification {
+
+ ChainCommand c1 = Mock()
+ ChainCommand c2 = Mock()
+
+ ChainCommand chain = getService(ChainBuilder).build(ChainCommand, [c1, c2])
+
+ def "chaining of simple void method with no parameters"() {
+ when:
+
+ chain.run()
+
+ then:
+
+ 1 * c1.run()
+
+ then:
+
+ 1 * c2.run()
+ 0 * _
+ }
+
+ def "chaining of method with int parameter and return type"() {
+
+ when:
+
+ assert chain.workInt(7) == 99
+
+ then:
+
+ 1 * c1.workInt(7) >> 0
+
+ then:
+
+ 1 * c2.workInt(7) >> 99
+ 0 * _
+ }
+
+ def "verify that an int method that returns a non-zero value short-circuits the chain"() {
+ when:
+
+ assert chain.workInt(7) == 88
+
+ then:
+
+ 1 * c1.workInt(7) >> 88
+ 0 * _
+ }
+
+ def "verify boolean parameters, return type, and short circuiting"() {
+
+ when:
+
+ assert chain.workBoolean(true) == true
+
+ then:
+
+ 1 * c1.workBoolean(true) >> false
+
+ then:
+
+ 1 * c2.workBoolean(true) >> true
+ 0 * _
+ }
+
+ def "verify string method parameter, return type, and short circuiting"() {
+ when:
+
+ assert chain.workString("fred") == "flintstone"
+
+ then:
+
+ 1 * c1.workString("fred") >> null
+
+ then:
+
+ 1 * c2.workString("fred") >> "flintstone"
+ 0 * _
+ }
+
+ def "verify double method parameter, return type, and short circuiting"() {
+
+ when:
+
+ assert chain.workDouble(1.2d) == 3.14d
+
+ then:
+
+ 1 * c1.workDouble(1.2d) >> 0d
+
+ then:
+
+ 1 * c2.workDouble(1.2d) >> 3.14d
+ 0 * _
+ }
+
+ def "chain instance has reasonable toString()"() {
+ expect:
+
+ chain.toString() == "<Command chain of org.apache.tapestry5.ioc.internal.services.ChainCommand>"
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/64b1b184/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ChainBuilderImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ChainBuilderImplTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ChainBuilderImplTest.java
deleted file mode 100644
index 826aa59..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ChainBuilderImplTest.java
+++ /dev/null
@@ -1,159 +0,0 @@
-// Copyright 2006, 2007, 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.ioc.internal.services;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.tapestry5.ioc.internal.IOCInternalTestCase;
-import org.apache.tapestry5.ioc.services.ChainBuilder;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-public class ChainBuilderImplTest extends IOCInternalTestCase
-{
- @Test
- public void simple_void_method()
- {
- Runnable r1 = mockRunnable();
- Runnable r2 = mockRunnable();
-
- // Training:
-
- r1.run();
- r2.run();
-
- replay();
-
- Runnable chain = build(Runnable.class, r1, r2);
-
- chain.run();
-
- verify();
-
- Assert.assertEquals(chain.toString(), "<Command chain of java.lang.Runnable>");
- }
-
- @Test
- public void int_method()
- {
- ChainCommand c1 = mockChainCommand();
- ChainCommand c2 = mockChainCommand();
-
- expect(c1.workInt(7)).andReturn(0);
-
- expect(c2.workInt(7)).andReturn(99);
-
- replay();
-
- ChainCommand chain = build(ChainCommand.class, c1, c2);
-
- assertEquals(chain.workInt(7), 99);
-
- verify();
- }
-
- @Test
- public void int_method_shortcircuits()
- {
- ChainCommand c1 = mockChainCommand();
- ChainCommand c2 = mockChainCommand();
-
- expect(c1.workInt(7)).andReturn(88);
-
- replay();
-
- ChainCommand chain = build(ChainCommand.class, c1, c2);
-
- assertEquals(chain.workInt(7), 88);
-
- verify();
- }
-
- @Test
- public void boolean_method()
- {
- ChainCommand c1 = mockChainCommand();
- ChainCommand c2 = mockChainCommand();
-
- train_workBoolean(c1, true, false);
- train_workBoolean(c2, true, true);
-
- replay();
-
- ChainCommand chain = build(ChainCommand.class, c1, c2);
-
- assertEquals(chain.workBoolean(true), true);
-
- verify();
- }
-
- protected final void train_workBoolean(ChainCommand command, boolean parameter, boolean result)
- {
- expect(command.workBoolean(parameter)).andReturn(result);
- }
-
- @Test
- public void string_method()
- {
- ChainCommand c1 = mockChainCommand();
- ChainCommand c2 = mockChainCommand();
-
- expect(c1.workString("fred")).andReturn(null);
-
- expect(c2.workString("fred")).andReturn("flintstone");
-
- replay();
-
- ChainCommand chain = build(ChainCommand.class, c1, c2);
-
- assertEquals(chain.workString("fred"), "flintstone");
-
- verify();
-
- }
-
- @Test
- public void double_method()
- {
- ChainCommand c1 = mockChainCommand();
- ChainCommand c2 = mockChainCommand();
-
- expect(c1.workDouble(1.2d)).andReturn(0d);
-
- expect(c2.workDouble(1.2d)).andReturn(3.14d);
-
- replay();
-
- ChainCommand chain = build(ChainCommand.class, c1, c2);
-
- assertEquals(chain.workDouble(1.2d), 3.14d);
-
- verify();
- }
-
- private ChainCommand mockChainCommand()
- {
- return newMock(ChainCommand.class);
- }
-
- private <T> T build(Class<T> commandInterface, T... commands)
- {
- List<T> list = Arrays.asList(commands);
-
- return getService(ChainBuilder.class).build(commandInterface, list);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/64b1b184/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ChainCommand.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ChainCommand.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ChainCommand.java
deleted file mode 100644
index 2cada46..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ChainCommand.java
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2006 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;
-
-/**
- * Used with {@link org.apache.tapestry5.ioc.internal.services.ChainBuilderImplTest}.
- */
-public interface ChainCommand
-{
- int workInt(int input);
-
- boolean workBoolean(boolean input);
-
- double workDouble(double input);
-
- String workString(String input);
-}