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/01 17:28:33 UTC
[1/2] git commit: Convert TestNG to Spock
Updated Branches:
refs/heads/master d6e5f4131 -> 399b52c77
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/399b52c7
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/399b52c7
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/399b52c7
Branch: refs/heads/master
Commit: 399b52c771c7afe4d89a420fd1ff13f534e7e1f5
Parents: d31c08c
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Fri Jun 1 08:26:20 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Fri Jun 1 08:26:20 2012 -0700
----------------------------------------------------------------------
...RecursiveServiceCreationCheckWrapperSpec.groovy | 80 +++++++++++
.../RecursiveServiceCreationCheckWrapperTest.java | 105 ---------------
2 files changed, 80 insertions(+), 105 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/399b52c7/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperSpec.groovy
new file mode 100644
index 0000000..703d50e
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperSpec.groovy
@@ -0,0 +1,80 @@
+package org.apache.tapestry5.ioc.internal
+
+import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
+import org.apache.tapestry5.ioc.ObjectCreator
+import org.apache.tapestry5.ioc.def.ServiceDef
+import org.slf4j.Logger
+
+class RecursiveServiceCreationCheckWrapperSpec extends AbstractSharedRegistrySpecification {
+
+ static DESCRIPTION = "{SOURCE DESCRIPTION}"
+
+ Logger logger = Mock()
+ ObjectCreatorSource source = Mock()
+ ObjectCreator delegate = Mock()
+ Object service = Mock()
+
+ ServiceDef sd = new ServiceDefImpl(Runnable, null, "Bar", null, "singleton", false, false, source)
+
+ def "ensure that the creator is called only once"() {
+
+ when:
+
+ ObjectCreator wrapper = new RecursiveServiceCreationCheckWrapper(sd, delegate, logger)
+
+ def actual = wrapper.createObject()
+
+ then:
+
+ actual == service
+
+ 1 * delegate.createObject() >> service
+
+ when:
+
+ wrapper.createObject()
+
+ then:
+
+ IllegalStateException e = thrown()
+
+ e.message.contains "Construction of service 'Bar' has failed due to recursion"
+ e.message.contains DESCRIPTION
+
+ 1 * source.description >> DESCRIPTION
+ }
+
+ def "construction exceptions are logged properly"() {
+
+ def t = new RuntimeException("Just cranky.")
+
+ when:
+
+ ObjectCreator wrapper = new RecursiveServiceCreationCheckWrapper(sd, delegate, logger)
+
+ wrapper.createObject()
+
+ then:
+
+ RuntimeException e = thrown()
+
+ e.is(t)
+
+ 1 * delegate.createObject() >> { throw t }
+
+ 1 * logger.error("Construction of service Bar failed: ${t.message}", t)
+
+
+ when: "a subsequent call"
+
+ def actual = wrapper.createObject()
+
+ then: "the delegate is reinvoked (succesfully, this time)"
+
+ actual.is(service)
+
+ 1 * delegate.createObject() >> service
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/399b52c7/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperTest.java
deleted file mode 100644
index f4d8ba9..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2006, 2007, 2009 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;
-
-import org.apache.tapestry5.ioc.ObjectCreator;
-import org.apache.tapestry5.ioc.def.ServiceDef;
-import org.slf4j.Logger;
-import org.testng.annotations.Test;
-
-public class RecursiveServiceCreationCheckWrapperTest extends IOCInternalTestCase
-{
-
- private static final String SOURCE_DESCRIPTION = "{SOURCE DESCRIPTION}";
-
- @Test
- public void ensure_only_called_once() throws Exception
- {
- Logger logger = mockLogger();
- ObjectCreatorSource source = mockObjectCreatorSource();
- ObjectCreator delegate = mockObjectCreator();
- Object service = new Object();
-
- ServiceDef def = new ServiceDefImpl(Runnable.class, null, "Bar", null, "singleton", false, false, source);
-
- train_createObject(delegate, service);
-
- train_getDescription(source, SOURCE_DESCRIPTION);
-
- replay();
-
- ObjectCreator wrapper = new RecursiveServiceCreationCheckWrapper(def, delegate, logger);
-
- assertSame(wrapper.createObject(), service);
-
- try
- {
- wrapper.createObject();
- unreachable();
- }
- catch (IllegalStateException ex)
- {
- assertMessageContains(
- ex,
- "Construction of service 'Bar' has failed due to recursion: the service depends on itself in some way.",
- SOURCE_DESCRIPTION,
- "for references to another service that is itself dependent on service 'Bar'.");
- }
-
- verify();
- }
-
- @Test
- public void reporting_of_construction_failure() throws Exception
- {
- RuntimeException failure = new RuntimeException("Just cranky.");
- Logger logger = mockLogger();
- ObjectCreatorSource source = mockObjectCreatorSource();
- ObjectCreator delegate = mockObjectCreator();
- Object service = new Object();
-
- ServiceDef def = new ServiceDefImpl(Runnable.class, null, "Bar", null, "singleton", false, false, source);
-
- expect(delegate.createObject()).andThrow(failure);
-
- logger.error("Construction of service Bar failed: Just cranky.", failure);
-
- replay();
-
- ObjectCreator wrapper = new RecursiveServiceCreationCheckWrapper(def, delegate, logger);
-
- try
- {
- wrapper.createObject();
- unreachable();
- }
- catch (RuntimeException ex)
- {
- assertSame(ex, failure);
- }
-
- verify();
-
- // Now test that the locked flag is not set and that the object may still be created.
-
- train_createObject(delegate, service);
-
- replay();
-
- assertSame(service, wrapper.createObject());
-
- verify();
- }
-}