You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2022/01/17 22:18:36 UTC
[groovy] branch GROOVY_4_0_X updated: GROOVY-5358: getProperty, setProperty, invokeMethod from category method (additional test case)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new 8e2b08e GROOVY-5358: getProperty, setProperty, invokeMethod from category method (additional test case)
8e2b08e is described below
commit 8e2b08e6fe31ddcf15a4bcfb0cb8803042fc0e2f
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Jan 18 00:26:37 2022 +1000
GROOVY-5358: getProperty, setProperty, invokeMethod from category method (additional test case)
---
src/test/groovy/bugs/Groovy5358.groovy | 43 ++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/src/test/groovy/bugs/Groovy5358.groovy b/src/test/groovy/bugs/Groovy5358.groovy
index 28a1000..8737636 100644
--- a/src/test/groovy/bugs/Groovy5358.groovy
+++ b/src/test/groovy/bugs/Groovy5358.groovy
@@ -66,4 +66,47 @@ final class Groovy5358 {
}
'''
}
+
+ @Test
+ void testSetPropertyOverrides() {
+ assertScript '''
+ class FooWorksAsMap {
+ def val
+ void setProperty(String name, value) {
+ val = "OK:FooWorksAsMap.$value"
+ }
+ }
+ class BarWorksAsMap {
+ def val
+ }
+ @Category(BarWorksAsMap) class C {
+ void setProperty(String name, value) {
+ setVal("OK:BarWorksAsMap.$value")
+ }
+ }
+ BarWorksAsMap.mixin C
+ class BazWorksAsMap {
+ def val
+ }
+ BazWorksAsMap.metaClass.setProperty = { String name, value ->
+ setVal("OK:BazWorksAsMap.$value")
+ }
+
+ def objects = [
+ new FooWorksAsMap(),
+ new BarWorksAsMap(),
+ new BazWorksAsMap(),
+ [:]
+ ]
+ for (def obj in objects) {
+ def which = "${obj.getClass().getSimpleName()}.val"
+ try {
+ obj.val = which.startsWith('LinkedHashMap') ? "OK:LinkedHashMap.bar" : 'bar'
+ assert obj.val.startsWith('OK:') : "$which -> $obj.val"
+ } catch (any) {
+ assert false : "$which -> FAIL:$any"
+ }
+ }
+ '''
+ }
}