This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY_5_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_5_0_X by this push:
     new 76a5335af4 add trait tests
76a5335af4 is described below

commit 76a5335af40e97beb1bd9d07a684f3d4de774eb1
Author: Eric Milles <[email protected]>
AuthorDate: Fri Sep 19 11:43:06 2025 -0500

    add trait tests
---
 .../traitx/TraitASTTransformationTest.groovy       | 84 ++++++++++++++++++----
 1 file changed, 71 insertions(+), 13 deletions(-)

diff --git 
a/src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
 
b/src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
index acdb2dc6ce..b697369a4f 100644
--- 
a/src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
+++ 
b/src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
@@ -393,33 +393,91 @@ final class TraitASTTransformationTest {
     @Test
     void testOverridePropertyDefinedInTrait() {
         assertScript shell, '''
-            trait Id {
-                Long id = 123L
+            trait Foo {
+                long id = 123L
             }
-
-            class Foo implements Id {
-                Long id = 456L
+            class Bar implements Foo {
+                long id = 456L
             }
-            def f = new Foo()
-            assert f.id == 456L
+
+            def pogo = new Bar()
+            assert pogo.id == 456L
+            assert pogo.getId() == 456L
         '''
     }
 
     @Test
     void testOverridePropertyGetterDefinedInTrait() {
         assertScript shell, '''
-            trait Id {
-                Long id = 123L
+            trait Foo {
+                long id = 123L
             }
+            class Bar implements Foo {
+                long getId() { 456L }
+            }
+
+            def pogo = new Bar()
+            assert pogo.id == 456L
+            assert pogo.getId() == 456L
+        '''
+    }
 
-            class Foo implements Id {
-                Long getId() { 456L }
+    @Test
+    void testShadowingPropertyGetterDefinedInTrait() {
+        assertScript shell, '''
+            trait Foo {
+                private long getId() { 123L }
             }
-            def f = new Foo()
-            assert f.id == 456L
+            trait Bar extends Foo {
+                long id = 456L
+            }
+            class Baz implements Bar {
+            }
+
+            def pogo = new Baz()
+            assert pogo.id == 456L
+            assert pogo.getId() == 456L
         '''
     }
 
+    @ParameterizedTest
+    @ValueSource(strings=['public',/*TODO:'protected',*/'private'])
+    void testFinalPropertyGetterDefinedInSuperClass(String modifier) {
+        assertScript shell, """
+            trait Foo {
+                final long id = 123L
+            }
+            class Bar {
+                $modifier final long getId() { 456L }
+            }
+            class Baz extends Bar implements Foo {
+            }
+
+            def pogo = new Baz()
+            assert pogo.id == ${modifier == 'private' ? '123L' : '456L'}
+            assert pogo.getId() == ${modifier == 'private' ? '123L' : '456L'}
+        """
+    }
+
+    @ParameterizedTest
+    
@ValueSource(strings=['private','@PackageScope','protected','public','static'])
+    void testNonFinalPropertyGetterDefinedInSuperClass(String modifier) {
+        assertScript shell, """
+            trait Foo {
+                long id = 123L
+            }
+            class Bar {
+                $modifier long getId() { 456L }
+            }
+            class Baz extends Bar implements Foo {
+            }
+
+            def pogo = new Baz()
+            assert pogo.id == 123L
+            assert pogo.getId() == 123L
+        """
+    }
+
     @Test
     void testSimpleTraitInheritance() {
         assertScript shell, '''

Reply via email to