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/06/21 21:35:35 UTC

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

Branch: refs/heads/master
Commit: 8169bde464561b5ec2db122d0da7af01864a5422
Parents: ac83e0e
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Thu Jun 21 11:51:20 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Thu Jun 21 11:51:20 2012 -0700

----------------------------------------------------------------------
 .../ioc/specs/UpdateListenerHubImplSpec.groovy     |   54 +++++++++++
 .../services/UpdateListenerHubImplTest.java        |   71 ---------------
 2 files changed, 54 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8169bde4/tapestry-ioc/src/test/groovy/ioc/specs/UpdateListenerHubImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/UpdateListenerHubImplSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/UpdateListenerHubImplSpec.groovy
new file mode 100644
index 0000000..5e76926
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/UpdateListenerHubImplSpec.groovy
@@ -0,0 +1,54 @@
+package ioc.specs
+
+import org.apache.tapestry5.ioc.internal.services.UpdateListenerHubImpl
+import org.apache.tapestry5.services.UpdateListener
+import org.apache.tapestry5.services.UpdateListenerHub
+import spock.lang.Specification
+
+import java.lang.ref.WeakReference
+
+class UpdateListenerHubImplSpec extends Specification {
+
+  UpdateListenerHub hub = new UpdateListenerHubImpl()
+
+  def "add a listener and invoke it"() {
+
+    UpdateListener listener = Mock()
+
+    hub.addUpdateListener(listener)
+
+    when:
+
+    hub.fireCheckForUpdates()
+
+    then:
+
+    1 * listener.checkForUpdates()
+  }
+
+  def "weak references are not invoked once cleared"() {
+
+    // Can't do this with a mock, because we hold a live reference to a mock!
+    def listener = {
+      throw new RuntimeException("checkForUpdates() should not be invoked on a dead reference.")
+    } as UpdateListener
+
+    WeakReference ref = new WeakReference(listener)
+
+    hub.addUpdateListener(listener)
+
+    // Release the only live reference and wait for GC to reclaim it
+    listener = null
+
+    while (ref.get()) { System.gc() }
+
+    when:
+
+    hub.fireCheckForUpdates()
+
+    then:
+
+    noExceptionThrown()
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8169bde4/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/UpdateListenerHubImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/UpdateListenerHubImplTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/UpdateListenerHubImplTest.java
deleted file mode 100644
index 37727a8..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/UpdateListenerHubImplTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2006, 2007, 2008, 2010 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.lang.ref.WeakReference;
-
-import org.apache.tapestry5.ioc.internal.services.UpdateListenerHubImpl;
-import org.apache.tapestry5.ioc.test.TestBase;
-import org.apache.tapestry5.services.UpdateListener;
-import org.apache.tapestry5.services.UpdateListenerHub;
-import org.testng.annotations.Test;
-
-public class UpdateListenerHubImplTest extends TestBase
-{
-    @Test
-    public void add_listener_and_invoke() throws Exception
-    {
-        UpdateListener listener = newMock(UpdateListener.class);
-
-        UpdateListenerHub hub = new UpdateListenerHubImpl();
-
-        listener.checkForUpdates();
-
-        replay();
-
-        hub.addUpdateListener(listener);
-
-        hub.fireCheckForUpdates();
-
-        verify();
-    }
-
-    @Test
-    public void weak_references_are_not_invoked_once_clears() throws Exception
-    {
-        UpdateListener listener = new UpdateListener()
-        {
-            public void checkForUpdates()
-            {
-                throw new RuntimeException("checkForUpdates() should not be invoked on a dead reference.");
-            }
-        };
-
-        WeakReference<UpdateListener> ref = new WeakReference<UpdateListener>(listener);
-
-        UpdateListenerHub hub = new UpdateListenerHubImpl();
-
-        hub.addUpdateListener(listener);
-
-        listener = null;
-
-        while (ref.get() != null)
-        {
-            System.gc();
-        }
-
-        hub.fireCheckForUpdates();
-    }
-}