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 14:26:46 UTC

[groovy] branch master 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 master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 1658103  GROOVY-5358: getProperty, setProperty, invokeMethod from category method (additional test case)
1658103 is described below

commit 1658103121e313893926a8febcfbcf6f4f489c57
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"
+                }
+            }
+        '''
+    }
 }