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 19:28:19 UTC
[8/9] Refactor all the tapestry-ioc Spock specifications into the
ioc.specs package Convert some package-private classes and constructors to
public
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MasterObjectProviderImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MasterObjectProviderImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MasterObjectProviderImplSpec.groovy
deleted file mode 100644
index 73ba4c5..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MasterObjectProviderImplSpec.groovy
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.AnnotationProvider
-import org.apache.tapestry5.ioc.ObjectLocator
-import org.apache.tapestry5.ioc.ObjectProvider
-import org.apache.tapestry5.ioc.OperationTracker
-import org.apache.tapestry5.ioc.internal.QuietOperationTracker
-import org.apache.tapestry5.ioc.services.MasterObjectProvider
-import spock.lang.Shared
-import spock.lang.Specification
-
-class MasterObjectProviderImplSpec extends Specification {
-
- @Shared
- OperationTracker tracker = new QuietOperationTracker()
-
- def "found match via first provider"() {
- ObjectProvider prov1 = Mock()
- ObjectProvider prov2 = Mock()
- AnnotationProvider ap = Mock()
- ObjectLocator locator = Mock()
- Runnable expected = Mock()
-
- MasterObjectProvider mop = new MasterObjectProviderImpl([prov1, prov2], tracker)
-
- when:
-
- assert mop.provide(Runnable, ap, locator, true).is(expected)
-
- then:
-
- 1 * prov1.provide(Runnable, ap, locator) >> expected
- 0 * _
- }
-
- def "found match after first provider"() {
- ObjectProvider prov1 = Mock()
- ObjectProvider prov2 = Mock()
- AnnotationProvider ap = Mock()
- ObjectLocator locator = Mock()
- Runnable expected = Mock()
-
- MasterObjectProvider mop = new MasterObjectProviderImpl([prov1, prov2], tracker)
-
- when:
-
- assert mop.provide(Runnable, ap, locator, true).is(expected)
-
- then:
-
- 1 * prov1.provide(Runnable, ap, locator) >> null
-
- then:
-
- 1 * prov2.provide(Runnable, ap, locator) >> expected
- 0 * _
- }
-
- def "no match found on optional search returns null"() {
- ObjectProvider prov1 = Mock()
- ObjectProvider prov2 = Mock()
- AnnotationProvider ap = Mock()
- ObjectLocator locator = Mock()
-
- MasterObjectProvider mop = new MasterObjectProviderImpl([prov1, prov2], tracker)
-
- when:
-
- assert mop.provide(Runnable, ap, locator, false) == null
-
- then:
-
- 1 * prov1.provide(Runnable, ap, locator) >> null
-
- then:
-
- 1 * prov2.provide(Runnable, ap, locator) >> null
- 0 * _
- }
-
- def "no match for a required search delegates to the ObjectLocator.getService(Class)"() {
- ObjectProvider prov1 = Mock()
- ObjectProvider prov2 = Mock()
- AnnotationProvider ap = Mock()
- ObjectLocator locator = Mock()
- Runnable expected = Mock()
-
- MasterObjectProvider mop = new MasterObjectProviderImpl([prov1, prov2], tracker)
-
- when:
-
- assert mop.provide(Runnable, ap, locator, true).is(expected)
-
- then:
-
- 1 * prov1.provide(Runnable, ap, locator) >> null
-
- then:
-
- 1 * prov2.provide(Runnable, ap, locator) >> null
-
- then:
-
- 1 * locator.getService(Runnable) >> expected
-
- 0 * _
-
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MethodIteratorSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MethodIteratorSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MethodIteratorSpec.groovy
deleted file mode 100644
index 13142ac..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MethodIteratorSpec.groovy
+++ /dev/null
@@ -1,113 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import spock.lang.Specification
-import spock.lang.Unroll
-
-interface Play extends Runnable {
-
- void jump()
-}
-
-interface Runnable2 {
-
- void run()
-}
-
-interface Runnable3 extends Runnable, Runnable2 {
-
-}
-
-interface Openable {
-
- public void open();
-}
-
-interface OpenableWithError {
-
- public void open() throws IOException;
-}
-
-interface CombinedOpeneable extends Openable, OpenableWithError {
-}
-
-class MethodIteratorSpec extends Specification {
-
- def "iterate a simple (single-method) interface"() {
-
- MethodIterator mi = new MethodIterator(Runnable)
-
- expect:
-
- mi.hasNext()
-
- when: "iterate to first method"
-
- def actual = mi.next()
-
- then: "first method signature returned"
-
- actual == new MethodSignature(void, "run", null, null)
-
- !mi.hasNext()
-
- when: "iterating when no method signatures left"
-
- mi.next()
-
- then: "throws exception"
-
- thrown(NoSuchElementException)
- }
-
- def "method inherited from super interface are visible"() {
-
- MethodIterator mi = new MethodIterator(Play)
-
- expect:
-
- mi.hasNext()
-
- mi.next() == new MethodSignature(void, "jump", null, null)
-
- mi.hasNext()
-
- mi.next() == new MethodSignature(void, "run", null, null)
-
- !mi.hasNext()
- }
-
- @Unroll
- def "getToString() on #interfaceType.name should be #expected"() {
-
- expect:
-
- new MethodIterator(interfaceType).getToString() == expected
-
- where:
-
- interfaceType | expected
- Runnable | false
- Play | false
- ToString | true
- }
-
- def "method duplicated from a base interface into a sub interface are filtered out"() {
- MethodIterator mi = new MethodIterator(Runnable3)
-
- expect:
-
- mi.next() == new MethodSignature(void, "run", null, null)
- !mi.hasNext()
- }
-
- def "inherited methods are filtered out if less specific"() {
- MethodIterator mi = new MethodIterator(CombinedOpeneable)
-
- expect:
-
- mi.next() == new MethodSignature(void, "open", null, [IOException] as Class[])
-
- !mi.hasNext()
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MethodSignatureSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MethodSignatureSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MethodSignatureSpec.groovy
deleted file mode 100644
index a84788a..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/MethodSignatureSpec.groovy
+++ /dev/null
@@ -1,178 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import spock.lang.Specification
-import spock.lang.Unroll
-
-import java.lang.reflect.Method
-import java.sql.SQLException
-
-class MethodSignatureSpec extends Specification {
-
- def MethodSignature find(Class sourceClass, String methodName) {
- Method match = sourceClass.methods.find { it.name == methodName }
-
- if (match == null) {
- throw new IllegalStateException("Call $sourceClass.name has no method named '$methodName'.")
- }
-
- return new MethodSignature(match)
- }
-
- @Unroll
- def "#firstClass.name and #secondClass.name have identical MethodSignatures for method #methodName"() {
-
- when:
-
- def m1 = find firstClass, methodName
- def m2 = find secondClass, methodName
-
- then:
-
- m1.hashCode() == m2.hashCode()
- m1 == m2
-
- where:
-
- firstClass | secondClass | methodName
- Object | Boolean | "hashCode"
- String | StringBuilder | "charAt"
- ObjectInput | ObjectInputStream | "close"
- }
-
- def "a null parameter or exception list is equivalent to an empty one"() {
- def m1 = new MethodSignature(void, "foo", null, null)
- def m2 = new MethodSignature(void, "foo", [] as Class[], [] as Class[])
-
- expect:
-
- m1 == m2
- m2 == m1
-
- m1.hashCode() == m2.hashCode()
- }
-
- def "a mismatch of method name causes inequality"() {
- def m1 = new MethodSignature(void, "foo", null, null)
- def m2 = new MethodSignature(void, "bar", null, null)
-
- expect:
-
- m1 != m2
- }
-
- def "a mismatch of parameters causes inequality"() {
- def m1 = new MethodSignature(void, "foo", [String] as Class[], null)
- def m2 = new MethodSignature(void, "foo", [Boolean] as Class[], null)
-
- expect:
-
- m1 != m2
- }
-
- def "a MethodSignature never equals null"() {
-
- expect:
-
- new MethodSignature(void, "foo", null, null) != null
- }
-
- def "a MethodSignature may only equal another MethodSignature"() {
-
- expect:
-
- new MethodSignature(void, "foo", null, null) != "Any Old Thing"
- }
-
- @Unroll
- def "MethodSignature.toString() for #clazz.name #methodName is '#toString'"() {
-
- def sig = find(clazz, methodName)
-
- expect:
-
- sig.toString() == toString
-
- where:
-
- clazz | methodName | toString
- String | "getChars" | "void getChars(int, int, char[], int)"
- Class | "newInstance" | "java.lang.Object newInstance() throws java.lang.IllegalAccessException, java.lang.InstantiationException"
- }
-
- @Unroll
- def "MethodSignature.uniqueId for #clazz.name #methodName is '#uniqueId'"() {
- def sig = find(clazz, methodName)
-
- expect:
-
- sig.uniqueId == uniqueId
-
- where:
-
- clazz | methodName | uniqueId
- String | "getChars" | "getChars(int,int,char[],int)"
- Class | "newInstance" | "newInstance()"
- }
-
- def "different return types will prevent override"() {
-
- def m1 = new MethodSignature(void, "foo", null, null)
- def m2 = new MethodSignature(int, "foo", null, null)
-
- expect:
-
- !m1.isOverridingSignatureOf(m2)
- }
-
- def "different method names will prevent override"() {
- def m1 = new MethodSignature(int, "foo", null, null)
- def m2 = new MethodSignature(int, "bar", null, null)
-
- expect:
-
- !m1.isOverridingSignatureOf(m2)
- }
-
- def "different parameter types will prevent override"() {
- def m1 = new MethodSignature(int, "foo", null, null)
- def m2 = new MethodSignature(int, "foo", [String] as Class[], null)
-
- expect:
-
- !m1.isOverridingSignatureOf(m2)
- }
-
- def "a difference of exceptions thrown allows for override"() {
- def m1 = new MethodSignature(int, "foo", null, [Exception] as Class[])
- def m2 = new MethodSignature(int, "foo", null, [RuntimeException] as Class[])
-
- expect:
-
- // All of m2's exceptions are assignable to at least one of m1's exceptions
- m1.isOverridingSignatureOf(m2)
- !m2.isOverridingSignatureOf(m1)
- }
-
- def "signature with no exceptions will not override"() {
- def m1 = new MethodSignature(int, "foo", null, null)
- def m2 = new MethodSignature(int, "foo", null, [RuntimeException] as Class[])
-
- expect:
-
- !m1.isOverridingSignatureOf(m2)
- m2.isOverridingSignatureOf(m1)
- }
-
- def "complex matching of signature exceptions when determining override"() {
- def m1 = new MethodSignature(void, "close", null,
- [SQLException, NumberFormatException] as Class[])
- def m2 = new MethodSignature(void.class, "close", null,
- [SQLException, IOException] as Class[])
-
- expect:
-
- // NumberFormatException and IOException don't fit in either direction
- !m1.isOverridingSignatureOf(m2)
- !m2.isOverridingSignatureOf(m1)
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/NonParallelExecutorSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/NonParallelExecutorSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/NonParallelExecutorSpec.groovy
deleted file mode 100644
index 4d79462..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/NonParallelExecutorSpec.groovy
+++ /dev/null
@@ -1,58 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.Invokable
-import org.apache.tapestry5.ioc.Registry
-import org.apache.tapestry5.ioc.RegistryBuilder
-import org.apache.tapestry5.ioc.services.ParallelExecutor
-import spock.lang.AutoCleanup
-import spock.lang.Shared
-import spock.lang.Specification
-
-class NonParallelExecutorSpec extends Specification {
-
- @Shared
- @AutoCleanup("shutdown")
- private Registry registry
-
- @Shared
- private ParallelExecutor executor
-
- def setupSpec() {
- registry = new RegistryBuilder().add(NonParallelModule).build()
-
- executor = registry.getService ParallelExecutor
- }
-
- def "passing an Invokable will immediately invoke()"() {
-
- Invokable inv = Mock()
-
- when:
-
- def actual = executor.invoke(String, inv)
-
- then:
-
- actual == "value"
-
- 1 * inv.invoke() >> "value"
- }
-
- def "A returned Future object is a simple wrapper around the result"() {
- Invokable inv = Mock()
-
- when:
-
- def future = executor.invoke(inv)
-
- then:
-
- 1 * inv.invoke() >> "right now"
-
- !future.cancel(false)
- !future.cancelled
- future.done
- future.get() == "right now"
- future.get(0, null) == "right now"
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ParallelExecutorSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ParallelExecutorSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ParallelExecutorSpec.groovy
deleted file mode 100644
index 4819fda..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ParallelExecutorSpec.groovy
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.Invokable
-import org.apache.tapestry5.ioc.StringHolder
-import org.apache.tapestry5.ioc.StringHolderImpl
-import org.apache.tapestry5.ioc.services.ParallelExecutor
-import spock.lang.Shared
-
-class ParallelExecutorSpec extends AbstractSharedRegistrySpecification {
-
- @Shared ParallelExecutor executor
-
- def setupSpec() {
- executor = getService ParallelExecutor
- }
-
- def "thunks execute in parallel and results are cached"() {
-
- def thunks = []
-
- when:
-
- 100.times { i ->
-
- def value = "Value[$i]"
-
- def first = true
-
- def inv = new Invokable() {
-
- Object invoke() {
-
- if (!first) { throw new IllegalStateException("Result of Invokable should be cached.") }
-
- def holder = new StringHolderImpl()
-
- holder.value = value
-
- Thread.sleep 10
-
- first = false
-
- return holder
- }
- }
-
- thunks.add executor.invoke(StringHolder, inv)
- }
-
- then:
-
- // Not sure how to truly prove that the results are happening in parallel.
- // I think it's basically that by the time we work our way though the list, some values
- // will have been computed ahead.
-
- thunks.size().times { i ->
-
- assert thunks[i].value == "Value[$i]"
- }
-
- then: "a second pass to proove that the thunk caches the result"
-
- thunks.size().times { i ->
-
- assert thunks[i].value == "Value[$i]"
- }
- }
-
- def "toString() of a thunk indicates the interface type"() {
-
- Invokable inv = Mock()
-
- when:
-
- StringHolder thunk = executor.invoke StringHolder, inv
-
- then:
-
- thunk.toString() == "FutureThunk[org.apache.tapestry5.ioc.StringHolder]"
- }
-
- def "exception inside the Invokable is rethrown by the thunk"() {
-
- def inv = new Invokable() {
-
- Object invoke() { throw new RuntimeException("Future failure!")}
- }
-
- StringHolder thunk = executor.invoke StringHolder, inv
-
-
- when:
-
- thunk.getValue()
-
- then:
-
- RuntimeException e = thrown()
-
- e.message.contains "Future failure!"
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImplSpec.groovy
deleted file mode 100644
index 63acf36..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImplSpec.groovy
+++ /dev/null
@@ -1,182 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.Invokable
-import org.apache.tapestry5.ioc.services.ThreadCleanupListener
-import org.slf4j.Logger
-import spock.lang.Specification
-
-class PerthreadManagerImplSpec extends Specification {
-
- def "nothing is logged when cleaning up with no listeners"() {
- Logger logger = Mock()
-
- def manager = new PerthreadManagerImpl(logger)
-
- when:
-
- manager.cleanup()
-
- then:
-
- 0 * _
- }
-
- def "listeners will only be invoked a single time, then discarded"() {
- Logger logger = Mock()
- ThreadCleanupListener listener = Mock()
-
- def manager = new PerthreadManagerImpl(logger)
-
- when:
-
- manager.addThreadCleanupListener(listener)
- manager.cleanup()
-
- then:
-
- 1 * listener.threadDidCleanup()
- 0 * _
-
- when:
-
- manager.cleanup()
-
- then:
-
- 0 * _
- }
-
- def "exceptions during thread cleanup are logged and other listeners still invoked"() {
- RuntimeException t = new RuntimeException("Boom!")
- Logger logger = Mock()
- ThreadCleanupListener l1 = Mock()
- ThreadCleanupListener l2 = Mock()
-
- def manager = new PerthreadManagerImpl(logger)
-
- manager.addThreadCleanupListener(l1)
- manager.addThreadCleanupListener(l2)
-
- when:
-
- manager.cleanup()
-
- then:
-
- 1 * l1.threadDidCleanup() >> { throw t }
- 1 * logger.warn({ it.contains "Error invoking listener"}, t)
-
- then:
-
- 1 * l2.threadDidCleanup()
- 0 * _
- }
-
- def "PerThreadValue does not initially exist"() {
- Logger logger = Mock()
- def manager = new PerthreadManagerImpl(logger)
-
- when:
-
- def value = manager.createValue()
-
- then:
-
- !value.exists()
- value.get() == null
-
- when:
-
- value.set(this)
-
- then:
-
- value.exists()
- value.get() == this
- }
-
- def "PerThreadValue.get() with default returns the default value when the value does not exist"() {
- Logger logger = Mock()
- def manager = new PerthreadManagerImpl(logger)
- def defaultValue = new Object()
- def nonNull = new Object()
-
- when:
-
- def value = manager.createValue()
-
- then:
-
- value.get(defaultValue).is(defaultValue)
-
- when:
-
- value.set(null)
-
- then:
-
- value.exists()
- value.get(defaultValue) == null
-
- when:
-
- value.set(nonNull)
-
- then:
-
- value.get(defaultValue).is(nonNull)
- }
-
- def "PerthreadManager.run() performs an implicit cleanup"() {
- Logger logger = Mock()
- ThreadCleanupListener listener = Mock()
-
- def manager = new PerthreadManagerImpl(logger)
- manager.addThreadCleanupListener listener
- def value = manager.createValue()
- def didRun = false
-
- def runnable = {
- didRun = true
- value.set "bar"
- }
-
- when:
-
- manager.run runnable
-
- then:
-
- 1 * listener.threadDidCleanup()
-
- didRun
- !value.exists()
- }
-
- def "PerthreadManager.invoke() performs an implicit cleanup"() {
- Logger logger = Mock()
- ThreadCleanupListener listener = Mock()
-
- def manager = new PerthreadManagerImpl(logger)
- manager.addThreadCleanupListener listener
- def value = manager.createValue()
-
- def inv = {
- value.set "bar"
- return "baz"
- } as Invokable
-
- when:
-
- assert manager.invoke(inv) == "baz"
-
- then:
-
- 1 * listener.threadDidCleanup()
-
- !value.exists()
-
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImplSpec.groovy
deleted file mode 100644
index 1610a93..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImplSpec.groovy
+++ /dev/null
@@ -1,86 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.services.PipelineBuilder
-import org.slf4j.Logger
-import spock.lang.Shared
-
-class PipelineBuilderImplSpec extends AbstractSharedRegistrySpecification {
-
- @Shared
- PipelineBuilder builder
-
- def setupSpec() { builder = getService PipelineBuilder }
-
- Logger logger = Mock()
-
- def "standard pipeline with filters"() {
-
- // For some reason, this didn't work with closures, just with actual inner classes
-
- StandardFilter subtracter = new StandardFilter() {
-
- @Override
- int run(int i, StandardService service) {
- service.run(i) - 2
- }
- }
-
- StandardFilter multiplier = new StandardFilter() {
-
- @Override
- int run(int i, StandardService service) {
- 2 * service.run(i)
- }
- }
-
- StandardFilter adder = new StandardFilter() {
-
- @Override
- int run(int i, StandardService service) {
- service.run(i + 3)
- }
- }
-
- StandardService terminator = new StandardService() {
-
- @Override
- int run(int i) {
- i
- }
- }
-
- when:
-
- StandardService pipeline = builder.build logger, StandardService, StandardFilter, [subtracter, multiplier, adder], terminator
-
- then:
-
- pipeline.run(5) == 14
- pipeline.run(10) == 24
- }
-
- def "a pipeline without filters is simply the temrinator"() {
-
- StandardService terminator = Mock()
-
- when:
-
- StandardService pipeline = builder.build logger, StandardService, StandardFilter, [], terminator
-
- then:
-
- pipeline.is terminator
- }
-
- def "a pipeline with no filters and no terminator does nothing"() {
- when:
-
- StandardService pipeline = builder.build logger, StandardService, StandardFilter, []
-
- then:
-
- pipeline.run(99) == 0
-
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PropertyAccessImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PropertyAccessImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PropertyAccessImplSpec.groovy
deleted file mode 100644
index 795f988..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PropertyAccessImplSpec.groovy
+++ /dev/null
@@ -1,708 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.beaneditor.DataType
-import org.apache.tapestry5.beaneditor.Validate
-import org.apache.tapestry5.ioc.annotations.Scope
-import org.apache.tapestry5.ioc.internal.util.Pair
-import org.apache.tapestry5.ioc.internal.util.StringLongPair
-import org.apache.tapestry5.ioc.services.ClassPropertyAdapter
-import org.apache.tapestry5.ioc.services.PropertyAccess
-
-import java.awt.Image
-import java.lang.reflect.Method
-
-import spock.lang.*
-
-import java.beans.*
-
-class ExceptionBean {
-
- boolean getFailure() {
- throw new RuntimeException("getFailure");
- }
-
- void setFailure(boolean b) {
- throw new RuntimeException("setFailure");
- }
-
- @Override
- String toString() {
- return "PropertyAccessImplSpecBean";
- }
-}
-
-class UglyBean {
-}
-
-class UglyBeanBeanInfo implements BeanInfo {
-
- BeanInfo[] getAdditionalBeanInfo() {
- return new BeanInfo[0];
- }
-
- BeanDescriptor getBeanDescriptor() {
- return null;
- }
-
- int getDefaultEventIndex() {
- return 0;
- }
-
- int getDefaultPropertyIndex() {
- return 0;
- }
-
- EventSetDescriptor[] getEventSetDescriptors() {
- return new EventSetDescriptor[0];
- }
-
- Image getIcon(int iconKind) {
- return null;
- }
-
- MethodDescriptor[] getMethodDescriptors() {
- return new MethodDescriptor[0];
- }
-
- PropertyDescriptor[] getPropertyDescriptors() {
- throw new RuntimeException("This is the UglyBean.");
- }
-
-}
-
-class ScalaBean {
-
- private String value;
-
- String getValue() {
- return value;
- }
-
- void setValue(String value) {
- this.value = value;
- }
-
- String value() {
- return value;
- }
-
- void value_$eq(String value) {
- this.value = value;
- }
-}
-
-class ScalaClass {
-
- private String value;
-
- String value() {
- return value;
- }
-
- void value_$eq(String value) {
- this.value = value;
- }
-}
-
-interface BeanInterface {
-
- String getValue();
-
- void setValue(String v);
-
- String getOtherValue();
-
- void setOtherValue(String v);
-
- int getIntValue(); // read-only
-}
-
-abstract class AbstractBean implements BeanInterface {
- // abstract class implements method from interface
- private String other;
-
- String getOtherValue() {
- return other;
- }
-
- void setOtherValue(String v) {
- other = v;
- }
-}
-
-class ConcreteBean extends AbstractBean {
-
- private String value;
- private int intValue;
-
- ConcreteBean(int intValue) {
- this.intValue = intValue;
- }
-
- String getValue() {
- return value;
- }
-
- void setValue(String v) {
- value = v;
- }
-
- int getIntValue() {
- return intValue;
- }
-}
-
-abstract class GenericBean<T> {
-
- public T value;
-}
-
-class GenericStringBean extends GenericBean<String> {
-}
-
-class PropertyAccessImplSpec extends Specification {
-
- @Shared
- PropertyAccess access = new PropertyAccessImpl()
-
- @Shared
- Random random = new Random()
-
- def "simple read access to a standard bean"() {
- Bean b = new Bean()
- int value = random.nextInt()
-
- when:
-
- b.value = value
-
- then:
-
- access.get(b, "value") == value
- }
-
- def "property name access is case insensitive"() {
- Bean b = new Bean()
- int value = random.nextInt()
-
- when:
-
- b.value = value
-
- then:
-
- access.get(b, "VaLUe") == value
- }
-
- def "simple write access to a standard bean"() {
- Bean b = new Bean()
- int value = random.nextInt()
-
- when:
-
- access.set(b, "value", value)
-
- then:
-
- b.value == value
- }
-
- def "missing properties are an exception"() {
- Bean b = new Bean()
-
- when:
-
- access.get(b, "zaphod")
-
- then:
-
- IllegalArgumentException e = thrown()
-
- e.message == "Class ${b.class.name} does not contain a property named 'zaphod'."
- }
-
- def "it is not possible to update a read-only property"() {
- Bean b = new Bean()
-
- when:
-
- access.set(b, "class", null)
-
- then:
-
- UnsupportedOperationException e = thrown()
-
- e.message == "Class ${b.class.name} does not provide a mutator ('setter') method for property 'class'."
- }
-
- def "it is not possible to read a write-only property"() {
- Bean b = new Bean()
-
- when:
-
- access.get(b, "writeOnly")
-
- then:
-
- UnsupportedOperationException e = thrown()
-
- e.message == "Class ${b.class.name} does not provide an accessor ('getter') method for property 'writeOnly'."
- }
-
- def "when a getter method throws an exception, the exception is wrapped and rethrown"() {
-
- ExceptionBean b = new ExceptionBean()
-
- when:
-
- access.get(b, "failure")
-
- then:
-
- RuntimeException e = thrown()
-
- e.message == "Error reading property 'failure' of ${b}: getFailure"
- }
-
- def "when a setter method throws an exception, the exception is wrapped and rethrown"() {
- ExceptionBean b = new ExceptionBean()
-
- when:
-
- access.set(b, "failure", false)
-
- then:
-
- RuntimeException e = thrown()
-
- e.message == "Error updating property 'failure' of ${b.class.name}: setFailure"
- }
-
- @Ignore
- def "exception throw when introspecting the class is wrapped and rethrown"() {
-
- // Due to Groovy, the exception gets thrown here, not inside
- // the access.get() method, thus @Ingore (for now)
-
- UglyBean b = new UglyBean()
-
- when:
-
- access.get(b, "google")
-
- then:
-
- RuntimeException e = thrown()
-
- e.message == "java.lang.RuntimeException: This is the UglyBean."
- }
-
- def "clearCache() wipes internal cache"() {
- when:
-
- ClassPropertyAdapter cpa1 = access.getAdapter Bean
-
- then:
-
- cpa1.is(access.getAdapter(Bean))
-
-
- when:
-
- access.clearCache()
-
- then:
-
- !cpa1.is(access.getAdapter(Bean))
- }
-
- def "ClassPropertyAdapter has a useful toString()"() {
-
- when:
-
- def cpa = access.getAdapter Bean
-
- then:
-
- cpa.toString() == "<ClassPropertyAdaptor ${Bean.class.name}: PI, class, readOnly, value, writeOnly>"
- }
-
- @Unroll
- def "expected properties for #beanClass.name property '#propertyName' are read=#read, update=#update, castRequired=#castRequired"() {
-
- when:
-
- def pa = getPropertyAdapter beanClass, propertyName
-
- then:
-
- pa.read == read
- pa.update == update
- pa.castRequired == castRequired
- pa.writeMethod == writeMethod
- pa.readMethod == readMethod
-
- where:
-
- beanClass | propertyName | read | update | castRequired | writeMethodName | readMethodName
- Bean | "readOnly" | true | false | false | null | "getReadOnly"
- Bean | "writeOnly" | false | true | false | "setWriteOnly" | null
- Bean | "pi" | true | false | false | null | null
-
- writeMethod = findMethod beanClass, writeMethodName
- readMethod = findMethod beanClass, readMethodName
- }
-
- def "PropertyAdapter for unknown property name is null"() {
- when:
-
- ClassPropertyAdapter cpa = access.getAdapter(Bean)
-
- then:
-
- cpa.getPropertyAdapter("google") == null
- }
-
- @Unroll
- def "PropertyAdapter.type for #beanClass.name property '#propertyName' is #type.name"() {
-
- ClassPropertyAdapter cpa = access.getAdapter(beanClass)
-
- when:
-
- def adapter = cpa.getPropertyAdapter(propertyName)
-
- then:
-
- adapter.type.is(type)
-
- where:
-
- beanClass | propertyName | type
- Bean | "value" | int
- Bean | "readOnly" | String
- Bean | "writeOnly" | boolean
- }
-
- def "ClassPropertyAdapter gives access to property names (in sorted order)"() {
- ClassPropertyAdapter cpa = access.getAdapter(Bean)
-
- expect:
-
- cpa.propertyNames == ["PI", "class", "readOnly", "value", "writeOnly"]
- }
-
- def "public static fields are treated as properties"() {
- when:
-
- def adapter =getPropertyAdapter Bean, "pi"
-
- then:
-
- adapter.get(null).is(Bean.PI)
- }
-
- def "public final static fields may not be updated"() {
- def adapter =getPropertyAdapter Bean, "pi"
-
- when:
-
- adapter.set(null, 3.0d)
-
- then:
-
- RuntimeException e = thrown()
-
- e.message.contains "final"
- e.message.contains "PI"
- }
-
- def "super interface methods are inherited by sub-interface"() {
- when:
-
- ClassPropertyAdapter cpa = access.getAdapter SubInterface
-
- then:
-
- cpa.propertyNames == ["grandParentProperty", "parentProperty", "subProperty"]
- }
-
- def "indexed properties are ignored"() {
- when:
-
- ClassPropertyAdapter cpa = access.getAdapter BeanWithIndexedProperty
-
- then:
-
- cpa.propertyNames == ["class", "primitiveProperty"]
- }
-
- def "getAnnotation() when annotation is not present is null"() {
-
- when:
-
- def pa = getPropertyAdapter AnnotatedBean, "readWrite"
-
- then:
-
- pa.getAnnotation(Scope) == null
- }
-
- def "getAnnotation() with annotation on setter method"() {
-
- when:
-
- def pa = getPropertyAdapter AnnotatedBean, "annotationOnWrite"
-
- then:
-
- pa.getAnnotation(Scope).value() == "onwrite"
- }
-
- def "annotation on getter method overrides annotation on setter method"() {
- def pa =getPropertyAdapter AnnotatedBean, "annotationOnRead"
-
- when:
-
- Scope annotation = pa.getAnnotation(Scope)
-
- then:
-
- annotation.value() == "onread"
- }
-
- def "getAnnotation() works on read-only properties, skipping the missing setter method"() {
-
- when:
-
- def pa = getPropertyAdapter AnnotatedBean, "readOnly"
-
- then:
-
- pa.getAnnotation(Scope) == null
- }
-
- def "annotations directly on fields are located"() {
- when:
-
- def pa = access.getAdapter(Bean).getPropertyAdapter("value")
-
- then:
-
- pa.getAnnotation(DataType).value() == "fred"
- }
-
- @Issue("TAPESTY-2448")
- def "getAnnotation() will find annotations from an inherited field in a super-class"() {
- when:
-
- def pa = getPropertyAdapter BeanSubclass, "value"
-
- then:
-
- pa.getAnnotation(DataType).value() == "fred"
- }
-
- def "annotations on a getter or setter method override annotations on the field"() {
- when:
-
- def pa = getPropertyAdapter Bean, "value"
-
- then:
-
- pa.getAnnotation(Validate).value() == "getter-value-overrides"
- }
-
- def "PropertyAdapter.type understands (simple) generic signatures"() {
- def cpa1 = access.getAdapter(StringLongPair)
-
- when:
-
- def key = cpa1.getPropertyAdapter("key")
-
- then:
-
- key.type == String
- key.castRequired
- key.declaringClass == Pair
-
- when:
-
- def value = cpa1.getPropertyAdapter("value")
-
- then:
-
- value.type == Long
- value.castRequired
-
- when:
-
- def cpa2 = access.getAdapter(Pair)
- def pkey = cpa2.getPropertyAdapter("key")
-
- then:
-
- pkey.type == Object
- !pkey.castRequired
-
- when:
-
- def pvalue = cpa2.getPropertyAdapter("value")
-
- then:
-
- pvalue.type == Object
- !pvalue.castRequired
- }
-
- def "PropertyAdapter prefers JavaBeans property method names to Scala method names"() {
- when:
-
- def pa = getPropertyAdapter ScalaBean, "value"
-
- then:
-
- pa.readMethod.name == "getValue"
- pa.writeMethod.name == "setValue"
- }
-
- def "PropertyAdapter understands Scala accessor method naming"() {
- when:
-
- def pa = getPropertyAdapter ScalaClass, "value"
-
- then:
-
- pa.readMethod.name == "value"
- pa.writeMethod.name == 'value_$eq'
- }
-
- def "PropertyAccess exposes public fields as if they were properties"() {
- when:
-
- def pa = getPropertyAdapter PublicFieldBean, "value"
-
- then:
-
- pa.field
- pa.read
- pa.update
-
- when:
-
- PublicFieldBean bean = new PublicFieldBean()
-
- pa.set(bean, "fred")
-
- then:
-
- bean.value == "fred"
-
- when:
-
- bean.value = "barney"
-
- then:
-
- pa.get(bean) == "barney"
- }
-
- def "access to property is favored over public field when the names are the same"() {
- def bean = new ShadowedPublicFieldBean()
-
- when:
-
- def pa = getPropertyAdapter ShadowedPublicFieldBean, "value"
-
- then:
-
- !pa.field
-
- when:
-
- pa.set(bean, "fred")
-
- then:
-
- bean.@value == null
-
- when:
-
- bean.@value = "barney"
- bean.value = "wilma"
-
- then:
-
- pa.get(bean) == "wilma"
- }
-
- def "a property defined by an unimplemented inteface method of an abstract class is accessible"() {
- AbstractBean bean = new ConcreteBean(33)
- def ca = access.getAdapter(AbstractBean)
-
- when:
-
- def va = ca.getPropertyAdapter("value")
-
- then:
-
- !va.field
-
- when:
-
- va.set(bean, "hello")
-
- then:
-
- va.get(bean) == "hello"
- bean.value == "hello"
-
- when:
-
- def ova = ca.getPropertyAdapter("otherValue")
-
- then:
-
- !ova.field
-
- when:
-
- ova.set(bean, "other value")
-
- then:
-
- ova.get(bean) == "other value"
- bean.otherValue == "other value"
-
- when:
-
- def iva = ca.getPropertyAdapter("intvalue")
-
- then:
-
- iva.get(bean) == 33
- iva.read
- !iva.update
- !iva.field
- }
-
- def "generic field is recognized"() {
- when:
- def pa = getPropertyAdapter GenericStringBean, "value"
-
- then:
-
- pa.castRequired
- pa.type == String
- pa.declaringClass == GenericBean
- }
-
-
- def getPropertyAdapter(clazz, name) {
- access.getAdapter(clazz).getPropertyAdapter(name)
- }
-
- private Method findMethod(Class beanClass, String methodName) {
- return beanClass.methods.find { it.name == methodName }
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PropertyShadowBuilderImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PropertyShadowBuilderImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PropertyShadowBuilderImplSpec.groovy
deleted file mode 100644
index 5a7bfaa..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/PropertyShadowBuilderImplSpec.groovy
+++ /dev/null
@@ -1,122 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.services.PropertyShadowBuilder
-import spock.lang.Shared
-
-interface Foo {
-
- void foo();
-}
-
-class FooHolder {
-
- private Foo foo;
-
- private int count = 0;
-
- public Foo getFoo() {
- count++;
-
- return foo;
- }
-
- public int getCount() {
- return count;
- }
-
- public void setFoo(Foo foo) {
- this.foo = foo;
- }
-
- @Override
- public String toString() {
- return "[FooHolder]";
- }
-
- public void setWriteOnly(Foo foo) {
-
- }
-}
-
-class PropertyShadowBuilderImplSpec extends AbstractSharedRegistrySpecification {
-
- @Shared
- PropertyShadowBuilder builder
-
- Foo foo = Mock()
- FooHolder holder = new FooHolder();
-
- def setupSpec() {
- builder = getService PropertyShadowBuilder
- }
-
-
- def "basic delegation from proxy to property"() {
-
- Foo shadow = builder.build(holder, "foo", Foo)
-
- holder.foo = foo
-
-
- when:
-
- shadow.foo()
-
- then:
-
- foo.foo()
- holder.count == 1
-
- shadow.toString() == "<Shadow: property foo of [FooHolder]>"
-
- when:
-
- shadow.foo()
-
- then:
-
- foo.foo()
- holder.count == 2
- }
-
- def "verify exception when accessing the value when null"() {
-
- Foo shadow = builder.build(holder, "foo", Foo)
-
- when:
-
- shadow.foo()
-
- then:
-
- NullPointerException e = thrown()
-
- e.message == "Unable to delegate method invocation to property 'foo' of [FooHolder], because the property is null."
- }
-
- def "property type mismatch"() {
- when:
-
- builder.build(holder, "count", Map)
-
- then:
-
- RuntimeException e = thrown()
-
- e.message == "Property 'count' of class ${FooHolder.name} is of type int, which is not assignable to type java.util.Map."
- }
-
- def "attempting to build for a write-only property is an exception"() {
- when:
-
- builder.build(holder, "writeOnly", Foo)
-
- then:
-
- RuntimeException e = thrown()
-
- e.message == "Class ${FooHolder.name} does not provide an accessor ('getter') method for property 'writeOnly'."
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryStartupSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryStartupSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryStartupSpec.groovy
deleted file mode 100644
index bf171a1..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryStartupSpec.groovy
+++ /dev/null
@@ -1,95 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.RegistryBuilder
-import org.slf4j.Logger
-import spock.lang.Specification
-
-class RegistryStartupSpec extends Specification {
-
-
- def "ensure that RegistryStartup service runs each of its contributed callbacks"() {
- Runnable r1 = Mock()
- Runnable r2 = Mock()
- Logger logger = Mock()
- def configuration = [r1, r2]
-
- Runnable startup = new RegistryStartup(logger, configuration)
-
- when:
-
- startup.run()
-
- then:
-
- 1 * r1.run()
-
- then:
-
- 1 * r2.run()
-
- then:
-
- configuration.empty
- }
-
- def "callback failure is logged and execution continues"() {
- Runnable r1 = Mock()
- Runnable r2 = Mock()
- Logger logger = Mock()
- RuntimeException ex = new RuntimeException("Crunch!")
-
- Runnable startup = new RegistryStartup(logger, [r1, r2])
-
- when:
-
- startup.run()
-
- then:
-
- 1 * r1.run() >> { throw ex }
- 1 * logger.error("An exception occurred during startup: Crunch!", ex)
- 1 * r2.run()
- }
-
- def "run may only be invoked once"() {
- Logger logger = Mock()
- Runnable startup = new RegistryStartup(logger, [])
-
- startup.run()
-
- when:
-
- startup.run()
-
- then:
-
- IllegalStateException e= thrown()
-
- e.message.contains "Method org.apache.tapestry5.ioc.internal.services.RegistryStartup.run"
- e.message.contains "may no longer be invoked."
- }
-
- def "integration test"() {
- when:
-
- def registry = new RegistryBuilder().add(StartupModule).build()
-
- then:
-
- ! StartupModule.startupInvoked
-
- when:
-
- registry.performRegistryStartup()
-
- then:
-
- StartupModule.startupInvoked
-
- cleanup:
-
- registry.shutdown()
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/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
deleted file mode 100644
index 09b3f82..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/RegistryshutdownHubImplSpec.groovy
+++ /dev/null
@@ -1,105 +0,0 @@
-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/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ResourceSymbolProviderSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ResourceSymbolProviderSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ResourceSymbolProviderSpec.groovy
deleted file mode 100644
index 481dc68..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ResourceSymbolProviderSpec.groovy
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.Resource
-import spock.lang.Specification
-
-class ResourceSymbolProviderSpec extends Specification {
-
- static final CONTENT = 'homer=simpson\r\nmonty=burns'
-
- def "access to contents of stream"() {
- Resource resource = Mock()
-
- when:
-
- ResourceSymbolProvider provider = new ResourceSymbolProvider(resource)
-
- then:
-
- 1 * resource.openStream() >> { new ByteArrayInputStream(CONTENT.bytes) }
-
- expect:
-
- provider.valueForSymbol("homer") == "simpson"
- provider.valueForSymbol("monty") == "burns"
-
- provider.valueForSymbol("HOMER") == "simpson"
-
- provider.valueForSymbol("marge") == null
-
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplSpec.groovy
deleted file mode 100644
index 71178e9..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplSpec.groovy
+++ /dev/null
@@ -1,70 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.services.StrategyBuilder
-import spock.lang.Shared
-
-
-interface KindOf
-{
- String kindOf(Object value);
-}
-
-class KindOfImpl implements KindOf {
-
- private final String value;
-
- KindOfImpl(String value) { this.value = value; }
-
- @Override
- String kindOf(Object value) {
- return this.value;
- }
-
-}
-
-class StrategyBuilderImplSpec extends AbstractSharedRegistrySpecification {
-
- @Shared
- KindOf service
-
-
- def setup() {
-
- StrategyBuilder builder = getService StrategyBuilder
-
- service = builder.build KindOf, [
- (Map): new KindOfImpl("MAP"),
- (List): new KindOfImpl("LIST")
- ]
- }
-
- def "generated class implements a useful toString()"() {
-
- expect:
-
- service.toString() == "<Strategy for org.apache.tapestry5.ioc.internal.services.KindOf>"
- }
-
- def "ensure implementation inputs map to interface definitions"() {
-
- expect:
-
- service.kindOf(Collections.EMPTY_MAP) == "MAP"
- service.kindOf(Collections.EMPTY_LIST) == "LIST"
- }
-
- def "mapping null with no void mapping is a failure"() {
-
- when:
-
- service.kindOf null
-
- then:
-
- RuntimeException e = thrown()
-
- e.message == "No adapter from type void to type org.apache.tapestry5.ioc.internal.services.KindOf is available."
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ToString.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ToString.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ToString.groovy
deleted file mode 100644
index f1b8854..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ToString.groovy
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services
-
-/** An interface that includes toString() */
-interface ToString {
-
- String toString();
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/cron/CronExpressionSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/cron/CronExpressionSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/cron/CronExpressionSpec.groovy
deleted file mode 100644
index bafc09c..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/cron/CronExpressionSpec.groovy
+++ /dev/null
@@ -1,103 +0,0 @@
-package org.apache.tapestry5.ioc.internal.services.cron
-
-import spock.lang.Ignore
-import spock.lang.Specification
-import spock.lang.Unroll
-
-import java.text.ParseException
-
-@Unroll
-class CronExpressionSpec extends Specification {
-
- // This allows the any of the constants defined on Calendar to be used
- // without qualification.
- def propertyMissing(String name) { Calendar[name] }
-
- def "isSatisfiedBy(#year, #month, #day, #hour, #minute, #second ) should be #satisfied for expression '#expr'"() {
-
- def cal = Calendar.getInstance();
-
- def exp = new CronExpression(expr)
-
- cal.set year, month, day, hour, minute, second
-
- expect:
-
- exp.isSatisfiedBy(cal.time) == satisfied
-
- where:
- expr | year | month | day | hour | minute | second | satisfied
- "0 15 10 * * ? 2005" | 2005 | JUNE | 1 | 10 | 15 | 0 | true
- "0 15 10 * * ? 2005" | 2006 | JUNE | 1 | 10 | 15 | 0 | false
- "0 15 10 * * ? 2005" | 2005 | JUNE | 1 | 10 | 16 | 0 | false
- "0 15 10 * * ? 2005" | 2005 | JUNE | 1 | 10 | 14 | 0 | false
- "0 15 10 L-2 * ? 2010" | 2010 | OCTOBER | 29 | 10 | 15 | 0 | true
- "0 15 10 L-2 * ? 2010" | 2010 | OCTOBER | 28 | 10 | 15 | 0 | false
- "0 15 10 L-5W * ? 2010" | 2010 | OCTOBER | 26 | 10 | 15 | 0 | true
- "0 15 10 L-1 * ? 2010" | 2010 | OCTOBER | 30 | 10 | 15 | 0 | true
- "0 15 10 L-1W * ? 2010" | 2010 | OCTOBER | 29 | 10 | 15 | 0 | true
- }
-
- def cloneViaSerialize(obj) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream()
-
- baos.withObjectOutputStream { it.writeObject(obj) }
-
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())
- ObjectInputStream ois = new ObjectInputStream(bais)
-
- ois.readObject()
- }
-
- // This test is in the original TestNG test but failed there (making me think that the test case was probably
- // not being run). It's clear that CronExpressions do not deserialize correctly by looking at the source!
- @Ignore
- def "check that CronExpressions serialize and deserialize"() {
-
- CronExpression original = new CronExpression("19 15 10 4 Apr ? ")
-
- when:
-
- CronExpression cloned = cloneViaSerialize original
-
- then:
-
- cloned.cronExpression == original.cronExpression
- cloned.getNextValidTimeAfter(new Date()) != null
- }
-
- def "Parse failure: parse of '#expr' should fail with '#err'"() {
-
- when:
- new CronExpression(expr)
-
- then:
- def e = thrown(ParseException)
-
- assert e.message.startsWith(err)
-
- where:
- expr | err
- "* * * * Foo ? " | "Invalid Month value:"
- "* * * * Jan-Foo ? " | "Invalid Month value:"
- "0 0 * * * *" | "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented."
- "0 0 * 4 * *" | "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented."
- "0 0 * * * 4" | "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented."
- "0 43 9 1,5,29,L * ?" | "Support for specifying 'L' and 'LW' with other days of the month is not implemented"
- "0 43 9 ? * SAT,SUN,L" | "Support for specifying 'L' with other days of the week is not implemented"
- "0 43 9 ? * 6,7,L" | "Support for specifying 'L' with other days of the week is not implemented"
- "0/5 * * 32W 1 ?" | "The 'W' option does not make sense with values larger than"
- }
-
- def "Expression '#expr' is valid"() {
- when:
- new CronExpression(expr)
-
- then:
- noExceptionThrown()
-
- where:
- expr << ["0 43 9 ? * 5L"]
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/CronScheduleSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/CronScheduleSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/CronScheduleSpec.groovy
deleted file mode 100644
index 927e0c7..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/CronScheduleSpec.groovy
+++ /dev/null
@@ -1,27 +0,0 @@
-package org.apache.tapestry5.ioc.services
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.services.cron.CronSchedule
-import org.apache.tapestry5.ioc.services.cron.PeriodicExecutor
-
-import java.util.concurrent.CountDownLatch
-import java.util.concurrent.TimeUnit
-
-class CronScheduleSpec extends AbstractSharedRegistrySpecification {
-
- def "add a job and ensure that it executes"() {
- def latch = new CountDownLatch(5)
-
- def executor = getService PeriodicExecutor
-
- executor.addJob(new CronSchedule("0/1 * * * * ?"), "Test", { latch.countDown() })
-
- when:
-
- latch.await(30, TimeUnit.SECONDS)
-
- then:
-
- latch.count == 0
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/GeneralIntegrationSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/GeneralIntegrationSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/GeneralIntegrationSpec.groovy
deleted file mode 100644
index d9c217c..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/GeneralIntegrationSpec.groovy
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.apache.tapestry5.ioc.services
-
-import org.apache.tapestry5.ioc.AbstractSharedRegistrySpecification
-import org.apache.tapestry5.ioc.internal.services.Bean
-
-
-class GeneralIntegrationSpec extends AbstractSharedRegistrySpecification {
-
- def "PropertyAccess service is available"() {
-
- PropertyAccess pa = getService "PropertyAccess", PropertyAccess
-
- Bean b = new Bean()
-
- when:
-
- pa.set(b, "value", 99)
-
- then:
-
- b.value == 99
- pa.get(b, "value") == 99
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/OperationAdvisorSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/OperationAdvisorSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/OperationAdvisorSpec.groovy
deleted file mode 100644
index 6aca825..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/OperationAdvisorSpec.groovy
+++ /dev/null
@@ -1,83 +0,0 @@
-package org.apache.tapestry5.ioc.services
-
-import org.apache.tapestry5.ioc.OperationTracker
-import org.apache.tapestry5.ioc.internal.DefaultModuleDefImpl
-import org.apache.tapestry5.ioc.internal.LoggerSourceImpl
-import org.apache.tapestry5.ioc.internal.RegistryImpl
-import org.apache.tapestry5.ioc.internal.services.PlasticProxyFactoryImpl
-import spock.lang.AutoCleanup
-import spock.lang.Shared
-import spock.lang.Specification
-
-class OperationAdvisorSpec extends Specification {
-
- @Shared @AutoCleanup("shutdown")
- def registry
-
- @Shared
- def operations = []
-
- def setupSpec() {
-
- def classLoader = Thread.currentThread().contextClassLoader
- def loggerSource = new LoggerSourceImpl()
-
- def logger = loggerSource.getLogger(OperationAdvisorSpec)
- def proxyFactoryLogger = loggerSource.getLogger(PlasticProxyFactory)
-
- def plasticProxyFactory = new PlasticProxyFactoryImpl(classLoader, proxyFactoryLogger)
-
- def simpleOperationTracker = [
-
- run: { description, operation ->
- operations << description
- operation.run()
- },
-
- invoke: {description, operation ->
- operations << description
- operation.invoke()
- }
- ] as OperationTracker
-
- registry = new RegistryImpl([
- new DefaultModuleDefImpl(TapestryIOCModule, logger, plasticProxyFactory),
- new DefaultModuleDefImpl(OperationTrackedModule, logger, plasticProxyFactory)],
- plasticProxyFactory,
- loggerSource,
- simpleOperationTracker)
- }
-
- def "simple operation tracking"() {
- def service = registry.getService OperationTrackedService
-
- service.nonOperation()
-
- when:
-
- operations.clear()
-
- service.first()
-
- then:
-
- operations == ["First operation"]
- }
-
- def "complex operation tracking"() {
- def service = registry.getService OperationTrackedService
-
- service.nonOperation()
-
- operations.clear()
-
- when:
-
- service.second "foo"
- service.second "bar"
-
- then:
-
- operations == ["Second operation: foo", "Second operation: bar"]
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/PeriodicExecutorSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/PeriodicExecutorSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/PeriodicExecutorSpec.groovy
deleted file mode 100644
index a9ec916..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/PeriodicExecutorSpec.groovy
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.apache.tapestry5.ioc.services
-
-import org.apache.tapestry5.ioc.AbstractRegistrySpecification
-import org.apache.tapestry5.ioc.services.cron.IntervalSchedule
-import org.apache.tapestry5.ioc.services.cron.PeriodicExecutor
-
-import java.util.concurrent.CountDownLatch
-import java.util.concurrent.TimeUnit
-
-class PeriodicExecutorSpec extends AbstractRegistrySpecification {
-
- def "execution intervals"() {
-
- buildRegistry()
-
- def countDownLatch = new CountDownLatch(5);
-
- def schedule = new IntervalSchedule(10)
-
- def job = getService(PeriodicExecutor).addJob(schedule, "count incrementer", { countDownLatch.countDown(); })
-
- countDownLatch.await 30, TimeUnit.SECONDS
-
- cleanup:
-
- job && job.cancel()
-
-
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/SystemEnvSymbolProviderSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/SystemEnvSymbolProviderSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/SystemEnvSymbolProviderSpec.groovy
deleted file mode 100644
index 9b24ec1..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/services/SystemEnvSymbolProviderSpec.groovy
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.apache.tapestry5.ioc.services
-
-import org.apache.tapestry5.ioc.internal.services.SystemEnvSymbolProvider
-import spock.lang.Specification
-
-class SystemEnvSymbolProviderSpec extends Specification {
-
- SymbolProvider provider = new SystemEnvSymbolProvider()
-
- def "key exists"() {
- expect:
- provider.valueForSymbol("env.home") == System.getenv("HOME")
- }
-
- def "key missing"() {
- expect: provider.valueForSymbol("env.does-not-exist") == null
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/CaseInsensitiveMapSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/CaseInsensitiveMapSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/CaseInsensitiveMapSpec.groovy
deleted file mode 100644
index b413af2..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/CaseInsensitiveMapSpec.groovy
+++ /dev/null
@@ -1,303 +0,0 @@
-package org.apache.tapestry5.ioc.util
-
-import spock.lang.Specification
-
-
-class CaseInsensitiveMapSpec extends Specification {
-
- CaseInsensitiveMap map = new CaseInsensitiveMap([fred: "flintstone", barney: "rubble", wilma: "flinstone", betty: "rubble"])
-
- def "get() is case insensitive"() {
- def map = new CaseInsensitiveMap()
-
- def value = "flintstone"
-
- when:
-
- map.put("fred", value)
-
- then:
-
- map.get("fred").is(value)
- map.get("Fred").is(value)
- }
-
- def "containsKey() is case insensitive"() {
-
- expect:
-
- map.containsKey("fred")
- map.containsKey("Fred")
- map.containsKey("barney")
- map.containsKey("wilma")
- !map.containsKey("dino")
- }
-
- def "remove() is case insensitive"() {
- expect:
-
- map.containsKey("fred")
- !map.isEmpty()
-
- when:
-
- map.remove("FrED")
-
- then:
-
- map.keySet() == ["barney", "wilma", "betty"] as Set
- }
-
- def "copying Map constructor"() {
- def standard = [fred: "flintstone", barney: "rubble", wilma: "flintstone"]
-
- when:
-
- def original = new CaseInsensitiveMap(standard)
-
- then:
-
- original == standard
-
- when:
-
- def copy = new CaseInsensitiveMap(original)
-
- then:
-
- copy == original
- }
-
- def "comparison of two CaseInsensitiveMaps ignores case"() {
- def lower = new CaseInsensitiveMap([fred: "flintstone", barney: "rubble"])
- def upper = new CaseInsensitiveMap([Fred: "flintstone", Barney: "rubble"])
-
- expect:
-
- upper == lower
- }
-
- def "put with different case replaces the old key"() {
-
- expect:
-
- map.keySet() == ["fred", "barney", "betty", "wilma"] as Set
-
-
- when:
-
- map.put("FRED", "flintstone")
-
- then:
-
- map.keySet() == ["FRED", "barney", "betty", "wilma"] as Set
- }
-
- def "get with missing key is null"() {
- expect:
-
- map.notFound == null
- }
-
- def "get with non-string key is null"() {
- expect:
-
- map.get(this) == null
- }
-
- def "expansion of the internal entry array"() {
-
- def count = 2000
-
- def map = new CaseInsensitiveMap()
-
- count.times { it ->
- assert map.put("key_$it" as String, it) == null
- }
-
- when:
-
- count.times { it ->
- assert map.get("key_$it" as String) == it
- }
-
- then:
-
- map.size() == count
- map.entrySet().size() == count
-
- when:
-
- map.clear()
-
- then:
-
- map.size() == 0
-
- }
-
- def "change value via entrySet()"() {
- def map = new CaseInsensitiveMap()
-
- map.put("fred", "flintstone")
-
- when:
-
- map.entrySet().each { entry -> entry.value = "murray" }
-
- then:
-
- map.get("fred") == "murray"
- }
-
- def "entrySet iterator fails fast after remove"() {
-
- def i = map.entrySet().iterator()
-
- i.next()
- map.remove("betty")
-
- when:
-
- i.next()
-
- then:
-
- thrown(ConcurrentModificationException)
- }
-
- def "entrySet iterator fails fast after put"() {
-
- def i = map.entrySet().iterator()
-
- i.next()
- map.put("zaphod", "breeblebrox")
-
- when:
-
- i.next()
-
- then:
-
- thrown(ConcurrentModificationException)
- }
-
- def "iterator may remove without concurrent exception"() {
-
- def i = map.entrySet().iterator()
-
- while (i.hasNext()) {
- if (i.next().key == "wilma") { i.remove() }
- }
-
- expect:
-
- map.keySet() == ["barney", "betty", "fred"] as Set
- }
-
- def "contains via entrySet"() {
-
- def set = map.entrySet()
-
- expect:
-
- set.contains(newMapEntry("fred", "flintstone"))
- set.contains(newMapEntry("Fred", "flintstone"))
-
- !set.contains(newMapEntry("Zaphod", "Breeblebox"))
- !set.contains(newMapEntry("fred", "murray"))
- }
-
- def "remove via entrySet"() {
-
- def set = map.entrySet()
-
- when:
-
- assert set.remove(newMapEntry("Zaphod", "Breeblrox")) == false
- assert set.remove(newMapEntry("fred", "murray")) == false
-
- assert set.remove(newMapEntry("fred", "flintstone")) == true
-
- then:
-
- map.keySet() == ["barney", "wilma", "betty"] as Set
- }
-
- def newMapEntry(key, value) {
- return new Map.Entry() {
-
- @Override
- Object getKey() {
- return key
- }
-
- @Override
- Object getValue() {
- return value;
- }
-
- @Override
- Object setValue(Object newValue) {
- value = newValue
- }
- }
- }
-
- def "null is a valid key"() {
- when:
-
- map.put(null, "NULL")
-
- then:
-
- map.get(null) == "NULL"
- }
-
- def "clearing the entrySet clears the map"() {
- expect:
-
- !map.isEmpty()
- !map.entrySet().isEmpty()
-
- when:
-
- map.entrySet().clear()
-
- then:
-
- map.isEmpty()
- }
-
- def "next() after last entry in entrySet is a failure"() {
- Iterator i = map.entrySet().iterator()
-
- while (i.hasNext()) { i.next() }
-
- when:
-
- i.next()
-
- then:
-
- thrown(NoSuchElementException)
- }
-
- def "serialize/deserialize copies all data"() {
-
- def baos = new ByteArrayOutputStream()
- def oos = new ObjectOutputStream(baos)
-
- oos.writeObject(map)
- oos.close()
-
- def bais = new ByteArrayInputStream(baos.toByteArray())
- ObjectInputStream ois = new ObjectInputStream(bais)
-
- def copy = ois.readObject()
-
- expect:
-
- copy == map
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/ConcurrentBarrierSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/ConcurrentBarrierSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/ConcurrentBarrierSpec.groovy
deleted file mode 100644
index fee1aa7..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/ConcurrentBarrierSpec.groovy
+++ /dev/null
@@ -1,146 +0,0 @@
-package org.apache.tapestry5.ioc.util
-
-import org.apache.tapestry5.ioc.internal.util.ConcurrentTarget
-import org.apache.tapestry5.ioc.internal.util.ConcurrentTargetWrapper
-import spock.lang.Specification
-
-class ConcurrentBarrierSpec extends Specification {
-
- def target = new ConcurrentTarget()
-
- static final int THREAD_COUNT = 1000
-
- static final int THREAD_BLOCK_SIZE = 50
-
- def run(op) {
- def threads = []
- def running = []
-
- assert target.counter == 0
-
- THREAD_COUNT.times {
- def t = new Thread(op)
-
- threads << t
-
- if (threads.size() >= THREAD_BLOCK_SIZE) {
- threads.each { it.start() }
- running.addAll threads
- threads.clear()
- }
- }
-
- running.each { it.join() }
- }
-
- def "acquire write lock"() {
-
- when:
-
- run { target.incrementCounter() }
-
- then:
-
- target.counter == THREAD_COUNT
- }
-
- def "acquire read lock while holding write lock"() {
-
- when:
-
- run { target.incrementCounterHard() }
-
- then:
-
- target.counter == THREAD_COUNT
- }
-
- def "upgrade read lock to write lock"() {
- when:
-
- run { target.incrementIfNonNegative() }
-
- then:
-
- target.counter == THREAD_COUNT
- }
-
- def "indirection between method with read lock and method that acquires write lock"() {
-
- when:
-
- run { target.incrementViaRunnable() }
-
- then:
-
- target.counter == THREAD_COUNT
- }
-
- def "barriers are independent when multiple are involved"() {
-
- when:
-
- run(new ConcurrentTargetWrapper(target))
-
- then:
-
- target.counter == THREAD_COUNT
- }
-
- def "use tryWithWrite() to get write lock if it is available"() {
-
- when: run {
- def good = false
- while (!good) { good = target.tryIncrementCounter() }
- }
-
- then:
-
- target.counter == THREAD_COUNT
- }
-
- def "acquire read lock when inside a tryWithWrite block"() {
-
- when:
-
- run {
- def good = false
- while (!good) { good = target.tryIncrementCounterHard() }
- }
-
- then:
-
- target.counter == THREAD_COUNT
- }
-
- def "read lock upgrades via tryWriteLock()"() {
-
- when:
-
- run {
- def good = false
- while (!good) { good = target.tryIncrementIfNonNegative() }
- }
-
- then:
-
- target.counter == THREAD_COUNT
- }
-
- def "write lock timeout inside read lock"() {
- when:
-
- target.withRead {
- try {
- run {
- assert target.tryIncrementIfNonNegative() == false
- }
- }
- catch (InterruptedException e) { }
- }
-
- then:
-
- target.counter == 0
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/DummyLockSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/DummyLockSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/DummyLockSpec.groovy
deleted file mode 100644
index 465871c..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/DummyLockSpec.groovy
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.apache.tapestry5.ioc.util
-
-import org.apache.tapestry5.ioc.internal.util.DummyLock
-import spock.lang.Specification
-
-import java.util.concurrent.locks.Lock
-
-class DummyLockSpec extends Specification {
-
- def "all methods are no-ops"() {
- Lock lock = new DummyLock()
-
- when:
-
- lock.lock()
- lock.unlock()
- lock.lockInterruptibly()
-
- then:
-
- noExceptionThrown()
-
- expect:
- lock.newCondition() == null
- lock.tryLock()
- lock.tryLock(0, null)
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/GenericUtilsSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/GenericUtilsSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/GenericUtilsSpec.groovy
deleted file mode 100644
index 1f279c8..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/GenericUtilsSpec.groovy
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.apache.tapestry5.ioc.util
-
-import org.apache.tapestry5.ioc.internal.util.GenericsUtils
-import org.apache.tapestry5.ioc.internal.util.NonGenericBean
-import org.apache.tapestry5.ioc.internal.util.StringBean
-import org.apache.tapestry5.ioc.internal.util.StringLongPair
-import spock.lang.Specification
-import spock.lang.Unroll
-
-class GenericUtilsSpec extends Specification {
-
- def find(clazz, name) {
- def method = clazz.methods.find { it.name.equalsIgnoreCase(name) }
-
- if (method == null) {
- throw new IllegalArgumentException("Unable to find method '$name' of ${clazz.name}.")
- }
-
- return method
- }
-
- @Unroll
- def "generic return type for #method is #expected"() {
-
- expect:
-
- GenericsUtils.extractGenericReturnType(clazz, method).is(expected)
-
- where:
-
- clazz | name | expected
- NonGenericBean | "getvalue" | String
- StringBean | "getvalue" | String
- StringLongPair | "getkey" | String
- StringLongPair | "getvalue" | Long
-
- method = find(clazz, name)
- }
-
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1bef869/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/InheritanceSearchSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/InheritanceSearchSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/InheritanceSearchSpec.groovy
deleted file mode 100644
index cecc377..0000000
--- a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/InheritanceSearchSpec.groovy
+++ /dev/null
@@ -1,68 +0,0 @@
-package org.apache.tapestry5.ioc.util
-
-import org.apache.tapestry5.plastic.PlasticUtils
-import spock.lang.Specification
-import spock.lang.Unroll
-import org.apache.tapestry5.ioc.internal.util.*
-
-class InheritanceSearchSpec extends Specification {
-
- def "remove() is always a failure"() {
- when:
-
- new InheritanceSearch(Object).remove()
-
- then:
-
- thrown(UnsupportedOperationException)
- }
-
- def "exception thrown when invoking next() after Object has been reached"() {
- def s = new InheritanceSearch(Object)
-
- expect:
-
- s.next() == Object
- !s.hasNext()
-
- when:
-
- s.next()
-
- then:
-
- thrown(IllegalStateException)
- }
-
- @Unroll
- def "inheritance of #className is #expectedNames"() {
- def search = new InheritanceSearch(clazz)
- def result = []
- while (search.hasNext()) {
- result << search.next()
- }
-
- expect:
-
- result == expected
-
- where:
-
- clazz | expected
- Object | [Object]
- String | [String, Serializable, Comparable, CharSequence, Object]
- Comparable | [Comparable, Object]
- FooBar | [FooBar, Foo, Bar, Object]
- FooBarImpl | [FooBarImpl, FooImpl, BarImpl, Bar, FooBar, Foo, Object]
- long | [long, Long, Number, Comparable, Serializable, Object]
- void | [void, Object]
- long[] | [long[], Cloneable, Serializable, Object]
- int[][] | [int[][], Cloneable, Serializable, Object]
- String[] | [String[], Object[], Cloneable, Serializable, Object]
- String[][] | [String[][], Object[], Cloneable, Serializable, Object]
-
- className = PlasticUtils.toTypeName(clazz)
- expectedNames = expected.collect { PlasticUtils.toTypeName(it) }.join(", ")
-
- }
-}
\ No newline at end of file