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/d31c08cc Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/d31c08cc Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/d31c08cc Branch: refs/heads/master Commit: d31c08cc95332e69cb3194f4d76ac47f5ffa92ef Parents: d6e5f41 Author: Howard M. Lewis Ship <[email protected]> Authored: Fri Jun 1 08:04:15 2012 -0700 Committer: Howard M. Lewis Ship <[email protected]> Committed: Fri Jun 1 08:04:15 2012 -0700 ---------------------------------------------------------------------- .../services/StrategyBuilderImplSpec.groovy | 70 +++++++++++ .../tapestry5/ioc/internal/services/KindOf.java | 23 ---- .../internal/services/StrategyBuilderImplTest.java | 93 --------------- 3 files changed, 70 insertions(+), 116 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d31c08cc/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 new file mode 100644 index 0000000..71178e9 --- /dev/null +++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplSpec.groovy @@ -0,0 +1,70 @@ +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/d31c08cc/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/KindOf.java ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/KindOf.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/KindOf.java deleted file mode 100644 index 6261f21..0000000 --- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/KindOf.java +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2006 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; - -/** - * Converts an object to a string describing the kind of the object. - */ -public interface KindOf -{ - String kindOf(Object value); -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d31c08cc/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplTest.java ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplTest.java deleted file mode 100644 index cca2b7b..0000000 --- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplTest.java +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2006, 2008, 2012 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.internal.IOCInternalTestCase; -import org.apache.tapestry5.ioc.internal.util.CollectionFactory; -import org.apache.tapestry5.ioc.services.StrategyBuilder; -import org.apache.tapestry5.ioc.util.StrategyRegistry; -import org.testng.annotations.Test; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -public class StrategyBuilderImplTest extends IOCInternalTestCase -{ - private static class KindOfImpl implements KindOf - { - private final String value; - - public KindOfImpl(final String value) - { - this.value = value; - } - - public String kindOf(Object value) - { - return this.value; - } - } - - @Test - public void standard() - { - StrategyRegistry<KindOf> registry = buildStrategyRegistry(); - - StrategyBuilder builder = getService(StrategyBuilder.class); - - KindOf service = builder.build(registry); - - assertEquals(service.kindOf(Collections.EMPTY_MAP), "MAP"); - assertEquals(service.kindOf(Collections.EMPTY_LIST), "LIST"); - - assertEquals(service.toString(), "<Strategy for org.apache.tapestry5.ioc.internal.services.KindOf>"); - - try - { - service.kindOf(null); - unreachable(); - } catch (RuntimeException ex) - { - assertEquals(ex.getMessage(), - "No adapter from type void to type org.apache.tapestry5.ioc.internal.services.KindOf is available."); - } - } - - @Test - public void using_registration_map() - { - Map<Class, KindOf> registrations = CollectionFactory.newMap(); - - registrations.put(Map.class, new KindOfImpl("MAP")); - registrations.put(List.class, new KindOfImpl("LIST")); - StrategyBuilder builder = getService(StrategyBuilder.class); - - KindOf service = builder.build(KindOf.class, registrations); - - assertEquals(service.kindOf(Collections.EMPTY_MAP), "MAP"); - assertEquals(service.kindOf(Collections.EMPTY_LIST), "LIST"); - } - - private StrategyRegistry<KindOf> buildStrategyRegistry() - { - Map<Class, KindOf> registrations = CollectionFactory.newMap(); - - registrations.put(Map.class, new KindOfImpl("MAP")); - registrations.put(List.class, new KindOfImpl("LIST")); - - return StrategyRegistry.newInstance(KindOf.class, registrations); - } -}
