tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [1/4] git commit: Convert TestNG to Spock
Date Mon, 11 Jun 2012 22:07:33 GMT
Updated Branches:
  refs/heads/master f576d28e5 -> 17f0c48f3


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

Branch: refs/heads/master
Commit: 17f0c48f30c9477f8a36235f05e1cafd7008f66b
Parents: b6bc16c
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Mon Jun 11 15:07:20 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Mon Jun 11 15:07:20 2012 -0700

----------------------------------------------------------------------
 .../ioc/services/OperationAdvisorSpec.groovy       |   83 +++++++++++
 .../ioc/services/OperationAdvisorTest.java         |  111 ---------------
 2 files changed, 83 insertions(+), 111 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/17f0c48f/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/OperationAdvisorSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/OperationAdvisorSpec.groovy
b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/OperationAdvisorSpec.groovy
new file mode 100644
index 0000000..6aca825
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/OperationAdvisorSpec.groovy
@@ -0,0 +1,83 @@
+package org.apache.tapestry5.ioc.services
+
+import org.apache.tapestry5.ioc.OperationTracker
+import org.apache.tapestry5.ioc.internal.DefaultModuleDefImpl
+import org.apache.tapestry5.ioc.internal.LoggerSourceImpl
+import org.apache.tapestry5.ioc.internal.RegistryImpl
+import org.apache.tapestry5.ioc.internal.services.PlasticProxyFactoryImpl
+import spock.lang.AutoCleanup
+import spock.lang.Shared
+import spock.lang.Specification
+
+class OperationAdvisorSpec extends Specification {
+
+  @Shared @AutoCleanup("shutdown")
+  def registry
+
+  @Shared
+  def operations = []
+
+  def setupSpec() {
+
+    def classLoader = Thread.currentThread().contextClassLoader
+    def loggerSource = new LoggerSourceImpl()
+
+    def logger = loggerSource.getLogger(OperationAdvisorSpec)
+    def proxyFactoryLogger = loggerSource.getLogger(PlasticProxyFactory)
+
+    def plasticProxyFactory = new PlasticProxyFactoryImpl(classLoader, proxyFactoryLogger)
+
+    def simpleOperationTracker = [
+
+        run: { description, operation ->
+          operations << description
+          operation.run()
+        },
+
+        invoke: {description, operation ->
+          operations << description
+          operation.invoke()
+        }
+    ] as OperationTracker
+
+    registry = new RegistryImpl([
+        new DefaultModuleDefImpl(TapestryIOCModule, logger, plasticProxyFactory),
+        new DefaultModuleDefImpl(OperationTrackedModule, logger, plasticProxyFactory)],
+        plasticProxyFactory,
+        loggerSource,
+        simpleOperationTracker)
+  }
+
+  def "simple operation tracking"() {
+    def service = registry.getService OperationTrackedService
+
+    service.nonOperation()
+
+    when:
+
+    operations.clear()
+
+    service.first()
+
+    then:
+
+    operations == ["First operation"]
+  }
+
+  def "complex operation tracking"() {
+    def service = registry.getService OperationTrackedService
+
+    service.nonOperation()
+
+    operations.clear()
+
+    when:
+
+    service.second "foo"
+    service.second "bar"
+
+    then:
+
+    operations == ["Second operation: foo", "Second operation: bar"]
+  }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/17f0c48f/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/services/OperationAdvisorTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/services/OperationAdvisorTest.java
b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/services/OperationAdvisorTest.java
deleted file mode 100644
index 8788b37..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/services/OperationAdvisorTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package org.apache.tapestry5.ioc.services;
-
-import org.apache.tapestry5.ioc.Invokable;
-import org.apache.tapestry5.ioc.LoggerSource;
-import org.apache.tapestry5.ioc.OperationTracker;
-import org.apache.tapestry5.ioc.Registry;
-import org.apache.tapestry5.ioc.def.ModuleDef;
-import org.apache.tapestry5.ioc.internal.DefaultModuleDefImpl;
-import org.apache.tapestry5.ioc.internal.LoggerSourceImpl;
-import org.apache.tapestry5.ioc.internal.RegistryImpl;
-import org.apache.tapestry5.ioc.internal.services.PlasticProxyFactoryImpl;
-import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
-import org.apache.tapestry5.ioc.test.IOCTestCase;
-import org.slf4j.Logger;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import java.util.List;
-
-/**
- * Tests for the {@link OperationAdvisor} service.
- *
- * @since 5.4
- */
-public class OperationAdvisorTest extends IOCTestCase
-{
-    private List<String> operations = CollectionFactory.newList();
-
-    private Registry registry;
-
-    @BeforeClass
-    public void setup()
-    {
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-        LoggerSource loggerSource = new LoggerSourceImpl();
-
-        Logger logger = loggerSource.getLogger(OperationAdvisorTest.class);
-        Logger proxyFactoryLogger = loggerSource.getLogger(TapestryIOCModule.class.getName()
+ ".PlasticProxyFactory");
-
-        PlasticProxyFactory plasticProxyFactory = new PlasticProxyFactoryImpl(classLoader,
proxyFactoryLogger);
-
-        List<ModuleDef> modules = CollectionFactory.newList();
-
-        modules.add(new DefaultModuleDefImpl(TapestryIOCModule.class, logger, plasticProxyFactory));
-        modules.add(new DefaultModuleDefImpl(OperationTrackedModule.class, logger, plasticProxyFactory));
-
-        OperationTracker simpleOperationTracker = new OperationTracker()
-        {
-            @Override
-            public void run(String description, Runnable operation)
-            {
-                operations.add(description);
-
-                operation.run();
-            }
-
-            @Override
-            public <T> T invoke(String description, Invokable<T> operation)
-            {
-                operations.add(description);
-
-                return operation.invoke();
-            }
-        };
-
-        registry = new RegistryImpl(modules, plasticProxyFactory, loggerSource, simpleOperationTracker);
-    }
-
-    @AfterClass
-    public void cleanup()
-    {
-        registry.shutdown();
-
-        registry = null;
-
-        operations = null;
-    }
-
-    @Test
-    public void simple_operation_tracking()
-    {
-        OperationTrackedService service = registry.getService(OperationTrackedService.class);
-
-        service.nonOperation();
-
-        operations.clear();
-
-        service.first();
-
-        assertListsEquals(operations, "First operation");
-    }
-
-    @Test
-    public void complex_operation_tracking()
-    {
-        OperationTrackedService service = registry.getService(OperationTrackedService.class);
-
-        service.nonOperation();
-
-        operations.clear();
-
-        service.second("foo");
-
-        service.second("bar");
-
-        assertListsEquals(operations, "Second operation: foo", "Second operation: bar");
-    }
-
-
-}


Mime
View raw message