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

sunlan 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 e0d51fde68 GROOVY-11915: add more test cases and trivial tweaks
e0d51fde68 is described below

commit e0d51fde6869d6121231f7943d22ad3254072944
Author: Daniel Sun <[email protected]>
AuthorDate: Sat Apr 11 10:31:21 2026 +0900

    GROOVY-11915: add more test cases and trivial tweaks
---
 .../apache/groovy/ginq/InvalidOptionException.java |  4 +-
 .../collection/runtime/GroupResultImpl.java        |  4 +-
 .../provider/collection/runtime/NamedRecord.groovy |  2 +-
 .../collection/runtime/TooManyValuesException.java |  4 +-
 .../test/org/apache/groovy/ginq/GinqTest.groovy    | 60 +++++++++++++++++++++-
 5 files changed, 68 insertions(+), 6 deletions(-)

diff --git 
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/InvalidOptionException.java
 
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/InvalidOptionException.java
index f25cb50f6c..22e74dfbf0 100644
--- 
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/InvalidOptionException.java
+++ 
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/InvalidOptionException.java
@@ -20,13 +20,15 @@ package org.apache.groovy.ginq;
 
 import org.codehaus.groovy.GroovyException;
 
+import java.io.Serial;
+
 /**
  * Represents invalid options, e.g. unsupported options
  *
  * @since 4.0.0
  */
 public class InvalidOptionException extends GroovyException {
-    private static final long serialVersionUID = -8644282992572200089L;
+    @Serial private static final long serialVersionUID = -8644282992572200089L;
 
     public InvalidOptionException(String message) {
         super(message);
diff --git 
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/GroupResultImpl.java
 
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/GroupResultImpl.java
index b9106a41a3..31c72c3e99 100644
--- 
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/GroupResultImpl.java
+++ 
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/GroupResultImpl.java
@@ -42,8 +42,8 @@ class GroupResultImpl<K, T> extends QueryableCollection<T> 
implements GroupResul
     public K getKey() {
         // For single-key groupby, the classifier wraps the key in a 
NamedRecord;
         // unwrap it so g.key returns the raw value rather than a 
single-element tuple
-        if (key instanceof NamedRecord && ((NamedRecord<?, ?>) key).size() == 
1) {
-            return (K) ((NamedRecord<?, ?>) key).get(0);
+        if (key instanceof NamedRecord k && k.size() == 1) {
+            return (K) k.get(0);
         }
         return key;
     }
diff --git 
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/NamedRecord.groovy
 
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/NamedRecord.groovy
index 8dcd535dc2..28ee82634f 100644
--- 
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/NamedRecord.groovy
+++ 
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/NamedRecord.groovy
@@ -32,7 +32,7 @@ import groovy.transform.stc.POJO
 @POJO
 class NamedRecord<E, T> extends NamedTuple<E> {
 
-    private static final long serialVersionUID = -2554041223576761912L
+    @Serial private static final long serialVersionUID = -2554041223576761912L
 
     private final List<String> aliasList
     private SourceRecord<T> sourceRecord
diff --git 
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/TooManyValuesException.java
 
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/TooManyValuesException.java
index 415bf44b0d..1b35e46ff0 100644
--- 
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/TooManyValuesException.java
+++ 
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/TooManyValuesException.java
@@ -20,13 +20,15 @@ package org.apache.groovy.ginq.provider.collection.runtime;
 
 import groovy.lang.GroovyRuntimeException;
 
+import java.io.Serial;
+
 /**
  * Thrown when too many values returned by sub-query in the {@code select} 
clause
  *
  * @since 4.0.0
  */
 public class TooManyValuesException extends GroovyRuntimeException {
-    private static final long serialVersionUID = -2479599910868287387L;
+    @Serial private static final long serialVersionUID = -2479599910868287387L;
 
     public TooManyValuesException(String msg) {
         super(msg);
diff --git 
a/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy 
b/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
index afdfeba38f..657f0ef6d5 100644
--- 
a/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
+++ 
b/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
@@ -3504,6 +3504,28 @@ class GinqTest {
         '''
     }
 
+    @Test
+    void "testGinq - from groupby into select - 4"() {
+        assertGinqScript '''
+            assert [[1, 2], [3, 6], [6, 18]] == GQ {
+                from n in [1, 1, 3, 3, 6, 6, 6]
+                groupby n into g
+                select g.n, g.sum(n -> n)
+            }.toList()
+        '''
+    }
+
+    @Test
+    void "testGinq - from groupby into select - 5"() {
+        assertGinqScript '''
+            assert [[1, 2], [3, 6], [6, 18]] == GQ {
+                from n in [1, 1, 3, 3, 6, 6, 6]
+                groupby n as m into g
+                select g.m, g.sum(m -> m)
+            }.toList()
+        '''
+    }
+
     @Test
     void "testGinq - from groupby into having select - 1"() {
         assertGinqScript '''
@@ -3517,7 +3539,7 @@ class GinqTest {
     }
 
     @Test
-    void "testGinq - from groupby into select - multi-key with property 
access"() {
+    void "testGinq - from groupby into select - multi-key with property access 
- 1"() {
         assertGinqScript '''
             def result = GQ {
                 from n in [[name: 'a', val: 1], [name: 'b', val: 2]]
@@ -3528,6 +3550,42 @@ class GinqTest {
         '''
     }
 
+    @Test
+    void "testGinq - from groupby into select - multi-key with property access 
- 2"() {
+        assertGinqScript '''
+            def result = GQ {
+                from n in [[name: 'a', val: 1], [name: 'b', val: 2]]
+                groupby n.name, n.val as val into g
+                select g.name, g.val, g.count()
+            }.toList().collect { it.toList() }.sort()
+            assert result == [['a', 1, 1], ['b', 2, 1]]
+        '''
+    }
+
+    @Test
+    void "testGinq - from groupby into select - multi-key with property access 
- 3"() {
+        assertGinqScript '''
+            def result = GQ {
+                from n in [[name: 'a', val: 1], [name: 'b', val: 2]]
+                groupby n.name as name, n.val into g
+                select g.name, g.val, g.count()
+            }.toList().collect { it.toList() }.sort()
+            assert result == [['a', 1, 1], ['b', 2, 1]]
+        '''
+    }
+
+    @Test
+    void "testGinq - from groupby into select - multi-key with property access 
- 4"() {
+        assertGinqScript '''
+            def result = GQ {
+                from n in [[name: 'a', val: 1], [name: 'b', val: 2]]
+                groupby n.name, n.val into g
+                select g.name, g.val, g.count()
+            }.toList().collect { it.toList() }.sort()
+            assert result == [['a', 1, 1], ['b', 2, 1]]
+        '''
+    }
+
     @Test
     void "testGinq - from groupby into select - multi-key with subscript"() {
         assertGinqScript '''

Reply via email to