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 23:28:15 UTC

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

Branch: refs/heads/master
Commit: f877aac2d891e8ee46a409bf4314471caa4d5a5e
Parents: 09bbb38
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed May 16 14:03:34 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 16 14:03:34 2012 -0700

----------------------------------------------------------------------
 .../services/PipelineBuilderImplSpec.groovy        |   86 +++++++++
 .../internal/services/PipelineBuilderImplTest.java |  149 ---------------
 2 files changed, 86 insertions(+), 149 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/f877aac2/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImplSpec.groovy
new file mode 100644
index 0000000..1610a93
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImplSpec.groovy
@@ -0,0 +1,86 @@
+package org.apache.tapestry5.ioc.internal.services
+
+import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
+import org.apache.tapestry5.ioc.services.PipelineBuilder
+import org.slf4j.Logger
+import spock.lang.Shared
+
+class PipelineBuilderImplSpec extends AbstractSharedRegistrySpecification {
+
+  @Shared
+  PipelineBuilder builder
+
+  def setupSpec() { builder = getService PipelineBuilder }
+
+  Logger logger = Mock()
+
+  def "standard pipeline with filters"() {
+
+    // For some reason, this didn't work with closures, just with actual inner classes
+
+    StandardFilter subtracter = new StandardFilter() {
+
+      @Override
+      int run(int i, StandardService service) {
+        service.run(i) - 2
+      }
+    }
+
+    StandardFilter multiplier = new StandardFilter() {
+
+      @Override
+      int run(int i, StandardService service) {
+        2 * service.run(i)
+      }
+    }
+
+    StandardFilter adder = new StandardFilter() {
+
+      @Override
+      int run(int i, StandardService service) {
+        service.run(i + 3)
+      }
+    }
+
+    StandardService terminator = new StandardService() {
+
+      @Override
+      int run(int i) {
+        i
+      }
+    }
+
+    when:
+
+    StandardService pipeline = builder.build logger, StandardService, StandardFilter, [subtracter, multiplier, adder], terminator
+
+    then:
+
+    pipeline.run(5) == 14
+    pipeline.run(10) == 24
+  }
+
+  def "a pipeline without filters is simply the temrinator"() {
+
+    StandardService terminator = Mock()
+
+    when:
+
+    StandardService pipeline = builder.build logger, StandardService, StandardFilter, [], terminator
+
+    then:
+
+    pipeline.is terminator
+  }
+
+  def "a pipeline with no filters and no terminator does nothing"() {
+    when:
+
+    StandardService pipeline = builder.build logger, StandardService, StandardFilter, []
+
+    then:
+
+    pipeline.run(99) == 0
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/f877aac2/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImplTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImplTest.java
deleted file mode 100644
index a4fec05..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImplTest.java
+++ /dev/null
@@ -1,149 +0,0 @@
-// Copyright 2006, 2007 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.Registry;
-import org.apache.tapestry5.ioc.internal.IOCInternalTestCase;
-import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList;
-import org.apache.tapestry5.ioc.services.PipelineBuilder;
-import org.slf4j.Logger;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Integration tests for the PipelineBuilder service.
- */
-public class PipelineBuilderImplTest extends IOCInternalTestCase
-{
-
-    private PipelineBuilder builder;
-
-    private Registry registry;
-
-    @BeforeClass
-    public void setup_builder()
-    {
-        registry = buildRegistry();
-        builder = registry.getService("PipelineBuilder", PipelineBuilder.class);
-    }
-
-    @AfterClass
-    public void shutdown_builder()
-    {
-        registry.shutdown();
-
-        builder = null;
-        registry = null;
-    }
-
-    @Test
-    public void pipeline_with_filters()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        StandardFilter subtracter = new StandardFilter()
-        {
-            public int run(int i, StandardService service)
-            {
-                return service.run(i) - 2;
-            }
-        };
-
-        StandardFilter multiplier = new StandardFilter()
-        {
-            public int run(int i, StandardService service)
-            {
-                return 2 * service.run(i);
-            }
-        };
-
-        StandardFilter adder = new StandardFilter()
-        {
-            public int run(int i, StandardService service)
-            {
-                return service.run(i + 3);
-            }
-        };
-
-        StandardService terminator = new StandardService()
-        {
-            public int run(int i)
-            {
-                return i;
-            }
-        };
-
-        StandardService pipeline = builder.build(
-                logger,
-                StandardService.class,
-                StandardFilter.class,
-                Arrays.asList(subtracter, multiplier, adder),
-                terminator);
-
-        // Should be order subtracter, multipler, adder
-        assertEquals(pipeline.run(5), 14);
-        assertEquals(pipeline.run(10), 24);
-
-        verify();
-    }
-
-    @Test
-    public void pipeline_without_filters_is_terminator()
-    {
-        Logger logger = mockLogger();
-        StandardService terminator = newMock(StandardService.class);
-
-        replay();
-
-        List<StandardFilter> filters = newList();
-
-        StandardService pipeline = builder.build(
-                logger,
-                StandardService.class,
-                StandardFilter.class,
-                filters,
-                terminator);
-
-        assertSame(pipeline, terminator);
-
-        verify();
-    }
-
-    @Test
-    public void pipeline_with_default_terminator()
-    {
-        Logger logger = mockLogger();
-
-        replay();
-
-        List<StandardFilter> filters = newList();
-
-        StandardService pipeline = builder.build(
-                logger,
-                StandardService.class,
-                StandardFilter.class,
-                filters);
-
-        assertEquals(pipeline.run(99), 0);
-
-        verify();
-    }
-}