Removed commented-out code.
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/fd3ce1a6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/fd3ce1a6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/fd3ce1a6 Branch: refs/heads/master Commit: fd3ce1a625ce92aae41a8339a7a77533c883f964 Parents: 1a320e9 Author: John Hurst <john.b.hu...@gmail.com> Authored: Sun Dec 28 17:41:59 2014 +1300 Committer: Paul King <pa...@asert.com.au> Committed: Fri May 22 20:59:26 2015 +1000 ---------------------------------------------------------------------- .../codehaus/groovy/ast/tools/GeneralUtils.java | 18 ++++ .../ExternalizeMethodsASTTransformation.java | 1 + .../ExternalizeVerifierASTTransformation.java | 1 + .../transform/SortableASTTransformation.java | 14 +-- .../transform/AutoCloneTransformTest.groovy | 66 ++++++++++++++ .../EqualsAndHashCodeTransformTest.groovy | 90 +++++++++++++++++++ .../ExternalizeMethodsTransformTest.groovy | 65 ++++++++++++++ .../ExternalizeVerifierTransformTest.groovy | 82 +++++++++++++++++ .../transform/SortableTransformTest.groovy | 13 ++- .../transform/ToStringTransformTest.groovy | 95 ++++++++++++++++---- .../TupleConstructorTransformTest.groovy | 89 ++++++++++++++++++ 11 files changed, 505 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fd3ce1a6/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java ---------------------------------------------------------------------- diff --git a/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java index 7fa98a1..16e8335 100644 --- a/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java +++ b/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java @@ -363,6 +363,15 @@ public class GeneralUtils { return result; } + public static List<String> getInstanceNonPropertyFieldNames(ClassNode cNode) { + List<FieldNode> fList = getInstanceNonPropertyFields(cNode); + List<String> result = new ArrayList<String>(fList.size()); + for (FieldNode fNode : fList) { + result.add(fNode.getName()); + } + return result; + } + public static List<PropertyNode> getInstanceProperties(ClassNode cNode) { final List<PropertyNode> result = new ArrayList<PropertyNode>(); for (PropertyNode pNode : cNode.getProperties()) { @@ -373,6 +382,15 @@ public class GeneralUtils { return result; } + public static List<String> getInstancePropertyNames(ClassNode cNode) { + List<PropertyNode> pList = getInstanceProperties(cNode); + List<String> result = new ArrayList<String>(pList.size()); + for (PropertyNode pNode : pList) { + result.add(pNode.getName()); + } + return result; + } + public static List<FieldNode> getInstancePropertyFields(ClassNode cNode) { final List<FieldNode> result = new ArrayList<FieldNode>(); for (PropertyNode pNode : cNode.getProperties()) { http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fd3ce1a6/src/main/org/codehaus/groovy/transform/ExternalizeMethodsASTTransformation.java ---------------------------------------------------------------------- diff --git a/src/main/org/codehaus/groovy/transform/ExternalizeMethodsASTTransformation.java b/src/main/org/codehaus/groovy/transform/ExternalizeMethodsASTTransformation.java index 17a4b96..822c0bf 100644 --- a/src/main/org/codehaus/groovy/transform/ExternalizeMethodsASTTransformation.java +++ b/src/main/org/codehaus/groovy/transform/ExternalizeMethodsASTTransformation.java @@ -75,6 +75,7 @@ public class ExternalizeMethodsASTTransformation extends AbstractASTTransformati cNode.addInterface(EXTERNALIZABLE_TYPE); boolean includeFields = memberHasValue(anno, "includeFields", true); List<String> excludes = getMemberList(anno, "excludes"); + if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields)) return; List<FieldNode> list = getInstancePropertyFields(cNode); if (includeFields) { list.addAll(getInstanceNonPropertyFields(cNode)); http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fd3ce1a6/src/main/org/codehaus/groovy/transform/ExternalizeVerifierASTTransformation.java ---------------------------------------------------------------------- diff --git a/src/main/org/codehaus/groovy/transform/ExternalizeVerifierASTTransformation.java b/src/main/org/codehaus/groovy/transform/ExternalizeVerifierASTTransformation.java index 7ec0cc9..4afeecf 100644 --- a/src/main/org/codehaus/groovy/transform/ExternalizeVerifierASTTransformation.java +++ b/src/main/org/codehaus/groovy/transform/ExternalizeVerifierASTTransformation.java @@ -62,6 +62,7 @@ public class ExternalizeVerifierASTTransformation extends AbstractASTTransformat boolean includeFields = memberHasValue(anno, "includeFields", true); boolean checkPropertyTypes = memberHasValue(anno, "checkPropertyTypes", true); List<String> excludes = getMemberList(anno, "excludes"); + if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields)) return; List<FieldNode> list = getInstancePropertyFields(cNode); if (includeFields) { list.addAll(getInstanceNonPropertyFields(cNode)); http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fd3ce1a6/src/main/org/codehaus/groovy/transform/SortableASTTransformation.java ---------------------------------------------------------------------- diff --git a/src/main/org/codehaus/groovy/transform/SortableASTTransformation.java b/src/main/org/codehaus/groovy/transform/SortableASTTransformation.java index 69e2bbb..a6f1eab 100644 --- a/src/main/org/codehaus/groovy/transform/SortableASTTransformation.java +++ b/src/main/org/codehaus/groovy/transform/SortableASTTransformation.java @@ -83,6 +83,8 @@ public class SortableASTTransformation extends AbstractASTTransformation { List<String> includes = getMemberList(annotation, "includes"); List<String> excludes = getMemberList(annotation, "excludes"); if (!checkIncludeExclude(annotation, excludes, includes, MY_TYPE_NAME)) return; + if (!checkPropertyList(classNode, includes, "includes", annotation, MY_TYPE_NAME, false)) return; + if (!checkPropertyList(classNode, excludes, "excludes", annotation, MY_TYPE_NAME, false)) return; if (classNode.isInterface()) { addError(MY_TYPE_NAME + " cannot be applied to interface " + classNode.getName(), annotation); } @@ -198,9 +200,6 @@ public class SortableASTTransformation extends AbstractASTTransformation { !includes.isEmpty() && !includes.contains(propertyName)) continue; properties.add(property); } - for (String name : includes) { - checkKnownProperty(annotation, name, properties); - } for (PropertyNode pNode : properties) { checkComparable(pNode); } @@ -223,13 +222,4 @@ public class SortableASTTransformation extends AbstractASTTransformation { pNode.getName() + "' must be Comparable", pNode); } - private void checkKnownProperty(AnnotationNode annotation, String name, List<PropertyNode> properties) { - for (PropertyNode pNode: properties) { - if (name.equals(pNode.getName())) { - return; - } - } - addError("Error during " + MY_TYPE_NAME + " processing: tried to include unknown property '" + - name + "'", annotation); - } } http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fd3ce1a6/src/test/org/codehaus/groovy/transform/AutoCloneTransformTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/org/codehaus/groovy/transform/AutoCloneTransformTest.groovy b/src/test/org/codehaus/groovy/transform/AutoCloneTransformTest.groovy new file mode 100644 index 0000000..05aa26b --- /dev/null +++ b/src/test/org/codehaus/groovy/transform/AutoCloneTransformTest.groovy @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.codehaus.groovy.transform + +class AutoCloneTransformTest extends GroovyShellTestCase { + + void testOk() { + assertScript """ + import groovy.transform.AutoClone + + @AutoClone + class Person { + String first, last + List favItems + Date since + } + + def p = new Person(first:'John', last:'Smith', favItems:['ipod', 'shiraz'], since:new Date()) + def p2 = p.clone() + + assert p instanceof Cloneable + assert p.favItems instanceof Cloneable + assert p.since instanceof Cloneable + assert !(p.first instanceof Cloneable) + + assert !p.is(p2) + assert !p.favItems.is(p2.favItems) + assert !p.since.is(p2.since) + assert p.first.is(p2.first) + """ + } + + void testExcludesWithInvalidPropertyNameResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.AutoClone + + @AutoClone(excludes='sirName') + class Person { + String firstName + String surName + } + + new Person(firstName: "John", surName: "Doe").clone() + """ + } + assert message.contains("Error during @AutoClone processing: 'excludes' property 'sirName' does not exist.") + } + +} http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fd3ce1a6/src/test/org/codehaus/groovy/transform/EqualsAndHashCodeTransformTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/org/codehaus/groovy/transform/EqualsAndHashCodeTransformTest.groovy b/src/test/org/codehaus/groovy/transform/EqualsAndHashCodeTransformTest.groovy new file mode 100644 index 0000000..1333887 --- /dev/null +++ b/src/test/org/codehaus/groovy/transform/EqualsAndHashCodeTransformTest.groovy @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.codehaus.groovy.transform + +class EqualsAndHashCodeTransformTest extends GroovyShellTestCase { + + void testOk() { + assertScript """ + import groovy.transform.EqualsAndHashCode + @EqualsAndHashCode + class Person { + String first, last + int age + } + + def p1 = new Person(first:'John', last:'Smith', age:21) + def p2 = new Person(first:'John', last:'Smith', age:21) + assert p1 == p2 + def map = [:] + map[p1] = 45 + assert map[p2] == 45 + """ + } + + void testIncludesAndExcludesTogetherResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.EqualsAndHashCode + + @EqualsAndHashCode(includes='surName', excludes='surName') + class Person { + String surName + } + + new Person(surName: "Doe") + """ + } + assert message.contains("Error during @EqualsAndHashCode processing: Only one of 'includes' and 'excludes' should be supplied not both.") + } + + void testIncludesWithInvalidPropertyNameResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.EqualsAndHashCode + + @EqualsAndHashCode(includes='sirName') + class Person { + String surName + } + + new Person(surName: "Doe") + """ + } + assert message.contains("Error during @EqualsAndHashCode processing: 'includes' property 'sirName' does not exist.") + } + + void testExcludesWithInvalidPropertyNameResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.EqualsAndHashCode + + @EqualsAndHashCode(excludes='sirName') + class Person { + String firstName + String surName + } + + new Person(firstName: "John", surName: "Doe") + """ + } + assert message.contains("Error during @EqualsAndHashCode processing: 'excludes' property 'sirName' does not exist.") + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fd3ce1a6/src/test/org/codehaus/groovy/transform/ExternalizeMethodsTransformTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/org/codehaus/groovy/transform/ExternalizeMethodsTransformTest.groovy b/src/test/org/codehaus/groovy/transform/ExternalizeMethodsTransformTest.groovy new file mode 100644 index 0000000..663a07c --- /dev/null +++ b/src/test/org/codehaus/groovy/transform/ExternalizeMethodsTransformTest.groovy @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.codehaus.groovy.transform + +class ExternalizeMethodsTransformTest extends GroovyShellTestCase { + + void testOk() { + assertScript """ + import groovy.transform.ExternalizeMethods + @ExternalizeMethods + class Person { + String first, last + List favItems + Date since + } + + def p = new Person(first: "John", last: "Doe", favItems: ["one", "two"], since: Date.parse("yyyy-MM-dd", "2014-12-28")) + + def baos = new ByteArrayOutputStream() + p.writeExternal(new ObjectOutputStream(baos)) + + def p2 = new Person() + p2.readExternal(new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) + + assert p2.first == "John" + assert p2.last == "Doe" + assert p2.favItems == ["one", "two"] + assert p2.since == Date.parse("yyyy-MM-dd", "2014-12-28") + """ + } + + void testExcludesWithInvalidPropertyNameResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.ExternalizeMethods + + @ExternalizeMethods(excludes='sirName') + class Person { + String firstName + String surName + } + + new Person(firstName: "John", surName: "Doe") + """ + } + assert message.contains("Error during @ExternalizeMethods processing: 'excludes' property 'sirName' does not exist.") + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fd3ce1a6/src/test/org/codehaus/groovy/transform/ExternalizeVerifierTransformTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/org/codehaus/groovy/transform/ExternalizeVerifierTransformTest.groovy b/src/test/org/codehaus/groovy/transform/ExternalizeVerifierTransformTest.groovy new file mode 100644 index 0000000..9a04081 --- /dev/null +++ b/src/test/org/codehaus/groovy/transform/ExternalizeVerifierTransformTest.groovy @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.codehaus.groovy.transform + +class ExternalizeVerifierTransformTest extends GroovyShellTestCase { + + void testCheckPropertyTypes() { + def message = shouldFail { + evaluate """ + import groovy.transform.ExternalizeVerifier + + class Foo {} + + @ExternalizeVerifier(checkPropertyTypes=true) + class Person implements Externalizable { + String firstName + Foo foo + + void readExternal(ObjectInput inp) {} + void writeExternal(ObjectOutput outp) {} + } + + new Person() + """ + } + assert message.contains("@ExternalizeVerifier: strict type checking is enabled and the non-primitive property (or field) 'foo' in an Externalizable class has the type 'Foo' which isn't Externalizable or Serializable") + } + + void testExcludes() { + assertScript """ + import groovy.transform.ExternalizeVerifier + + class Foo {} + + @ExternalizeVerifier(excludes='foo', checkPropertyTypes=true) + class Person implements Externalizable { + String firstName + Foo foo + + void readExternal(ObjectInput inp) {} + void writeExternal(ObjectOutput outp) {} + } + + new Person() + """ + } + + void testExcludesWithInvalidPropertyNameResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.ExternalizeVerifier + + @ExternalizeVerifier(excludes='sirName') + class Person implements Externalizable { + String firstName + String surName + + void readExternal(ObjectInput inp) {} + void writeExternal(ObjectOutput outp) {} + } + """ + } + assert message.contains("Error during @ExternalizeVerifier processing: 'excludes' property 'sirName' does not exist.") + } + +} http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fd3ce1a6/src/test/org/codehaus/groovy/transform/SortableTransformTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/org/codehaus/groovy/transform/SortableTransformTest.groovy b/src/test/org/codehaus/groovy/transform/SortableTransformTest.groovy index e4c59cc..6a0540e 100644 --- a/src/test/org/codehaus/groovy/transform/SortableTransformTest.groovy +++ b/src/test/org/codehaus/groovy/transform/SortableTransformTest.groovy @@ -135,7 +135,18 @@ class SortableTransformTest extends CompilableTestSupport { Integer born } ''' - assert message.contains("Error during @Sortable processing: tried to include unknown property 'middle'") + assert message.contains("Error during @Sortable processing: 'includes' property 'middle' does not exist.") + } + + void testBadExclude() { + def message = shouldFail ''' + @groovy.transform.Sortable(excludes='first,middle') class Person { + String first + String last + Integer born + } + ''' + assert message.contains("Error during @Sortable processing: 'excludes' property 'middle' does not exist.") } void testBadPropertyType() { http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fd3ce1a6/src/test/org/codehaus/groovy/transform/ToStringTransformTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/org/codehaus/groovy/transform/ToStringTransformTest.groovy b/src/test/org/codehaus/groovy/transform/ToStringTransformTest.groovy index 675c900..0df3b9d 100644 --- a/src/test/org/codehaus/groovy/transform/ToStringTransformTest.groovy +++ b/src/test/org/codehaus/groovy/transform/ToStringTransformTest.groovy @@ -18,11 +18,8 @@ */ package org.codehaus.groovy.transform -/** - * @author Andre Steingress - */ class ToStringTransformTest extends GroovyShellTestCase { - + void testSimpleToString() { def toString = evaluate(""" import groovy.transform.ToString @@ -140,7 +137,7 @@ class ToStringTransformTest extends GroovyShellTestCase { assertEquals("BandMember(bandName:U2, name:Bono)", toString) } - void testSuper() { + void testSuper() { def toString = evaluate(""" import groovy.transform.ToString @@ -164,7 +161,7 @@ class ToStringTransformTest extends GroovyShellTestCase { assertEquals("Person(null, Doe, HumanBeing())", toString) } - void testIgnoreStaticProperties() { + void testIgnoreStaticProperties() { def toString = evaluate(""" import groovy.transform.ToString @@ -180,7 +177,7 @@ class ToStringTransformTest extends GroovyShellTestCase { assertEquals("Person()", toString) } - void testWithCollection() { + void testWithCollection() { def toString = evaluate(""" import groovy.transform.ToString @@ -197,7 +194,7 @@ class ToStringTransformTest extends GroovyShellTestCase { assertEquals("Person(relatives:[a, b, c], mates:[friends:[c, d, e]])", toString) } - void testExcludesAndIgnoreNulls() { + void testExcludesAndIgnoreNulls() { def toString = evaluate(""" import groovy.transform.ToString @@ -213,7 +210,7 @@ class ToStringTransformTest extends GroovyShellTestCase { assertEquals("Person()", toString) } - void testIncludesAndIgnoreNulls() { + void testIncludesAndIgnoreNulls() { def toString = evaluate(""" import groovy.transform.ToString @@ -229,7 +226,7 @@ class ToStringTransformTest extends GroovyShellTestCase { assertEquals("Person()", toString) } - void testSkipInternalProperties() { + void testSkipInternalProperties() { def toString = evaluate(""" import groovy.transform.ToString @@ -245,7 +242,7 @@ class ToStringTransformTest extends GroovyShellTestCase { assertEquals("Person()", toString) } - void testPseudoProperties() { + void testPseudoProperties() { def toString = evaluate(''' import groovy.transform.* @@ -300,7 +297,7 @@ class ToStringTransformTest extends GroovyShellTestCase { assert toString == "SportsPerson(title:Mr, golfer:false, adult:true, cyclist:true)" } - void testSelfReference() { + void testSelfReference() { def toString = evaluate(""" import groovy.transform.* @@ -319,7 +316,7 @@ class ToStringTransformTest extends GroovyShellTestCase { assert toString == 'Tree(val:foo, left:(this), right:(this))' } - + void testIncludePackage() { def toString = evaluate(""" package my.company @@ -333,7 +330,7 @@ class ToStringTransformTest extends GroovyShellTestCase { """) assertEquals("my.company.Person()", toString) - + toString = evaluate(""" package my.company @@ -346,7 +343,7 @@ class ToStringTransformTest extends GroovyShellTestCase { """) assertEquals("my.company.Person()", toString) - + toString = evaluate(""" package my.company @@ -357,7 +354,73 @@ class ToStringTransformTest extends GroovyShellTestCase { new Person().toString() """) - + assertEquals("Person()", toString) } + + void testIncludeSuperWithoutSuperClassResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.ToString + + @ToString(includeSuper=true) + class Person { + String surName + } + + new Person(surName: "Doe").toString() + """ + } + assert message.contains("Error during @ToString processing: includeSuper=true but 'Person' has no super class.") + } + + void testIncludesAndExcludesTogetherResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.ToString + + @ToString(includes='surName', excludes='surName') + class Person { + String surName + } + + new Person(surName: "Doe").toString() + """ + } + assert message.contains("Error during @ToString processing: Only one of 'includes' and 'excludes' should be supplied not both.") + } + + void testIncludesWithInvalidPropertyNameResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.ToString + + @ToString(includes='sirName') + class Person { + String surName + } + + new Person(surName: "Doe").toString() + """ + } + assert message.contains("Error during @ToString processing: 'includes' property 'sirName' does not exist.") + } + + void testExcludesWithInvalidPropertyNameResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.ToString + + @ToString(excludes='sirName') + class Person { + String firstName + String surName + } + + new Person(firstName: "John", surName: "Doe").toString() + """ + } + assert message.contains("Error during @ToString processing: 'excludes' property 'sirName' does not exist.") + } + } http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fd3ce1a6/src/test/org/codehaus/groovy/transform/TupleConstructorTransformTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/org/codehaus/groovy/transform/TupleConstructorTransformTest.groovy b/src/test/org/codehaus/groovy/transform/TupleConstructorTransformTest.groovy new file mode 100644 index 0000000..d8fa6d9 --- /dev/null +++ b/src/test/org/codehaus/groovy/transform/TupleConstructorTransformTest.groovy @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.codehaus.groovy.transform + +class TupleConstructorTransformTest extends GroovyShellTestCase { + + void testOk() { + assertScript """ + import groovy.transform.TupleConstructor + + @TupleConstructor + class Person { + String firstName + String lastName + } + + def p = new Person("John", "Doe") + assert p.firstName == "John" + assert p.lastName == "Doe" + """ + } + + void testIncludesAndExcludesTogetherResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.TupleConstructor + + @TupleConstructor(includes='surName', excludes='surName') + class Person { + String surName + } + + new Person("Doe") + """ + } + assert message.contains("Error during @TupleConstructor processing: Only one of 'includes' and 'excludes' should be supplied not both.") + } + + void testIncludesWithInvalidPropertyNameResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.TupleConstructor + + @TupleConstructor(includes='sirName') + class Person { + String firstName + String surName + } + + def p = new Person("John", "Doe") + """ + } + assert message.contains("Error during @TupleConstructor processing: 'includes' property 'sirName' does not exist.") + } + + void testExcludesWithInvalidPropertyNameResultsInError() { + def message = shouldFail { + evaluate """ + import groovy.transform.TupleConstructor + + @TupleConstructor(excludes='sirName') + class Person { + String firstName + String surName + } + + def p = new Person("John", "Doe") + """ + } + assert message.contains("Error during @TupleConstructor processing: 'excludes' property 'sirName' does not exist.") + } + +} \ No newline at end of file