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 20:50:31 UTC
[14/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/e86bf1a3
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/e86bf1a3
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/e86bf1a3
Branch: refs/heads/master
Commit: e86bf1a3d34ddc7945f7a6e1dbfcbda6b3300b0e
Parents: fc2bf6f
Author: Howard M. Lewis Ship <hl...@gmail.com>
Authored: Fri May 4 14:36:57 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 16 11:50:13 2012 -0700
----------------------------------------------------------------------
.../services/JustInTimeObjectCreatorSpec.groovy | 52 +++++++++
.../services/JustInTimeObjectCreatorTest.java | 83 ---------------
2 files changed, 52 insertions(+), 83 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e86bf1a3/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorSpec.groovy
new file mode 100644
index 0000000..c1e9628
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorSpec.groovy
@@ -0,0 +1,52 @@
+package org.apache.tapestry5.ioc.internal.services
+
+import org.apache.tapestry5.ioc.ObjectCreator
+import org.apache.tapestry5.ioc.internal.ServiceActivityTracker
+import org.apache.tapestry5.ioc.services.Status
+import spock.lang.Specification
+
+class JustInTimeObjectCreatorSpec extends Specification {
+
+ static final String SERVICE_ID = "FooBar";
+
+ def "can not create object after shutdown"() {
+
+ ObjectCreator creator = Mock()
+
+ def jit = new JustInTimeObjectCreator(null, creator, SERVICE_ID)
+
+ // Simulate the invocation from the Registry when it shuts down.
+ jit.run()
+
+ when:
+
+ jit.createObject()
+
+ then:
+
+ RuntimeException e = thrown()
+
+ e.message.contains "Proxy for service FooBar is no longer active because the IOC Registry has been shut down."
+ }
+
+ def "lazily instantiates the object via its delegate creator"() {
+
+ ObjectCreator creator = Mock()
+ Object service = new Object()
+ ServiceActivityTracker tracker = Mock()
+
+ def jit = new JustInTimeObjectCreator(tracker, creator, SERVICE_ID)
+
+ when:
+
+ jit.eagerLoadService()
+
+ then:
+
+ 1 * creator.createObject() >> service
+ 1 * tracker.setStatus(SERVICE_ID, Status.REAL)
+ 0 * _
+
+ jit.createObject().is service
+ }
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e86bf1a3/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorTest.java
deleted file mode 100644
index 6117598..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2007, 2009, 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.ObjectCreator;
-import org.apache.tapestry5.ioc.internal.IOCInternalTestCase;
-import org.apache.tapestry5.ioc.internal.ServiceActivityTracker;
-import org.apache.tapestry5.ioc.services.Status;
-import org.testng.annotations.Test;
-
-public class JustInTimeObjectCreatorTest extends IOCInternalTestCase
-{
- private static final String SERVICE_ID = "FooBar";
-
- @Test
- public void create_after_shutdown()
- {
- ObjectCreator creator = mockObjectCreator();
-
- replay();
-
- JustInTimeObjectCreator j = new JustInTimeObjectCreator(null, creator, SERVICE_ID);
-
- j.run();
-
- try
- {
- j.createObject();
- unreachable();
- }
- catch (RuntimeException ex)
- {
- assertMessageContains(ex,
- "Proxy for service FooBar is no longer active because the IOC Registry has been shut down.");
- }
- }
-
- @Test
- public void eager_load()
- {
- ObjectCreator creator = mockObjectCreator();
- Object service = new Object();
- ServiceActivityTracker tracker = mockServiceActivityTracker();
-
- replay();
-
- JustInTimeObjectCreator j = new JustInTimeObjectCreator(tracker, creator, SERVICE_ID);
-
- verify();
-
- // First access: use the creator to get the actual object.
-
- train_createObject(creator, service);
-
- tracker.setStatus(SERVICE_ID, Status.REAL);
-
- replay();
-
- j.eagerLoadService();
-
- verify();
-
- // This part tests the caching part.
-
- replay();
-
- assertSame(j.createObject(), service);
-
- verify();
- }
-}