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:32 UTC

[34/44] git commit: Create an abstract base for specifications that use a default, shared Registry

Create an abstract base for specifications that use a default, shared Registry


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/01fb5e3b
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/01fb5e3b
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/01fb5e3b

Branch: refs/heads/master
Commit: 01fb5e3bb376ed055d6b6e3f93724e0a667ec45d
Parents: 2657563
Author: Howard M. Lewis Ship <hl...@gmail.com>
Authored: Thu Apr 19 17:40:48 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 16 11:49:41 2012 -0700

----------------------------------------------------------------------
 .../ioc/AbstractSharedRegistrySpecification.groovy |   47 +++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/01fb5e3b/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/AbstractSharedRegistrySpecification.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/AbstractSharedRegistrySpecification.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/AbstractSharedRegistrySpecification.groovy
new file mode 100644
index 0000000..2b8c425
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/AbstractSharedRegistrySpecification.groovy
@@ -0,0 +1,47 @@
+package org.apache.tapestry.ioc
+
+import org.apache.tapestry5.ioc.IOCUtilities
+import org.apache.tapestry5.ioc.Registry
+import spock.lang.Specification
+
+/** Uses a static, shared instance of the Registry.  All specifications that extend from this class will share
+ * a single instance of the Registry, that is created by whatever specification is created first. */
+abstract class AbstractSharedRegistrySpecification extends Specification {
+
+  static Registry registry;
+
+  /** Any unrecognized methods are evaluated against the shared Registry instance. */
+  def methodMissing(String name, args) {
+    registry."$name"(* args)
+  }
+
+  /** Creates the Registry if it does not already exist. */
+  def setupSpec() {
+    if (registry == null) {
+      registry = IOCUtilities.buildDefaultRegistry()
+    }
+
+    helpSetupSpec()
+  }
+
+  /** Does nothing; override in subclasses to do work that should occur inside setupSpec(). */
+  def helpSetupSpec() {
+
+  }
+
+  /** Invokes {@link Registry#cleanupThread()}. */
+  def cleanupSpec() {
+    registry.cleanupThread();
+
+    helpCleanupSpec()
+  }
+
+  /** Does nothing; override in subclasses to do work that should occur inside cleanupSpec(), after {@link Registry#cleanupThread()}. */
+  def helpCleanupSpec() {
+
+  }
+
+  // TODO: the Registry is never shutdown, since there's no notification
+  // that all tests are completing.
+
+}