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

[1/2] git commit: Convert TestNG to Spock

Updated Branches:
  refs/heads/master 09bbb38c7 -> 8a4fd5eed


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

Branch: refs/heads/master
Commit: 8a4fd5eed973fc507b198dd3335bfdc6e383f8d8
Parents: f877aac
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed May 16 14:28:08 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 16 14:28:08 2012 -0700

----------------------------------------------------------------------
 .../services/RegistryshutdownHubImplSpec.groovy    |  105 ++++++++++++
 .../services/RegistryShutdownHubImplTest.java      |  127 ---------------
 2 files changed, 105 insertions(+), 127 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8a4fd5ee/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryshutdownHubImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryshutdownHubImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryshutdownHubImplSpec.groovy
new file mode 100644
index 0000000..09b3f82
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryshutdownHubImplSpec.groovy
@@ -0,0 +1,105 @@
+package org.apache.tapestry5.ioc.internal.services
+
+import org.apache.tapestry5.ioc.services.RegistryShutdownListener
+import org.slf4j.Logger
+import spock.lang.Specification
+
+class RegistryshutdownHubImplSpec extends Specification {
+
+  RegistryShutdownHubImpl hub
+  Logger logger = Mock()
+
+  def setup() {
+    hub = new RegistryShutdownHubImpl(logger)
+  }
+
+  def "add old-style listeners and verify order"() {
+    RegistryShutdownListener l1 = Mock()
+    RegistryShutdownListener l2 = Mock()
+
+    when:
+
+    hub.addRegistryShutdownListener l1
+    hub.addRegistryShutdownListener l2
+
+    then:
+
+    0 * _
+
+    when:
+
+    hub.fireRegistryDidShutdown()
+
+    then:
+
+    1 * l1.registryDidShutdown()
+
+    then:
+
+    1 * l2.registryDidShutdown()
+    0 * _
+  }
+
+  def "will-shutdown-listeners are invoked before normal shutdown listeners"() {
+    Runnable will1 = Mock()
+    Runnable will2 = Mock()
+
+    RegistryShutdownListener l1 = Mock()
+    RegistryShutdownListener l2 = Mock()
+
+    hub.addRegistryWillShutdownListener will1
+    hub.addRegistryWillShutdownListener will2
+
+    hub.addRegistryShutdownListener l1
+    hub.addRegistryShutdownListener l2
+
+    when:
+
+    hub.fireRegistryDidShutdown()
+
+    then:
+
+    1 * will1.run()
+
+    then:
+
+    1 * will2.run()
+
+    then:
+
+    1 * l1.registryDidShutdown()
+    1 * l2.registryDidShutdown()
+    0 * _
+  }
+
+  def "an exception during notification is logged and notification continues"() {
+    Runnable l1 = Mock()
+    Runnable l2 = Mock()
+
+    hub.addRegistryShutdownListener l1
+    hub.addRegistryShutdownListener l2
+
+    RuntimeException e = new RuntimeException("Failure.")
+
+    when:
+
+    hub.fireRegistryDidShutdown()
+
+    then:
+
+    1 * l1.run() >> { throw e }
+    1 * logger.error(_, _) >> { message, exception ->
+      ["Error notifying", "registry shutdown", "Failure"].each {
+        assert message.contains(it)
+      }
+
+      assert exception.is(e)
+    }
+
+    then:
+
+    1 * l2.run()
+    0 * _
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8a4fd5ee/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/RegistryShutdownHubImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/RegistryShutdownHubImplTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/RegistryShutdownHubImplTest.java
deleted file mode 100644
index 2776157..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/RegistryShutdownHubImplTest.java
+++ /dev/null
@@ -1,127 +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 org.apache.tapestry5.ioc.internal.IOCInternalTestCase;
-import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
-import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
-import org.slf4j.Logger;
-import org.testng.annotations.Test;
-
-import java.util.List;
-
-import static org.easymock.EasyMock.contains;
-import static org.easymock.EasyMock.same;
-
-public class RegistryShutdownHubImplTest extends IOCInternalTestCase
-{
-
-    @Test
-    public void add_and_notify()
-    {
-        RegistryShutdownListener l1 = mockListener();
-        RegistryShutdownListener l2 = mockListener();
-        Logger logger = mockLogger();
-
-        l1.registryDidShutdown();
-        l2.registryDidShutdown();
-
-        replay();
-
-        RegistryShutdownHubImpl hub = new RegistryShutdownHubImpl(logger);
-
-        hub.addRegistryShutdownListener(l1);
-        hub.addRegistryShutdownListener(l2);
-
-        hub.fireRegistryDidShutdown();
-
-        verify();
-    }
-
-    @Test
-    public void pre_listeners_before_normal_listeners()
-    {
-        final List<String> ordering = CollectionFactory.newList();
-
-
-        RegistryShutdownHubImpl hub = new RegistryShutdownHubImpl(null);
-
-        for (int i = 1; i <= 3; i++)
-        {
-            final int k = i;
-
-            hub.addRegistryShutdownListener(new RegistryShutdownListener()
-            {
-                public void registryDidShutdown()
-                {
-                    ordering.add("did:" + k);
-                }
-            });
-
-            hub.addRegistryWillShutdownListener(new Runnable()
-            {
-                public void run()
-                {
-                    ordering.add("will:" + k);
-                }
-            });
-        }
-
-        hub.fireRegistryDidShutdown();
-
-        assertListsEquals(ordering, "will:1", "will:2", "will:3", "did:1", "did:2", "did:3");
-    }
-
-    /**
-     * Shows that multiple listener will be notified, and that an error in one doesn't prevent others from being
-     * notified.
-     */
-    @Test
-    public void notification_error()
-    {
-        RegistryShutdownListener l1 = mockListener();
-        RegistryShutdownListener l2 = mockListener();
-        RegistryShutdownListener l3 = mockListener();
-
-        Logger logger = mockLogger();
-
-        Throwable t = new RuntimeException("Shutdown failure.");
-
-        l1.registryDidShutdown();
-        l2.registryDidShutdown();
-        setThrowable(t);
-
-        logger.error(contains("Shutdown failure."), same(t));
-
-        l3.registryDidShutdown();
-
-        replay();
-
-        RegistryShutdownHubImpl hub = new RegistryShutdownHubImpl(logger);
-
-        hub.addRegistryShutdownListener(l1);
-        hub.addRegistryShutdownListener(l2);
-        hub.addRegistryShutdownListener(l3);
-
-        hub.fireRegistryDidShutdown();
-
-        verify();
-    }
-
-    private RegistryShutdownListener mockListener()
-    {
-        return newMock(RegistryShutdownListener.class);
-    }
-}