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 21:35:35 UTC
[6/6] 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/c9a62410
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/c9a62410
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/c9a62410
Branch: refs/heads/master
Commit: c9a624109b0fae47ef7fbc4ee32127bddd6b77ee
Parents: 26f41f2
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Thu Jun 21 10:50:50 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Thu Jun 21 10:50:50 2012 -0700
----------------------------------------------------------------------
.../groovy/ioc/specs/PropertyAccessImplSpec.groovy | 2 +-
.../src/test/groovy/ioc/specs/TestBaseSpec.groovy | 105 ++++++++++++++
.../internal/services/AnnotatedBeanSubclass.java | 5 +
.../ioc/internal/services/BeanSubclass.java | 25 ----
.../apache/tapestry5/ioc/test/BeanSubclass.java | 25 ++++
.../apache/tapestry5/ioc/test/TestBaseTest.java | 113 ---------------
6 files changed, 136 insertions(+), 139 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9a62410/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy
index f93c3fc..93a1459 100644
--- a/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy
@@ -497,7 +497,7 @@ class PropertyAccessImplSpec extends Specification {
def "getAnnotation() will find annotations from an inherited field in a super-class"() {
when:
- def pa = getPropertyAdapter BeanSubclass, "value"
+ def pa = getPropertyAdapter AnnotatedBeanSubclass, "value"
then:
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9a62410/tapestry-ioc/src/test/groovy/ioc/specs/TestBaseSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/TestBaseSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/TestBaseSpec.groovy
new file mode 100644
index 0000000..9eaadf6
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/TestBaseSpec.groovy
@@ -0,0 +1,105 @@
+package ioc.specs
+
+import org.apache.tapestry5.ioc.test.Bean
+import org.apache.tapestry5.ioc.test.BeanSubclass
+import org.apache.tapestry5.ioc.test.TestBase
+import spock.lang.Specification
+
+class TestBaseSpec extends Specification {
+
+ TestBase base = new TestBase()
+
+ /** Any unrecognized methods are evaluated against the TestBase instance. */
+ def methodMissing(String name, args) {
+ base."$name"(* args)
+ }
+
+
+ def "create an instance of an arbitrary class"() {
+ when:
+
+ def b = create(Bean, "value", "Magic")
+
+ then:
+
+ b.value == "Magic"
+ }
+
+ def "reporting of exception when instantiating an instance"() {
+ when:
+
+ create(Runnable)
+
+ then:
+
+ RuntimeException e = thrown()
+
+ e.message.contains "Unable to instantiate instance of java.lang.Runnable"
+ }
+
+ def "attempt to set value of non-existent instance field of created object"() {
+ when:
+
+ create(Bean, "unknownField", "doesn't matter")
+
+ then:
+
+ RuntimeException e = thrown()
+
+ e.message.contains "Unable to set field 'unknownField' of org.apache.tapestry5.ioc.test.Bean"
+ e.message.contains "Class org.apache.tapestry5.ioc.test.Bean does not contain a field named 'unknownField'."
+ }
+
+ def "type mismatch when setting field value of created object"() {
+
+ when:
+
+ create(Bean, "value", 99)
+
+ then:
+
+ RuntimeException e = thrown()
+
+ e.message.contains "Unable to set field 'value' of org.apache.tapestry5.ioc.test.Bean"
+ }
+
+ def "create object, setting fields from base class"() {
+ when:
+
+ def b = create(BeanSubclass, "flag", true, "value", "magic")
+
+ then:
+
+ b.flag == true
+ b.value == "magic"
+ }
+
+ def "write and read a private field"() {
+ def b = new Bean()
+ def expected = "fred"
+
+ when:
+
+ set(b, "value", expected)
+
+ then:
+
+ b.value.is(expected)
+ get(b, "value").is(expected)
+ }
+
+ def "getting the value of a field that does not exist is an error"() {
+ def b = new Bean()
+
+ when:
+
+ get(b, "missingField")
+
+ then:
+
+ RuntimeException e = thrown()
+
+ e.message.contains "Unable to read field 'missingField' of $Bean.name"
+ e.message.contains "Class $Bean.name does not contain a field named 'missingField'."
+ }
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9a62410/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/AnnotatedBeanSubclass.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/AnnotatedBeanSubclass.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/AnnotatedBeanSubclass.java
new file mode 100644
index 0000000..13c7844
--- /dev/null
+++ b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/AnnotatedBeanSubclass.java
@@ -0,0 +1,5 @@
+package org.apache.tapestry5.ioc.internal.services;
+
+public class AnnotatedBeanSubclass extends Bean
+{
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9a62410/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/BeanSubclass.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/BeanSubclass.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/BeanSubclass.java
deleted file mode 100644
index 62bffe3..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/BeanSubclass.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2008 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;
-
-public class BeanSubclass extends Bean
-{
- private boolean flag;
-
- public boolean isFlag()
- {
- return flag;
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9a62410/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/test/BeanSubclass.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/test/BeanSubclass.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/test/BeanSubclass.java
new file mode 100644
index 0000000..2fd0fa2
--- /dev/null
+++ b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/test/BeanSubclass.java
@@ -0,0 +1,25 @@
+// Copyright 2008 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.test;
+
+public class BeanSubclass extends Bean
+{
+ private boolean flag;
+
+ public boolean isFlag()
+ {
+ return flag;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9a62410/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/test/TestBaseTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/test/TestBaseTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/test/TestBaseTest.java
deleted file mode 100644
index 03cec2d..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/test/TestBaseTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright 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.test;
-
-import org.apache.tapestry5.ioc.internal.services.BeanSubclass;
-import org.testng.annotations.Test;
-
-public class TestBaseTest extends TestBase
-{
- @Test
- public void create_instance()
- {
- Bean b = create(Bean.class, "value", "Magic");
-
- assertEquals(b.getValue(), "Magic");
- }
-
- @Test
- public void create_instance_failure()
- {
- try
- {
- create(Runnable.class);
- unreachable();
- }
- catch (RuntimeException ex)
- {
- assertMessageContains(ex, "Unable to instantiate instance of java.lang.Runnable");
- }
- }
-
- @Test
- public void create_instance_field_missing()
- {
- try
- {
- create(Bean.class, "unknownField", "doesn't matter");
- unreachable();
- }
- catch (RuntimeException ex)
- {
- assertMessageContains(ex, "Unable to set field 'unknownField' of org.apache.tapestry5.ioc.test.Bean",
- "Class org.apache.tapestry5.ioc.test.Bean does not contain a field named 'unknownField'.");
- }
- }
-
- @Test
- public void type_mismatch_when_setting_field_value()
- {
- try
- {
- create(Bean.class, "value", 99);
- unreachable();
- }
- catch (RuntimeException ex)
- {
- assertMessageContains(ex, "Unable to set field 'value' of org.apache.tapestry5.ioc.test.Bean");
- }
- }
-
- @Test
- public void set_fields_from_base_class()
- {
- BeanSubclass b = create(BeanSubclass.class, "flag", true, "value", "magic");
-
- assertEquals(b.isFlag(), true);
- assertEquals(b.getValue(), "magic");
- }
-
- @Test
- public void get_field()
- {
- Bean b = new Bean();
-
- String expectedValue = "fred";
-
- set(b, "value", expectedValue);
-
- assertSame(b.getValue(), expectedValue);
- assertSame(get(b, "value"), expectedValue);
- }
-
- @Test
- public void error_getting_field()
- {
- Bean b = new Bean();
-
- try
- {
- get(b, "missingField");
- unreachable();
- }
- catch (RuntimeException ex)
- {
- assertMessageContains(ex,
- "Unable to read field 'missingField' of org.apache.tapestry5.ioc.test.Bean",
- "Class org.apache.tapestry5.ioc.test.Bean does not contain a field named 'missingField'.");
-
- }
- }
-}