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 2026/04/13 05:01:17 UTC

(groovy) branch master updated (848bf7a135 -> e6e582aaed)

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

paulk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


    from 848bf7a135 GROOVY-11924: Provide a minimal declarative http client for the new http builder module
     new 59a9b97d67 GROOVY-7633: Add constructor with Map for SAXOptions to XmlSlurper
     new 38fc020f6c GROOVY-7633: Add constructor with Map for SAXOptions to XmlSlurper (align XmlParser behavior)
     new 06c645979f GROOVY-7571: XmlUtil should allow user to specify a character encoding when serializing
     new 90863c0946 minor refactor: XML Tests to junit5
     new cd7c7cb630 minor refactor: junit5 tests can have slightly cleaner names
     new e6e582aaed minor refactor: remove checkstyle warnings

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/main/java/groovy/xml/MarkupBuilder.java    |  10 ++
 .../src/main/java/groovy/xml/XmlParser.java        | 119 +++++++++++++---
 .../src/main/java/groovy/xml/XmlSlurper.java       | 150 ++++++++++++++++---
 .../src/main/java/groovy/xml/XmlUtil.java          | 158 ++++++++++++++++++++-
 .../org/apache/groovy/xml/tools/DomToGroovy.java   |   2 +
 .../groovy-xml/src/spec/doc/xml-userguide.adoc     |  57 ++++++++
 .../groovy-xml/src/spec/test/DOMBuilderTest.groovy |   5 +-
 .../groovy-xml/src/spec/test/SaxBuilderTest.groovy |   5 +-
 .../src/spec/test/StaxBuilderTest.groovy           |   8 +-
 .../src/spec/test/UserGuideDOMCategoryTest.groovy  |   5 +-
 .../spec/test/UserGuideMarkupBuilderTest.groovy    |  12 +-
 .../UserGuideStreamingMarkupBuilderTest.groovy     |   6 +-
 .../src/spec/test/UserGuideXmlParserTest.groovy    |  18 ++-
 .../src/spec/test/UserGuideXmlSlurperTest.groovy   |  23 ++-
 .../src/spec/test/UserGuideXmlUtilTest.groovy      |  25 +++-
 .../src/test/groovy/groovy/xml/DOMTest.groovy      |   4 +-
 .../test/groovy/groovy/xml/FactorySupportTest.java |  17 ++-
 .../groovy/groovy/xml/MarkupWithWriterTest.groovy  |   4 +-
 .../groovy/xml/NamespaceNodeGPathTest.groovy       |   2 +-
 .../groovy/groovy/xml/NamespaceNodeTest.groovy     |   8 +-
 .../groovy/groovy/xml/NavigationXmlTest.groovy     |   6 +-
 .../src/test/groovy/groovy/xml/SAXTest.groovy      |   4 +-
 .../groovy/xml/SafeNumberXmlParserTest.groovy      |   2 +-
 .../groovy/xml/SafeNumberXmlSlurperTest.groovy     |   2 +-
 .../test/groovy/groovy/xml/StaxBuilderTest.groovy  |   4 +-
 .../groovy/xml/StreamingSAXBuilderTest.groovy      |   6 +-
 .../groovy/xml/UseMarkupWithWriterScript.groovy    |   2 +-
 .../test/groovy/groovy/xml/VerboseDOMTest.groovy   |   4 +-
 .../groovy/groovy/xml/XmlNodePrinterTest.groovy    |  34 ++---
 .../groovy/groovy/xml/XmlParserFactoryTest.groovy  |   2 +-
 .../test/groovy/groovy/xml/XmlParserTest.groovy    |  58 +++++---
 .../groovy/groovy/xml/XmlSlurperFactoryTest.groovy |   2 +-
 .../test/groovy/groovy/xml/XmlSlurperTest.groovy   |  62 +++++---
 .../src/test/groovy/groovy/xml/XmlUtilTest.groovy  |   8 +-
 .../groovy/xml/benchmark/BuilderPerfTest.groovy    |   2 +-
 .../groovy/groovy/xml/bugs/Groovy249_Bug.groovy    |   4 +-
 .../groovy/groovy/xml/bugs/Groovy593_Bug.groovy    |   2 +-
 .../groovy/groovy/xml/bugs/Groovy_2473Bug.groovy   |   2 +-
 .../groovy/groovy/xml/bugs/MarkupInScriptBug.java  |   2 +-
 .../src/test/groovy/groovy/xml/bugs/SeansBug.java  |   4 +-
 .../groovy/groovy/xml/bugs/StaticMarkupBug.groovy  |   2 +-
 .../groovy/groovy/xml/bugs/TedsClosureBug.groovy   |   2 +-
 .../groovy/groovy/xml/dom/DOMCategoryTest.groovy   |  28 ++--
 .../src/test/groovy/groovy/xml/dom/DOMTest.groovy  |  14 +-
 .../groovy/groovy/xml/dom/NamespaceDOMTest.groovy  |   6 +-
 .../apache/groovy/xml/tools/DomToGroovyTest.groovy |   4 +-
 46 files changed, 719 insertions(+), 187 deletions(-)


(groovy) 04/06: minor refactor: XML Tests to junit5

Posted by pa...@apache.org.
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

commit 90863c0946b62fcce0f9d8a4ee4539a9fd77fdb6
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Apr 13 14:34:49 2026 +1000

    minor refactor: XML Tests to junit5
---
 .../groovy-xml/src/spec/test/DOMBuilderTest.groovy        |  5 +++--
 .../groovy-xml/src/spec/test/SaxBuilderTest.groovy        |  5 +++--
 .../groovy-xml/src/spec/test/StaxBuilderTest.groovy       |  8 ++++++--
 .../src/spec/test/UserGuideDOMCategoryTest.groovy         |  5 +++--
 .../src/spec/test/UserGuideMarkupBuilderTest.groovy       | 12 ++++++++++--
 .../spec/test/UserGuideStreamingMarkupBuilderTest.groovy  |  6 ++++--
 .../src/spec/test/UserGuideXmlParserTest.groovy           | 10 ++++++++--
 .../src/spec/test/UserGuideXmlSlurperTest.groovy          | 15 +++++++++++++--
 .../groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy  |  6 ++++--
 .../src/test/groovy/groovy/xml/FactorySupportTest.java    | 11 +++++++++--
 10 files changed, 63 insertions(+), 20 deletions(-)

diff --git a/subprojects/groovy-xml/src/spec/test/DOMBuilderTest.groovy b/subprojects/groovy-xml/src/spec/test/DOMBuilderTest.groovy
index 4099f0d716..d60cd8d859 100644
--- a/subprojects/groovy-xml/src/spec/test/DOMBuilderTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/DOMBuilderTest.groovy
@@ -16,10 +16,11 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
 
-class DOMBuilderTest extends GroovyTestCase {
+class DOMBuilderTest {
 
+    @Test
     void testParse() {
         // tag::xml_string[]
         String recordsXML = '''
diff --git a/subprojects/groovy-xml/src/spec/test/SaxBuilderTest.groovy b/subprojects/groovy-xml/src/spec/test/SaxBuilderTest.groovy
index ac054cd5d3..18bfb1bd0c 100644
--- a/subprojects/groovy-xml/src/spec/test/SaxBuilderTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/SaxBuilderTest.groovy
@@ -17,9 +17,9 @@
  *  under the License.
  */
 
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
 
-class SaxBuilderTest extends GroovyTestCase {
+class SaxBuilderTest {
 
     // tag::sax_builder_handler[]
     class LogHandler extends org.xml.sax.helpers.DefaultHandler {
@@ -36,6 +36,7 @@ class SaxBuilderTest extends GroovyTestCase {
     }
     // end::sax_builder_handler[]
 
+    @Test
     void testSaxBuilder() {
         // tag::sax_builder[]
         def handler = new LogHandler()
diff --git a/subprojects/groovy-xml/src/spec/test/StaxBuilderTest.groovy b/subprojects/groovy-xml/src/spec/test/StaxBuilderTest.groovy
index 2c8968415b..f5deb48624 100644
--- a/subprojects/groovy-xml/src/spec/test/StaxBuilderTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/StaxBuilderTest.groovy
@@ -17,10 +17,13 @@
  *  under the License.
  */
 
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
 
-class StaxBuilderTest extends GroovyTestCase {
+import static groovy.test.GroovyAssert.assertScript
 
+class StaxBuilderTest {
+
+    @Test
     void testStaxBuilder() {
         // tag::stax_builder[]
         def factory = javax.xml.stream.XMLOutputFactory.newInstance()
@@ -38,6 +41,7 @@ class StaxBuilderTest extends GroovyTestCase {
         // end::stax_builder[]
     }
 
+    @Test
     void testStaxBuilderExternalLibrary() {
         assertScript '''
             // tag::stax_builder_external_library[]
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideDOMCategoryTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideDOMCategoryTest.groovy
index 6c2de916c2..ba8cb6769f 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideDOMCategoryTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideDOMCategoryTest.groovy
@@ -18,13 +18,13 @@
  */
 package groovy.xml
 
-import groovy.test.GroovyTestCase
 import groovy.xml.dom.DOMCategory
+import org.junit.jupiter.api.Test
 
 /**
  * Tests for the Groovy Xml user guide related to DOMCategory.
  */
-class UserGuideDOMCategoryTest extends GroovyTestCase {
+class UserGuideDOMCategoryTest {
 
     // tag::testXML[]
     static def CAR_RECORDS = '''
@@ -45,6 +45,7 @@ class UserGuideDOMCategoryTest extends GroovyTestCase {
     '''
     // end::testXML[]
 
+    @Test
     void testExample1() {
         // tag::testExample1[]
         def reader = new StringReader(CAR_RECORDS)
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideMarkupBuilderTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideMarkupBuilderTest.groovy
index 17bff6214e..aa1e8233b9 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideMarkupBuilderTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideMarkupBuilderTest.groovy
@@ -18,13 +18,13 @@
  */
 package groovy.xml
 
-import groovy.test.GroovyTestCase
 import org.apache.groovy.xml.tools.DomToGroovy
+import org.junit.jupiter.api.Test
 
 /**
  * Tests for the Groovy Xml user guide related to MarkupBuilderTest.
  */
-class UserGuideMarkupBuilderTest extends GroovyTestCase {
+class UserGuideMarkupBuilderTest {
 
     void createCarsTest() {
         // tag::createCarsTest[]
@@ -49,6 +49,7 @@ class UserGuideMarkupBuilderTest extends GroovyTestCase {
         // end::createCarsTest[]
     }
 
+    @Test
     void testCreateSimpleXml1() {
         // tag::testCreateSimpleXml1[]
         def xmlString = "<movie>the godfather</movie>" // <1>
@@ -63,6 +64,7 @@ class UserGuideMarkupBuilderTest extends GroovyTestCase {
     }
 
 
+    @Test
     void testCreateSimpleXml2() {
         // tag::testCreateSimpleXml2[]
         def xmlString = "<movie id='2'>the godfather</movie>"
@@ -76,6 +78,7 @@ class UserGuideMarkupBuilderTest extends GroovyTestCase {
         // end::testCreateSimpleXml2[]
     }
 
+    @Test
     void testCreateSimpleXml3() {
         // tag::testCreateSimpleXml3[]
         def xmlWriter = new StringWriter()
@@ -92,6 +95,7 @@ class UserGuideMarkupBuilderTest extends GroovyTestCase {
         // end::testCreateSimpleXml3[]
     }
 
+    @Test
     void testNamespaceAware() {
         // tag::testNamespaceAware[]
         def xmlWriter = new StringWriter()
@@ -113,6 +117,7 @@ class UserGuideMarkupBuilderTest extends GroovyTestCase {
         // end::testNamespaceAware[]
     }
 
+    @Test
     void testComplexUse1() {
         // tag::testComplexUse1[]
         def xmlWriter = new StringWriter()
@@ -138,6 +143,7 @@ class UserGuideMarkupBuilderTest extends GroovyTestCase {
         // end::testComplexUse1[]
     }
 
+    @Test
     void testComplexUse2() {
         // tag::testComplexUse2[]
         def xmlWriter = new StringWriter()
@@ -169,6 +175,7 @@ class UserGuideMarkupBuilderTest extends GroovyTestCase {
         // end::testComplexUse2[]
     }
 
+    @Test
     void testDOMToGroovy() {
         // tag::testDOMToGroovy[]
         def songs = """
@@ -204,6 +211,7 @@ class UserGuideMarkupBuilderTest extends GroovyTestCase {
         // end::testDOMToGroovy[]
     }
 
+    @Test
     void testMkp1() {
         // tag::testMkp1[]
         def xmlWriter = new StringWriter()
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideStreamingMarkupBuilderTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideStreamingMarkupBuilderTest.groovy
index b6fe469385..4b39c664aa 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideStreamingMarkupBuilderTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideStreamingMarkupBuilderTest.groovy
@@ -18,13 +18,14 @@
  */
 package groovy.xml
 
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
 
 /**
  * Tests for the Groovy Xml user guide related to StreamingMarkupBuilderTest.
  */
-class UserGuideStreamingMarkupBuilderTest extends GroovyTestCase {
+class UserGuideStreamingMarkupBuilderTest {
 
+    @Test
     void testSimpleExample() {
         // tag::testSimpleExample[]
         def xml = new StreamingMarkupBuilder().bind { // <1>
@@ -51,6 +52,7 @@ class UserGuideStreamingMarkupBuilderTest extends GroovyTestCase {
         // end::testSimpleExample[]
     }
 
+    @Test
     void testMkp() {
         // tag::testMkp[]
         def xml = new StreamingMarkupBuilder().bind {
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideXmlParserTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideXmlParserTest.groovy
index 5626f8d508..96d2ef2fcb 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideXmlParserTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideXmlParserTest.groovy
@@ -19,12 +19,12 @@
 package groovy.xml
 
 import groovy.namespace.QName
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
 
 /**
  * Tests for the Groovy Xml user guide related to XmlParser.
  */
-class UserGuideXmlParserTest extends GroovyTestCase {
+class UserGuideXmlParserTest {
 
     // tag::responseBookXml[]
     def xml = """
@@ -41,6 +41,7 @@ class UserGuideXmlParserTest extends GroovyTestCase {
     """
     // end::responseBookXml[]
 
+    @Test
     void testParseText() {
         // tag::testParseText[]
         def text = '''
@@ -58,6 +59,7 @@ class UserGuideXmlParserTest extends GroovyTestCase {
         // end::testParseText[]
     }
 
+    @Test
     void testAddingNodes1() {
         // tag::testAddingNodes1[]
         def parser = new XmlParser()
@@ -73,6 +75,7 @@ class UserGuideXmlParserTest extends GroovyTestCase {
         // end::testAddingNodes1[]
     }
 
+    @Test
     void testAddingNodes2() {
         // tag::testAddingNodes2[]
         def parser = new XmlParser()
@@ -88,6 +91,7 @@ class UserGuideXmlParserTest extends GroovyTestCase {
         // end::testAddingNodes2[]
     }
 
+    @Test
     void testModifyingNodes1() {
         // tag::testModifyingNodes1[]
         def response = new XmlParser().parseText(xml)
@@ -110,6 +114,7 @@ class UserGuideXmlParserTest extends GroovyTestCase {
         // end::testModifyingNodes1[]
     }
 
+    @Test
     void testSettingAttributes1() {
         // tag::testSettingAttributes1[]
         def parser = new XmlParser()
@@ -121,6 +126,7 @@ class UserGuideXmlParserTest extends GroovyTestCase {
         // end::testSettingAttributes1[]
     }
 
+    @Test
     void testNamedParameters() {
         // tag::testNamedParameters[]
         def parser = new XmlParser(namespaceAware: false, trimWhitespace: true)
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
index 5e473b2c25..0ef5bea0b5 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
@@ -21,9 +21,9 @@
  */
 import groovy.xml.StreamingMarkupBuilder
 import groovy.xml.XmlSlurper
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
 
-class UserGuideXmlSlurperTest extends GroovyTestCase {
+class UserGuideXmlSlurperTest {
 
     // tag::books[]
     static final String books = '''
@@ -52,6 +52,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
     '''
     // end::books[]
 
+    @Test
     void testParseText() {
         // tag::testParseText[]
         def text = '''
@@ -69,6 +70,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
         // end::testParseText[]
     }
 
+    @Test
     void testGettingANodeText() {
         // tag::testGettingANodeText[]
         def response = new XmlSlurper().parseText(books)
@@ -78,6 +80,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
         // end::testGettingANodeText[]
     }
 
+    @Test
     void testGettingAnAttributeText() {
         // tag::testGettingAnAttributeText[]
         def response = new XmlSlurper().parseText(books)
@@ -92,6 +95,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
         // end::testGettingAnAttributeText[]
     }
 
+    @Test
     void testChildren() {
         // tag::testChildren[]
         def response = new XmlSlurper().parseText(books)
@@ -106,6 +110,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
         // end::testChildren[]
     }
 
+    @Test
     void testDepthFirst1() {
         // tag::testDepthFirst1[]
         def response = new XmlSlurper().parseText(books)
@@ -119,6 +124,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
         // end::testDepthFirst1[]
     }
 
+    @Test
     void testDepthFirst2() {
         // tag::testDepthFirst2[]
         def response = new XmlSlurper().parseText(books)
@@ -129,6 +135,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
         // end::testDepthFirst2[]
     }
 
+    @Test
     void testDepthVsBreadth() {
         // tag::testDepthVsBreadth[]
         def response = new XmlSlurper().parseText(books)
@@ -142,6 +149,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
         // end::testDepthVsBreadth[]
     }
 
+    @Test
     void testHelpers() {
         // tag::testHelpers[]
         def response = new XmlSlurper().parseText(books)
@@ -155,6 +163,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
         // end::testHelpers[]
     }
 
+    @Test
     void testModifyingNodes1() {
         // tag::testModifyingNodes1[]
         def response = new XmlSlurper().parseText(books)
@@ -180,6 +189,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
         // end::testModifyingNodes1[]
     }
 
+    @Test
     void testSettingAttributes1() {
         // tag::testSettingAttributes1[]
         def response = new XmlSlurper().parseText(books)
@@ -189,6 +199,7 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
         // end::testSettingAttributes1[]
     }
 
+    @Test
     void testNamedParameters() {
         // tag::testNamedParameters[]
         def slurper = new XmlSlurper(namespaceAware: false, keepIgnorableWhitespace: true)
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy
index 06171eddf2..f2f355a7a4 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy
@@ -18,12 +18,12 @@
  */
 package groovy.xml
 
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
 
 /**
  * Tests for the Groovy Xml user guide related to XmlUtil.
  */
-class UserGuideXmlUtilTest extends GroovyTestCase {
+class UserGuideXmlUtilTest {
 
     // tag::responseBookXml[]
     def xml = """
@@ -40,6 +40,7 @@ class UserGuideXmlUtilTest extends GroovyTestCase {
     """
     // end::responseBookXml[]
 
+    @Test
     void testGettingANode() {
         // tag::testGettingANode[]
         def response = new XmlParser().parseText(xml)
@@ -51,6 +52,7 @@ class UserGuideXmlUtilTest extends GroovyTestCase {
         // end::testGettingANode[]
     }
 
+    @Test
     void testSerializeOptions() {
         // tag::testSerializeOptions[]
         def response = new XmlParser().parseText(xml)
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/FactorySupportTest.java b/subprojects/groovy-xml/src/test/groovy/groovy/xml/FactorySupportTest.java
index 10675cc907..87efd51eda 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/FactorySupportTest.java
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/FactorySupportTest.java
@@ -18,21 +18,27 @@
  */
 package groovy.xml;
 
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
 
 import javax.xml.parsers.ParserConfigurationException;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 
-public class FactorySupportTest extends TestCase {
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class FactorySupportTest {
     private static final PrivilegedActionException PRIVILEGED_ACTION_EXCEPTION = new PrivilegedActionException(new IllegalStateException());
     private static final ParserConfigurationException PARSER_CONFIGURATION_EXCEPTION = new ParserConfigurationException();
 
+    @Test
     public void testCreatesFactories() throws Exception {
         assertNotNull(FactorySupport.createDocumentBuilderFactory());
         assertNotNull(FactorySupport.createSaxParserFactory());
     }
 
+    @Test
     public void testParserConfigurationExceptionNotWrapped() throws ParserConfigurationException {
         try {
             FactorySupport.createFactory(new PrivilegedExceptionAction() {
@@ -46,6 +52,7 @@ public class FactorySupportTest extends TestCase {
         }
     }
 
+    @Test
     public void testOtherExceptionsWrappedAsUnchecked() throws ParserConfigurationException {
         try {
             FactorySupport.createFactory(new PrivilegedExceptionAction() {


(groovy) 02/06: GROOVY-7633: Add constructor with Map for SAXOptions to XmlSlurper (align XmlParser behavior)

Posted by pa...@apache.org.
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

commit 38fc020f6cd6254094d0576a39e94864cf1f99e4
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Apr 13 14:04:43 2026 +1000

    GROOVY-7633: Add constructor with Map for SAXOptions to XmlSlurper (align XmlParser behavior)
---
 .../src/main/java/groovy/xml/XmlParser.java        | 119 +++++++++++++++++----
 .../groovy-xml/src/spec/doc/xml-userguide.adoc     |  48 +++++++++
 .../src/spec/test/UserGuideXmlParserTest.groovy    |   8 ++
 .../src/spec/test/UserGuideXmlSlurperTest.groovy   |   8 ++
 .../test/groovy/groovy/xml/XmlParserTest.groovy    |  26 +++++
 5 files changed, 189 insertions(+), 20 deletions(-)

diff --git a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlParser.java b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlParser.java
index b1afa20275..6937addc59 100644
--- a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlParser.java
+++ b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlParser.java
@@ -75,21 +75,28 @@ public class XmlParser implements ContentHandler {
     private StringBuilder bodyText = new StringBuilder();
     private final List<Node> stack = new ArrayList<Node>();
     private Locator locator;
-    private final XMLReader reader;
+    private XMLReader reader;
     private Node parent;
 
     private boolean trimWhitespace = false;
     private boolean keepIgnorableWhitespace = false;
-    private boolean namespaceAware;
+    private boolean namespaceAware = true;
+    private boolean validating = false;
+    private boolean allowDocTypeDeclaration = false;
 
     /**
      * Creates a non-validating and namespace-aware <code>XmlParser</code> which does not allow DOCTYPE declarations in documents.
+     * <p>
+     * Parser options can be configured via setters before the first parse call:
+     * <pre>
+     * // Using Groovy named parameters:
+     * def parser = new XmlParser(namespaceAware: false, trimWhitespace: true)
+     * </pre>
      *
      * @throws ParserConfigurationException if no parser which satisfies the requested configuration can be created.
      * @throws SAXException for SAX errors.
      */
     public XmlParser() throws ParserConfigurationException, SAXException {
-        this(false, true);
     }
 
     /**
@@ -114,21 +121,43 @@ public class XmlParser implements ContentHandler {
      * @throws SAXException for SAX errors.
      */
     public XmlParser(boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration) throws ParserConfigurationException, SAXException {
+        this.validating = validating;
+        this.namespaceAware = namespaceAware;
+        this.allowDocTypeDeclaration = allowDocTypeDeclaration;
+    }
+
+    public XmlParser(XMLReader reader) {
+        this.reader = reader;
+    }
+
+    public XmlParser(SAXParser parser) throws SAXException {
+        reader = parser.getXMLReader();
+    }
+
+    private void initReader() throws ParserConfigurationException, SAXException {
         SAXParserFactory factory = FactorySupport.createSaxParserFactory();
         factory.setNamespaceAware(namespaceAware);
-        this.namespaceAware = namespaceAware;
         factory.setValidating(validating);
         setFeatureQuietly(factory, XMLConstants.FEATURE_SECURE_PROCESSING, true);
         setFeatureQuietly(factory, "http://apache.org/xml/features/disallow-doctype-decl", !allowDocTypeDeclaration);
         reader = factory.newSAXParser().getXMLReader();
     }
 
-    public XmlParser(XMLReader reader) {
-        this.reader = reader;
+    private XMLReader ensureReader() {
+        try {
+            if (reader == null) {
+                initReader();
+            }
+            return reader;
+        } catch (ParserConfigurationException | SAXException e) {
+            throw new RuntimeException("Failed to initialize XML reader", e);
+        }
     }
 
-    public XmlParser(SAXParser parser) throws SAXException {
-        reader = parser.getXMLReader();
+    private void checkNotInitialized(String property) {
+        if (reader != null) {
+            throw new IllegalStateException(property + " must be set before parsing");
+        }
     }
 
     /**
@@ -304,13 +333,62 @@ public class XmlParser implements ContentHandler {
 
     /**
      * Enable and/or disable namespace handling.
+     * Must be set before the first parse call.
      *
      * @param namespaceAware the new desired value
+     * @throws IllegalStateException if called after parsing has started
      */
     public void setNamespaceAware(boolean namespaceAware) {
+        checkNotInitialized("namespaceAware");
         this.namespaceAware = namespaceAware;
     }
 
+    /**
+     * Determine if the parser validates documents.
+     *
+     * @return true if validation is enabled
+     * @since 6.0.0
+     */
+    public boolean isValidating() {
+        return validating;
+    }
+
+    /**
+     * Enable and/or disable validation.
+     * Must be set before the first parse call.
+     *
+     * @param validating the new desired value
+     * @throws IllegalStateException if called after parsing has started
+     * @since 6.0.0
+     */
+    public void setValidating(boolean validating) {
+        checkNotInitialized("validating");
+        this.validating = validating;
+    }
+
+    /**
+     * Determine if DOCTYPE declarations are allowed.
+     *
+     * @return true if DOCTYPE declarations are allowed
+     * @since 6.0.0
+     */
+    public boolean isAllowDocTypeDeclaration() {
+        return allowDocTypeDeclaration;
+    }
+
+    /**
+     * Enable and/or disable DOCTYPE declaration support.
+     * Must be set before the first parse call.
+     *
+     * @param allowDocTypeDeclaration the new desired value
+     * @throws IllegalStateException if called after parsing has started
+     * @since 6.0.0
+     */
+    public void setAllowDocTypeDeclaration(boolean allowDocTypeDeclaration) {
+        checkNotInitialized("allowDocTypeDeclaration");
+        this.allowDocTypeDeclaration = allowDocTypeDeclaration;
+    }
+
     // Delegated XMLReader methods
     //------------------------------------------------------------------------
 
@@ -318,70 +396,70 @@ public class XmlParser implements ContentHandler {
      * @see org.xml.sax.XMLReader#getDTDHandler()
      */
     public DTDHandler getDTDHandler() {
-        return this.reader.getDTDHandler();
+        return ensureReader().getDTDHandler();
     }
 
     /* (non-Javadoc)
      * @see org.xml.sax.XMLReader#getEntityResolver()
      */
     public EntityResolver getEntityResolver() {
-        return this.reader.getEntityResolver();
+        return ensureReader().getEntityResolver();
     }
 
     /* (non-Javadoc)
      * @see org.xml.sax.XMLReader#getErrorHandler()
      */
     public ErrorHandler getErrorHandler() {
-        return this.reader.getErrorHandler();
+        return ensureReader().getErrorHandler();
     }
 
     /* (non-Javadoc)
      * @see org.xml.sax.XMLReader#getFeature(java.lang.String)
      */
     public boolean getFeature(final String uri) throws SAXNotRecognizedException, SAXNotSupportedException {
-        return this.reader.getFeature(uri);
+        return ensureReader().getFeature(uri);
     }
 
     /* (non-Javadoc)
      * @see org.xml.sax.XMLReader#getProperty(java.lang.String)
      */
     public Object getProperty(final String uri) throws SAXNotRecognizedException, SAXNotSupportedException {
-        return this.reader.getProperty(uri);
+        return ensureReader().getProperty(uri);
     }
 
     /* (non-Javadoc)
      * @see org.xml.sax.XMLReader#setDTDHandler(org.xml.sax.DTDHandler)
      */
     public void setDTDHandler(final DTDHandler dtdHandler) {
-        this.reader.setDTDHandler(dtdHandler);
+        ensureReader().setDTDHandler(dtdHandler);
     }
 
     /* (non-Javadoc)
      * @see org.xml.sax.XMLReader#setEntityResolver(org.xml.sax.EntityResolver)
      */
     public void setEntityResolver(final EntityResolver entityResolver) {
-        this.reader.setEntityResolver(entityResolver);
+        ensureReader().setEntityResolver(entityResolver);
     }
 
     /* (non-Javadoc)
      * @see org.xml.sax.XMLReader#setErrorHandler(org.xml.sax.ErrorHandler)
      */
     public void setErrorHandler(final ErrorHandler errorHandler) {
-        this.reader.setErrorHandler(errorHandler);
+        ensureReader().setErrorHandler(errorHandler);
     }
 
     /* (non-Javadoc)
      * @see org.xml.sax.XMLReader#setFeature(java.lang.String, boolean)
      */
     public void setFeature(final String uri, final boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
-        this.reader.setFeature(uri, value);
+        ensureReader().setFeature(uri, value);
     }
 
     /* (non-Javadoc)
      * @see org.xml.sax.XMLReader#setProperty(java.lang.String, java.lang.Object)
      */
     public void setProperty(final String uri, final Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
-        reader.setProperty(uri, value);
+        ensureReader().setProperty(uri, value);
     }
 
     // ContentHandler interface
@@ -464,8 +542,9 @@ public class XmlParser implements ContentHandler {
     // Implementation methods
     //-------------------------------------------------------------------------
     protected XMLReader getXMLReader() {
-        reader.setContentHandler(this);
-        return reader;
+        XMLReader r = ensureReader();
+        r.setContentHandler(this);
+        return r;
     }
 
     protected void addTextToNode() {
diff --git a/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc b/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
index 056567b3d1..ace9bc78ee 100644
--- a/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
+++ b/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
@@ -95,6 +95,54 @@ GPath expressions with them are the same (both use `breadthFirst()` and
 `depthFirst()` expressions). So I guess it depends on the write/read
 frequency.
 
+=== Parser configuration with named parameters
+
+Both `XmlParser` and `XmlSlurper` support Groovy's named parameter syntax
+for configuration, making it easy to set options without remembering
+positional boolean argument order:
+
+[source,groovy]
+.XmlSlurper
+----
+include::../test/UserGuideXmlSlurperTest.groovy[tags=testNamedParameters,indent=0]
+----
+
+[source,groovy]
+.XmlParser
+----
+include::../test/UserGuideXmlParserTest.groovy[tags=testNamedParameters,indent=0]
+----
+
+Available options for both parsers:
+
+[cols="1,3,1",options="header"]
+|===
+| Option | Description | Default
+
+| `namespaceAware`
+| Enable XML namespace handling
+| `true`
+
+| `validating`
+| Validate documents against a DTD
+| `false`
+
+| `allowDocTypeDeclaration`
+| Allow DOCTYPE declarations in documents
+| `false`
+
+| `keepIgnorableWhitespace`
+| Preserve whitespace before elements
+| `false`
+|===
+
+`XmlParser` additionally supports `trimWhitespace` (default `false`)
+to trim whitespace from element text content.
+
+NOTE: Options that affect the underlying SAX parser (`namespaceAware`,
+`validating`, `allowDocTypeDeclaration`) must be set before the first
+parse call. Setting them afterwards throws an `IllegalStateException`.
+
 === DOMCategory
 
 There is another way of parsing XML documents with Groovy with the
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideXmlParserTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideXmlParserTest.groovy
index be06ac1fbd..5626f8d508 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideXmlParserTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideXmlParserTest.groovy
@@ -121,4 +121,12 @@ class UserGuideXmlParserTest extends GroovyTestCase {
         // end::testSettingAttributes1[]
     }
 
+    void testNamedParameters() {
+        // tag::testNamedParameters[]
+        def parser = new XmlParser(namespaceAware: false, trimWhitespace: true)
+        def result = parser.parseText('<root><item>value</item></root>')
+        assert result.item[0].text() == 'value'
+        // end::testNamedParameters[]
+    }
+
 }
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
index e91aad8a63..5e473b2c25 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideXmlSlurperTest.groovy
@@ -189,4 +189,12 @@ class UserGuideXmlSlurperTest extends GroovyTestCase {
         // end::testSettingAttributes1[]
     }
 
+    void testNamedParameters() {
+        // tag::testNamedParameters[]
+        def slurper = new XmlSlurper(namespaceAware: false, keepIgnorableWhitespace: true)
+        def result = slurper.parseText('<root><item>value</item></root>')
+        assert result.item.text() == 'value'
+        // end::testNamedParameters[]
+    }
+
 }
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlParserTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlParserTest.groovy
index 52745fc8d5..dc32462cf7 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlParserTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlParserTest.groovy
@@ -343,4 +343,30 @@ p() {
         def result = writer.toString()
         assert result == '<root><foo bar="baz"><inner/></foo><foo bar="zab"><inner>text</inner></foo></root>'
     }
+
+    @Test
+    void testNamedParameterConstruction() {
+        def xml = '<root><item name="test">value</item></root>'
+
+        // named parameters via setters
+        def parser = new XmlParser(namespaceAware: false, trimWhitespace: true)
+        def result = parser.parseText(xml)
+        assert result.item[0].text() == 'value'
+        assert result.item[0].@name == 'test'
+
+        // setter after boolean constructor, before first parse
+        def parser2 = new XmlParser(false, false)
+        parser2.allowDocTypeDeclaration = true
+        assert parser2.parseText(xml).item[0].text() == 'value'
+
+        // setter after parse should fail
+        def parser3 = new XmlParser()
+        parser3.parseText(xml)
+        try {
+            parser3.namespaceAware = false
+            assert false, 'should have thrown'
+        } catch (IllegalStateException e) {
+            assert e.message.contains('must be set before parsing')
+        }
+    }
 }


(groovy) 03/06: GROOVY-7571: XmlUtil should allow user to specify a character encoding when serializing

Posted by pa...@apache.org.
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

commit 06c645979f4ae9bc42a2b5462d28af42cfe0781b
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Apr 13 14:25:58 2026 +1000

    GROOVY-7571: XmlUtil should allow user to specify a character encoding when serializing
---
 .../src/main/java/groovy/xml/XmlUtil.java          | 159 ++++++++++++++++++++-
 .../groovy-xml/src/spec/doc/xml-userguide.adoc     |   9 ++
 .../src/spec/test/UserGuideXmlUtilTest.groovy      |  19 +++
 3 files changed, 182 insertions(+), 5 deletions(-)

diff --git a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
index f8530d957c..21304f80e2 100644
--- a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
+++ b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
@@ -55,7 +55,7 @@ import java.io.PrintWriter;
 import java.io.StringReader;
 import java.io.Writer;
 import java.net.URL;
-import java.nio.charset.StandardCharsets;
+import java.nio.charset.Charset;
 
 /**
  * Used for pretty printing XML content and other XML related utilities.
@@ -283,6 +283,138 @@ public class XmlUtil {
         serialize(asStreamSource(xmlString), w, allowDocTypeDeclaration);
     }
 
+    // --- SerializeOptions overloads ---
+
+    /**
+     * Return a pretty String version of the Element using the specified options.
+     *
+     * @param element the Element to serialize
+     * @param options the serialization options
+     * @return the pretty String representation of the Element
+     * @since 6.0.0
+     */
+    public static String serialize(Element element, SerializeOptions options) {
+        Writer sw = new StringBuilderWriter();
+        serialize(new DOMSource(element), sw, options);
+        return sw.toString();
+    }
+
+    /**
+     * Write a pretty version of the Element to the OutputStream using the specified options.
+     *
+     * @param element the Element to serialize
+     * @param os      the OutputStream to write to
+     * @param options the serialization options
+     * @since 6.0.0
+     */
+    public static void serialize(Element element, OutputStream os, SerializeOptions options) {
+        serialize(new DOMSource(element), os, options);
+    }
+
+    /**
+     * Return a pretty String version of the Node using the specified options.
+     *
+     * @param node    the Node to serialize
+     * @param options the serialization options
+     * @return the pretty String representation of the Node
+     * @since 6.0.0
+     */
+    public static String serialize(Node node, SerializeOptions options) {
+        Writer sw = new StringBuilderWriter();
+        serialize(asStreamSource(asString(node)), sw, options);
+        return sw.toString();
+    }
+
+    /**
+     * Write a pretty version of the Node to the OutputStream using the specified options.
+     *
+     * @param node    the Node to serialize
+     * @param os      the OutputStream to write to
+     * @param options the serialization options
+     * @since 6.0.0
+     */
+    public static void serialize(Node node, OutputStream os, SerializeOptions options) {
+        serialize(asStreamSource(asString(node)), os, options);
+    }
+
+    /**
+     * Return a pretty String version of the GPathResult using the specified options.
+     *
+     * @param node    a GPathResult to serialize to a String
+     * @param options the serialization options
+     * @return the pretty String representation of the GPathResult
+     * @since 6.0.0
+     */
+    public static String serialize(GPathResult node, SerializeOptions options) {
+        Writer sw = new StringBuilderWriter();
+        serialize(asStreamSource(asString(node)), sw, options);
+        return sw.toString();
+    }
+
+    /**
+     * Write a pretty version of the GPathResult to the OutputStream using the specified options.
+     *
+     * @param node    a GPathResult to serialize
+     * @param os      the OutputStream to write to
+     * @param options the serialization options
+     * @since 6.0.0
+     */
+    public static void serialize(GPathResult node, OutputStream os, SerializeOptions options) {
+        serialize(asStreamSource(asString(node)), os, options);
+    }
+
+    /**
+     * Return a pretty String version of the XML content produced by the Writable using the specified options.
+     *
+     * @param writable the Writable to serialize
+     * @param options  the serialization options
+     * @return the pretty String representation of the content from the Writable
+     * @since 6.0.0
+     */
+    public static String serialize(Writable writable, SerializeOptions options) {
+        Writer sw = new StringBuilderWriter();
+        serialize(asStreamSource(asString(writable)), sw, options);
+        return sw.toString();
+    }
+
+    /**
+     * Write a pretty version of the XML content produced by the Writable to the OutputStream using the specified options.
+     *
+     * @param writable the Writable to serialize
+     * @param os       the OutputStream to write to
+     * @param options  the serialization options
+     * @since 6.0.0
+     */
+    public static void serialize(Writable writable, OutputStream os, SerializeOptions options) {
+        serialize(asStreamSource(asString(writable)), os, options);
+    }
+
+    /**
+     * Return a pretty version of the XML content contained in the given String using the specified options.
+     *
+     * @param xmlString the String to serialize
+     * @param options   the serialization options
+     * @return the pretty String representation of the original content
+     * @since 6.0.0
+     */
+    public static String serialize(String xmlString, SerializeOptions options) {
+        Writer sw = new StringBuilderWriter();
+        serialize(asStreamSource(xmlString), sw, options);
+        return sw.toString();
+    }
+
+    /**
+     * Write a pretty version of the given XML string to the OutputStream using the specified options.
+     *
+     * @param xmlString the String to serialize
+     * @param os        the OutputStream to write to
+     * @param options   the serialization options
+     * @since 6.0.0
+     */
+    public static void serialize(String xmlString, OutputStream os, SerializeOptions options) {
+        serialize(asStreamSource(xmlString), os, options);
+    }
+
     /**
      * Factory method to create a SAXParser configured to validate according to a particular schema language and
      * optionally providing the schema sources to validate with.
@@ -526,22 +658,39 @@ public class XmlUtil {
     }
 
     private static void serialize(Source source, OutputStream os, boolean allowDocTypeDeclaration) {
-        serialize(source, new StreamResult(new OutputStreamWriter(os, StandardCharsets.UTF_8)), allowDocTypeDeclaration);
+        serialize(source, os, SerializeOptions.DEFAULT);
+    }
+
+    private static void serialize(Source source, OutputStream os, SerializeOptions options) {
+        serialize(source, new StreamResult(new OutputStreamWriter(os, options.getCharset())), options);
     }
 
     private static void serialize(Source source, Writer w, boolean allowDocTypeDeclaration) {
-        serialize(source, new StreamResult(w), allowDocTypeDeclaration);
+        SerializeOptions options = new SerializeOptions();
+        options.setAllowDocTypeDeclaration(allowDocTypeDeclaration);
+        serialize(source, new StreamResult(w), options);
+    }
+
+    private static void serialize(Source source, Writer w, SerializeOptions options) {
+        serialize(source, new StreamResult(w), options);
     }
 
     private static void serialize(Source source, StreamResult target, boolean allowDocTypeDeclaration) {
+        SerializeOptions options = new SerializeOptions();
+        options.setAllowDocTypeDeclaration(allowDocTypeDeclaration);
+        serialize(source, target, options);
+    }
+
+    private static void serialize(Source source, StreamResult target, SerializeOptions options) {
         TransformerFactory factory = TransformerFactory.newInstance();
-        setFeatureQuietly(factory, "http://apache.org/xml/features/disallow-doctype-decl", !allowDocTypeDeclaration);
-        setIndent(factory, 2);
+        setFeatureQuietly(factory, "http://apache.org/xml/features/disallow-doctype-decl", !options.isAllowDocTypeDeclaration());
+        setIndent(factory, options.getIndent());
         try {
             Transformer transformer = factory.newTransformer();
             transformer.setOutputProperty(OutputKeys.INDENT, "yes");
             transformer.setOutputProperty(OutputKeys.METHOD, "xml");
             transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml");
+            transformer.setOutputProperty(OutputKeys.ENCODING, options.getEncoding());
             transformer.transform(source, target);
         }
         catch (TransformerException e) {
diff --git a/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc b/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
index ace9bc78ee..23b596e63a 100644
--- a/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
+++ b/subprojects/groovy-xml/src/spec/doc/xml-userguide.adoc
@@ -641,3 +641,12 @@ methods to serialize the xml fragment from several type of sources
 include::../test/UserGuideXmlUtilTest.groovy[tags=testGettingANode,indent=0]
 ----
 
+Serialization can be customized using `SerializeOptions` to control
+encoding, indentation, and DOCTYPE handling:
+
+[source,groovy]
+.Customizing serialization
+----
+include::../test/UserGuideXmlUtilTest.groovy[tags=testSerializeOptions,indent=0]
+----
+
diff --git a/subprojects/groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy b/subprojects/groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy
index 77aff2d41a..06171eddf2 100644
--- a/subprojects/groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy
+++ b/subprojects/groovy-xml/src/spec/test/UserGuideXmlUtilTest.groovy
@@ -51,4 +51,23 @@ class UserGuideXmlUtilTest extends GroovyTestCase {
         // end::testGettingANode[]
     }
 
+    void testSerializeOptions() {
+        // tag::testSerializeOptions[]
+        def response = new XmlParser().parseText(xml)
+
+        // Custom encoding
+        def latin1 = XmlUtil.serialize(response, new SerializeOptions(encoding: 'ISO-8859-1'))
+        assert latin1.contains('encoding="ISO-8859-1"')
+
+        // Custom indent (4 spaces instead of default 2)
+        def wideIndent = XmlUtil.serialize(response, new SerializeOptions(indent: 4))
+        assert wideIndent.contains('    <value>')
+
+        // Multiple options
+        def custom = XmlUtil.serialize(response, new SerializeOptions(encoding: 'ISO-8859-1', indent: 4))
+        assert custom.contains('encoding="ISO-8859-1"')
+        assert custom.contains('    <value>')
+        // end::testSerializeOptions[]
+    }
+
 }


(groovy) 05/06: minor refactor: junit5 tests can have slightly cleaner names

Posted by pa...@apache.org.
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

commit cd7c7cb630f38c47b4e4c5f882638634f53bc0d3
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Apr 13 14:42:11 2026 +1000

    minor refactor: junit5 tests can have slightly cleaner names
---
 .../src/test/groovy/groovy/xml/DOMTest.groovy      |  4 +--
 .../test/groovy/groovy/xml/FactorySupportTest.java |  6 ++--
 .../groovy/groovy/xml/MarkupWithWriterTest.groovy  |  4 +--
 .../groovy/xml/NamespaceNodeGPathTest.groovy       |  2 +-
 .../groovy/groovy/xml/NamespaceNodeTest.groovy     |  8 ++---
 .../groovy/groovy/xml/NavigationXmlTest.groovy     |  6 ++--
 .../src/test/groovy/groovy/xml/SAXTest.groovy      |  4 +--
 .../groovy/xml/SafeNumberXmlParserTest.groovy      |  2 +-
 .../groovy/xml/SafeNumberXmlSlurperTest.groovy     |  2 +-
 .../test/groovy/groovy/xml/StaxBuilderTest.groovy  |  4 +--
 .../groovy/xml/StreamingSAXBuilderTest.groovy      |  6 ++--
 .../groovy/xml/UseMarkupWithWriterScript.groovy    |  2 +-
 .../test/groovy/groovy/xml/VerboseDOMTest.groovy   |  4 +--
 .../groovy/groovy/xml/XmlNodePrinterTest.groovy    | 34 +++++++++----------
 .../groovy/groovy/xml/XmlParserFactoryTest.groovy  |  2 +-
 .../test/groovy/groovy/xml/XmlParserTest.groovy    | 34 +++++++++----------
 .../groovy/groovy/xml/XmlSlurperFactoryTest.groovy |  2 +-
 .../test/groovy/groovy/xml/XmlSlurperTest.groovy   | 38 +++++++++++-----------
 .../src/test/groovy/groovy/xml/XmlUtilTest.groovy  |  8 ++---
 .../groovy/xml/benchmark/BuilderPerfTest.groovy    |  2 +-
 .../groovy/groovy/xml/bugs/Groovy249_Bug.groovy    |  4 +--
 .../groovy/groovy/xml/bugs/Groovy593_Bug.groovy    |  2 +-
 .../groovy/groovy/xml/bugs/Groovy_2473Bug.groovy   |  2 +-
 .../groovy/groovy/xml/bugs/MarkupInScriptBug.java  |  2 +-
 .../src/test/groovy/groovy/xml/bugs/SeansBug.java  |  4 +--
 .../groovy/groovy/xml/bugs/StaticMarkupBug.groovy  |  2 +-
 .../groovy/groovy/xml/bugs/TedsClosureBug.groovy   |  2 +-
 .../groovy/groovy/xml/dom/DOMCategoryTest.groovy   | 28 ++++++++--------
 .../src/test/groovy/groovy/xml/dom/DOMTest.groovy  | 14 ++++----
 .../groovy/groovy/xml/dom/NamespaceDOMTest.groovy  |  6 ++--
 .../apache/groovy/xml/tools/DomToGroovyTest.groovy |  4 +--
 31 files changed, 122 insertions(+), 122 deletions(-)

diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/DOMTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/DOMTest.groovy
index a56eba0dbd..c7ec6316f8 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/DOMTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/DOMTest.groovy
@@ -27,7 +27,7 @@ import org.junit.jupiter.api.Test
 final class DOMTest extends TestXmlSupport {
 
     @Test
-    void testSmallTree() {
+    void smallTree() {
         def b = DOMBuilder.newInstance()
 
         def root = b.root1(a:5, b:7) {
@@ -42,7 +42,7 @@ final class DOMTest extends TestXmlSupport {
     }
 
     @Test
-    void testTree() {
+    void tree() {
         def b = DOMBuilder.newInstance()
 
         def root = b.root2(a:5, b:7) {
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/FactorySupportTest.java b/subprojects/groovy-xml/src/test/groovy/groovy/xml/FactorySupportTest.java
index 87efd51eda..01c4ba9ce5 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/FactorySupportTest.java
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/FactorySupportTest.java
@@ -33,13 +33,13 @@ public class FactorySupportTest {
     private static final ParserConfigurationException PARSER_CONFIGURATION_EXCEPTION = new ParserConfigurationException();
 
     @Test
-    public void testCreatesFactories() throws Exception {
+    public void createsFactories() throws Exception {
         assertNotNull(FactorySupport.createDocumentBuilderFactory());
         assertNotNull(FactorySupport.createSaxParserFactory());
     }
 
     @Test
-    public void testParserConfigurationExceptionNotWrapped() throws ParserConfigurationException {
+    public void parserConfigurationExceptionNotWrapped() throws ParserConfigurationException {
         try {
             FactorySupport.createFactory(new PrivilegedExceptionAction() {
                 public Object run() throws Exception {
@@ -53,7 +53,7 @@ public class FactorySupportTest {
     }
 
     @Test
-    public void testOtherExceptionsWrappedAsUnchecked() throws ParserConfigurationException {
+    public void otherExceptionsWrappedAsUnchecked() throws ParserConfigurationException {
         try {
             FactorySupport.createFactory(new PrivilegedExceptionAction() {
                 public Object run() throws Exception {
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/MarkupWithWriterTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/MarkupWithWriterTest.groovy
index 6c861b6c99..dabbc08547 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/MarkupWithWriterTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/MarkupWithWriterTest.groovy
@@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals
 final class MarkupWithWriterTest extends TestXmlSupport {
 
     @Test
-    void testSmallTreeWithStringWriter() {
+    void smallTreeWithStringWriter() {
         def writer = new java.io.StringWriter()
         def b = new MarkupBuilder(writer)
 
@@ -45,7 +45,7 @@ final class MarkupWithWriterTest extends TestXmlSupport {
     }
 
     @Test
-    void testWriterUseInScriptFile() {
+    void writerUseInScriptFile() {
         assertScriptFile 'src/test/groovy/groovy/xml/UseMarkupWithWriterScript.groovy'
     }
 }
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeGPathTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeGPathTest.groovy
index 15061719d4..fe80a2c2cb 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeGPathTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeGPathTest.groovy
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test
 final class NamespaceNodeGPathTest extends TestXmlSupport {
 
     @Test
-    void testTree() {
+    void tree() {
         Node root = new XmlParser().parseText("""
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <xsd:annotation xsd:cheese="Edam">
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeTest.groovy
index 6a26eccf85..f9b45ceb24 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeTest.groovy
@@ -27,7 +27,7 @@ import org.junit.jupiter.api.Test
 final class NamespaceNodeTest extends TestXmlSupport {
 
     @Test
-    void testNodeBuilderWithNamespace() {
+    void nodeBuilderWithNamespace() {
         def n = new Namespace('http://foo/bar')
         def builder = NamespaceBuilder.newInstance(new NodeBuilder(), n.uri)
         def result = builder.outer(id: "3") {
@@ -39,7 +39,7 @@ final class NamespaceNodeTest extends TestXmlSupport {
     }
 
     @Test
-    void testTree() {
+    void tree() {
         def builder = NodeBuilder.newInstance()
         def xmlns = new NamespaceBuilder(builder)
         def xsd = xmlns.namespace('http://www.w3.org/2001/XMLSchema', 'xsd')
@@ -88,7 +88,7 @@ final class NamespaceNodeTest extends TestXmlSupport {
     }
 
     @Test
-    void testNodeBuilderWithImplicitNamespace() {
+    void nodeBuilderWithImplicitNamespace() {
         def n = new Namespace('http://foo/bar')
         def builder = NamespaceBuilder.newInstance(new NodeBuilder(), n.uri)
 
@@ -112,7 +112,7 @@ final class NamespaceNodeTest extends TestXmlSupport {
     }
 
     @Test
-    void testNamespaceBuilderWithoutNamespace() {
+    void namespaceBuilderWithoutNamespace() {
         def builder = NamespaceBuilder.newInstance(new NodeBuilder())
         def result = builder.outer(id: "3") {
             inner(name: "foo")
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/NavigationXmlTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/NavigationXmlTest.groovy
index 26b8180ad6..87d339fc32 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/NavigationXmlTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/NavigationXmlTest.groovy
@@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test
  */
 class NavigationXmlTest {
     @Test
-    void testPrePostOrder() {
+    void prePostOrder() {
         def root = createTreeFromXmlParser()
         def combos = [[false, true], ['depthFirst', 'breadthFirst']].combinations()
         def actual = combos.collect{ preorder, type ->
@@ -44,7 +44,7 @@ class NavigationXmlTest {
     }
 
     @Test
-    void testPrePostOrderWithClosure() {
+    void prePostOrderWithClosure() {
         def root = createTreeFromXmlParser()
         def combos = [[false, true], ['depthFirst', 'breadthFirst']].combinations()
         def actual = combos.collect{ preorder, type ->
@@ -62,7 +62,7 @@ class NavigationXmlTest {
     }
 
     @Test
-    void testLevelWithClosure() {
+    void levelWithClosure() {
         def root = createTreeFromXmlParser()
         def result = [:].withDefault { [] }
         root.depthFirst { node, index ->
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/SAXTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/SAXTest.groovy
index 80aa313fbe..2c661e96d4 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/SAXTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/SAXTest.groovy
@@ -27,7 +27,7 @@ import org.junit.jupiter.api.Test
 final class SAXTest extends TestXmlSupport {
 
     @Test
-    void testSmallTree() {
+    void smallTree() {
         def b = createSAXBuilder()
 
         def root = b.root1(a:5, b:7) {
@@ -38,7 +38,7 @@ final class SAXTest extends TestXmlSupport {
     }
 
     @Test
-    void testTree() {
+    void tree() {
         def b = createSAXBuilder()
 
         def root = b.root2(a:5, b:7) {
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/SafeNumberXmlParserTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/SafeNumberXmlParserTest.groovy
index bacd6599a6..4baf146650 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/SafeNumberXmlParserTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/SafeNumberXmlParserTest.groovy
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test
 class SafeNumberXmlParserTest {
 
     @Test
-    void testSafetyWhenConvertingToNumbers() {
+    void safetyWhenConvertingToNumbers() {
         def xmlText = '''
                 <someNumberValues>
                 <someBigDecimal>123.4</someBigDecimal>
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/SafeNumberXmlSlurperTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/SafeNumberXmlSlurperTest.groovy
index dde1368ba6..06fb69a4e1 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/SafeNumberXmlSlurperTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/SafeNumberXmlSlurperTest.groovy
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test
 class SafeNumberXmlSlurperTest {
 
     @Test
-    void testSafetyWhenConvertingToNumbers() {
+    void safetyWhenConvertingToNumbers() {
         def xmlText = '''
                 <someNumberValues>
                 <someBigDecimal>123.4</someBigDecimal>
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/StaxBuilderTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/StaxBuilderTest.groovy
index 11ca94b93d..ab7bcbdacd 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/StaxBuilderTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/StaxBuilderTest.groovy
@@ -32,7 +32,7 @@ import javax.xml.stream.XMLOutputFactory
 class StaxBuilderTest {
 
     @Test
-    void testJava6() {
+    void java6() {
         def factory = XMLOutputFactory.newInstance()
         def writer = new StringWriter()
         def builder = new StaxBuilder(factory.createXMLStreamWriter(writer))
@@ -48,7 +48,7 @@ class StaxBuilderTest {
     }
 
 //    @Grab('org.codehaus.jettison:jettison:1.2')
-//    void testJettison() {
+//    void jettison() {
 //        def conv = new MappedNamespaceConvention()
 //        def writer = new StringWriter()
 //        def mappedWriter = new MappedXMLStreamWriter(conv, writer)
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/StreamingSAXBuilderTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/StreamingSAXBuilderTest.groovy
index 9fe3deaea3..753c17103e 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/StreamingSAXBuilderTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/StreamingSAXBuilderTest.groovy
@@ -29,7 +29,7 @@ import javax.xml.transform.stream.StreamResult
 class StreamingSAXBuilderTest {
 
     @Test
-    void testDefaultSerialization() {
+    void defaultSerialization() {
         def handler = TransformerFactory.newInstance().newTransformerHandler()
         def outstream = new ByteArrayOutputStream()
         handler.setResult(new StreamResult(outstream))
@@ -48,7 +48,7 @@ class StreamingSAXBuilderTest {
     }
 
     @Test
-    void testDefaultSerializationNamespaces() {
+    void defaultSerializationNamespaces() {
         def handler = TransformerFactory.newInstance().newTransformerHandler()
         def outstream = new ByteArrayOutputStream()
         handler.setResult(new StreamResult(outstream))
@@ -69,7 +69,7 @@ class StreamingSAXBuilderTest {
     }
 
     @Test
-    void testCustomHandler() {
+    void customHandler() {
         def visited = []
         def handler = [
                 startDocument: {->
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/UseMarkupWithWriterScript.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/UseMarkupWithWriterScript.groovy
index 00f03b6377..1f62fda8ab 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/UseMarkupWithWriterScript.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/UseMarkupWithWriterScript.groovy
@@ -18,7 +18,7 @@
  */
 package groovy.xml
 
-// used by MarkupWithWriterTest.testWriterUseInScriptFile
+// used by MarkupWithWriterTest.writerUseInScriptFile
 
 writer = new StringWriter()
 b = new MarkupBuilder(writer)
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/VerboseDOMTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/VerboseDOMTest.groovy
index 3c9068892c..7c6aabf08c 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/VerboseDOMTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/VerboseDOMTest.groovy
@@ -27,7 +27,7 @@ import org.junit.jupiter.api.Test
 final class VerboseDOMTest extends TestXmlSupport {
 
     @Test
-    void testSmallTree() {
+    void smallTree() {
         def b = DOMBuilder.newInstance()
 
         def root = b.root1(['a':5, 'b':7], {->
@@ -42,7 +42,7 @@ final class VerboseDOMTest extends TestXmlSupport {
     }
 
     @Test
-    void testTree() {
+    void tree() {
         def b = DOMBuilder.newInstance()
 
         def root = b.root2(['a':5, 'b':7], {
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlNodePrinterTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlNodePrinterTest.groovy
index a588e11273..c1d7d0ce74 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlNodePrinterTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlNodePrinterTest.groovy
@@ -104,12 +104,12 @@ class XmlNodePrinterTest {
     }
 
     @Test
-    void testNamespacesDefault() {
+    void namespacesDefault() {
         checkRoundtrip namespaceInput, namespaceInput
     }
 
     @Test
-    void testNamespacesPreserving() {
+    void namespacesPreserving() {
         parser.trimWhitespace = false
         parser.keepIgnorableWhitespace = true
         setUpNoindentingPrinter()
@@ -117,25 +117,25 @@ class XmlNodePrinterTest {
     }
 
     @Test
-    void testNamespacesDisabledOnParsing() {
+    void namespacesDisabledOnParsing() {
         parser = new XmlParser(false, false)
         parser.trimWhitespace = true
         checkRoundtrip namespaceInput, namespaceInput
     }
 
     @Test
-    void testNamespacesDisabledOnPrinting() {
+    void namespacesDisabledOnPrinting() {
         printer.namespaceAware = false
         checkRoundtrip namespaceInput, noNamespaceInputVerbose
     }
 
     @Test
-    void testWithoutNamespacesVerboseInDefaultOut() {
+    void withoutNamespacesVerboseInDefaultOut() {
         checkRoundtrip noNamespaceInputVerbose, noNamespaceInputVerbose
     }
 
     @Test
-    void testWithoutNamespacesVerbosePreserving() {
+    void withoutNamespacesVerbosePreserving() {
         parser.trimWhitespace = false
         parser.keepIgnorableWhitespace = true
         setUpNoindentingPrinter()
@@ -143,64 +143,64 @@ class XmlNodePrinterTest {
     }
 
     @Test
-    void testWithoutNamespacesVerboseInPreserveOut() {
+    void withoutNamespacesVerboseInPreserveOut() {
         printer.preserveWhitespace = true
         checkRoundtrip noNamespaceInputVerbose, noNamespaceInputCompact
     }
 
     @Test
-    void testWithoutNamespacesCompactInPreserveOut() {
+    void withoutNamespacesCompactInPreserveOut() {
         printer.preserveWhitespace = true
         checkRoundtrip noNamespaceInputCompact, noNamespaceInputCompact
     }
 
     @Test
-    void testNoExpandOfEmptyElements() {
+    void noExpandOfEmptyElements() {
         checkRoundtrip emptyTagExpanded, emptyTagCompact
     }
 
     @Test
-    void testExpandEmptyElements() {
+    void expandEmptyElements() {
         printer.expandEmptyElements = true
         checkRoundtrip emptyTagExpanded, emptyTagExpanded
     }
 
     @Test
-    void testWithoutNamespacesCompactInDefaultOut() {
+    void withoutNamespacesCompactInDefaultOut() {
         checkRoundtrip noNamespaceInputCompact, noNamespaceInputVerbose
     }
 
     @Test
-    void testAttributeWithQuot() {
+    void attributeWithQuot() {
         printer = new XmlNodePrinter(pw, "  ", "\"")
         checkRoundtrip attributeInput, attributeExpectedOutputQuot
     }
 
     @Test
-    void testAttributeWithApos() {
+    void attributeWithApos() {
         printer = new XmlNodePrinter(pw, "  ", "'")
         checkRoundtrip attributeInput, attributeExpectedOutputApos
     }
 
     @Test
-    void testAttributeWithNewline() {
+    void attributeWithNewline() {
         checkRoundtrip attributeWithNewlineInput, attributeWithNewlineExpectedOutput
     }
 
     @Test
-    void testContentWithSpecialSymbolsApos() {
+    void contentWithSpecialSymbolsApos() {
         printer = new XmlNodePrinter(pw, "  ", "'")
         checkRoundtrip tagWithSpecialChars, tagWithSpecialChars
     }
 
     @Test
-    void testContentWithSpecialSymbolsQuot() {
+    void contentWithSpecialSymbolsQuot() {
         printer = new XmlNodePrinter(pw, "  ", "\"")
         checkRoundtrip tagWithSpecialChars, tagWithSpecialChars
     }
 
     @Test
-    void testAttributeWithNamespaceInput() {
+    void attributeWithNamespaceInput() {
         checkRoundtrip attributeWithNamespaceInput, attributeWithNamespaceInput
     }
 
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlParserFactoryTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlParserFactoryTest.groovy
index 211dbafb1e..2ebc987c99 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlParserFactoryTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlParserFactoryTest.groovy
@@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test
 
 class XmlParserFactoryTest {
     @Test
-    void testCreateParser() {
+    void createParser() {
         def xml = '<root><old/></root>'
         def parser = XmlParserFactory.newParser()
         def root = parser.parseText(xml)
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlParserTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlParserTest.groovy
index dc32462cf7..1096cb6947 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlParserTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlParserTest.groovy
@@ -55,7 +55,7 @@ class XmlParserTest {
 """
 
     @Test
-    void testNodePrinter() {
+    void nodePrinter() {
         def text = """
 <p>Please read the <a href="index.html">Home</a> page</p>
 """
@@ -76,7 +76,7 @@ p() {
     }
 
     @Test
-    void testXmlNodePrinter() {
+    void xmlNodePrinter() {
         def text = """
 <p>Please read the <a href="index.html">Home</a> page</p>
 """
@@ -97,7 +97,7 @@ p() {
     }
 
     @Test
-    void testXmlNodePrinterNamespaces() {
+    void xmlNodePrinterNamespaces() {
         def html = new XmlParser(trimWhitespace: true).parseText(bookXml)
         StringWriter sw = new StringWriter()
         new XmlNodePrinter(new PrintWriter(sw)).print(html)
@@ -178,7 +178,7 @@ p() {
     }
 
     @Test
-    void testNamespaceGPath() {
+    void namespaceGPath() {
         def anyName = new QName("*", "*")
         def anyHtml = new QName("http://www.w3.org/HTML/1998/html4", "*")
         def anyTitle = new QName("*", "title")
@@ -205,7 +205,7 @@ p() {
     }
 
     @Test
-    void testElement() {
+    void element() {
         GpathSyntaxTestSupport.checkUpdateElementValue(getRoot)
         GpathSyntaxTestSupport.checkElement(getRoot)
         GpathSyntaxTestSupport.checkFindElement(getRoot)
@@ -216,46 +216,46 @@ p() {
     }
 
     @Test
-    void testAttribute() {
+    void attribute() {
         GpathSyntaxTestSupport.checkAttribute(getRoot)
         GpathSyntaxTestSupport.checkAttributes(getRoot)
         GpathSyntaxTestSupport.checkAttributeTruth(getRoot)
     }
 
     @Test
-    void testNavigation() {
+    void navigation() {
         GpathSyntaxTestSupport.checkChildren(getRoot)
         GpathSyntaxTestSupport.checkParent(getRoot)
         GpathSyntaxTestSupport.checkNestedSizeExpressions(getRoot)
     }
 
     @Test
-    void testTraversal() {
+    void traversal() {
         TraversalTestSupport.checkDepthFirst(getRoot)
         TraversalTestSupport.checkBreadthFirst(getRoot)
     }
 
     @Test
-    void testIndices() {
+    void indices() {
         GpathSyntaxTestSupport.checkNegativeIndices(getRoot)
         GpathSyntaxTestSupport.checkRangeIndex(getRoot)
     }
 
     @Test
-    void testReplacementsAndAdditions() {
+    void replacementsAndAdditions() {
         GpathSyntaxTestSupport.checkReplaceNode(getRoot)
         GpathSyntaxTestSupport.checkReplaceMultipleNodes(getRoot)
         GpathSyntaxTestSupport.checkPlus(getRoot)
     }
 
     @Test
-    void testMixedMarkup() {
+    void mixedMarkup() {
         MixedMarkupTestSupport.checkMixedMarkup(getRoot)
         MixedMarkupTestSupport.checkMixedMarkupText(getRoot)
     }
 
     @Test
-    void testWhitespaceTrimming() {
+    void whitespaceTrimming() {
         def text = '<outer><inner>   Here is some text    </inner></outer>'
         def parser = new XmlParser(trimWhitespace: true)
         def outer = parser.parseText(text)
@@ -266,7 +266,7 @@ p() {
     }
 
     @Test
-    void testUpdate() {
+    void update() {
         def xml = '<root></root>'
         def parser = new XmlParser()
         def root = parser.parseText(xml)
@@ -296,7 +296,7 @@ p() {
     }
 
     @Test
-    void testReplaceNode() {
+    void replaceNode() {
         def xml = '<root><old/></root>'
         def parser = new XmlParser()
         def root = parser.parseText(xml)
@@ -319,14 +319,14 @@ p() {
     }
 
     @Test
-    void testXmlParserExtensionPoints() {
+    void xmlParserExtensionPoints() {
         def html = new CustomXmlParser().parseText(bookXml)
         assert html.getClass() == CustomNode
         assert html.name() == new Integer(42)
     }
 
     @Test
-    void testCloning() {
+    void cloning() {
         def xml = '<root><foo bar="baz"><inner/></foo></root>'
         def parser = new XmlParser()
         def root = parser.parseText(xml)
@@ -345,7 +345,7 @@ p() {
     }
 
     @Test
-    void testNamedParameterConstruction() {
+    void namedParameterConstruction() {
         def xml = '<root><item name="test">value</item></root>'
 
         // named parameters via setters
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlSlurperFactoryTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlSlurperFactoryTest.groovy
index c25d111eaf..237e858644 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlSlurperFactoryTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlSlurperFactoryTest.groovy
@@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test
 
 class XmlSlurperFactoryTest {
     @Test
-    void testCreateParser() {
+    void createParser() {
         def xml = '<root><old/></root>'
         def slurper = XmlSlurperFactory.newSlurper(true, true)
         def root = slurper.parseText(xml)
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlSlurperTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlSlurperTest.groovy
index f12863b7a8..54e2905525 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlSlurperTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlSlurperTest.groovy
@@ -29,7 +29,7 @@ final class XmlSlurperTest {
     final Closure<GPathResult> getRoot = { String xml -> new XmlSlurper().parseText(xml) }
 
     @Test
-    void testWsdl() {
+    void wsdl() {
         def wsdl = '''
             <definitions name="AgencyManagementService"
                          xmlns:ns1="http://www.example.org/NS1"
@@ -58,7 +58,7 @@ final class XmlSlurperTest {
     }
 
     @Test
-    void testElement() {
+    void element() {
         // can't update value directly with XmlSlurper, use replaceNode instead
         // GpathSyntaxTestSupport.checkUpdateElementValue(getRoot)
         GpathSyntaxTestSupport.checkElement(getRoot)
@@ -70,7 +70,7 @@ final class XmlSlurperTest {
     }
 
     @Test
-    void testAttribute() {
+    void attribute() {
         GpathSyntaxTestSupport.checkAttribute(getRoot)
         GpathSyntaxTestSupport.checkAttributes(getRoot)
         GpathSyntaxTestSupport.checkAttributeTruth(getRoot)
@@ -78,7 +78,7 @@ final class XmlSlurperTest {
 
     // GROOVY-11667
     @Test
-    void testAttribute2() {
+    void attribute2() {
         def xml = '''
             <person>
                 <name>John Doe</name>
@@ -99,39 +99,39 @@ final class XmlSlurperTest {
     }
 
     @Test
-    void testNavigation() {
+    void navigation() {
         GpathSyntaxTestSupport.checkChildren(getRoot)
         GpathSyntaxTestSupport.checkParent(getRoot)
         GpathSyntaxTestSupport.checkNestedSizeExpressions(getRoot)
     }
 
     @Test
-    void testTraversal() {
+    void traversal() {
         TraversalTestSupport.checkDepthFirst(getRoot)
         TraversalTestSupport.checkBreadthFirst(getRoot)
     }
 
     @Test
-    void testIndices() {
+    void indices() {
         GpathSyntaxTestSupport.checkNegativeIndices(getRoot)
         GpathSyntaxTestSupport.checkRangeIndex(getRoot)
     }
 
     @Test
-    void testReplacementsAndAdditions() {
+    void replacementsAndAdditions() {
         GpathSyntaxTestSupport.checkReplaceNode(getRoot)
         GpathSyntaxTestSupport.checkReplaceMultipleNodes(getRoot)
         GpathSyntaxTestSupport.checkPlus(getRoot)
     }
 
     @Test
-    void testMixedMarkup() {
+    void mixedMarkup() {
         MixedMarkupTestSupport.checkMixedMarkup(getRoot)
         MixedMarkupTestSupport.checkMixedMarkupText(getRoot)
     }
 
     @Test
-    void testReplace() {
+    void replace() {
         def input = "<doc><sec>Hello<p>World</p></sec></doc>"
         def replaceSlurper = new XmlSlurper().parseText(input)
         replaceSlurper.sec.replaceNode { node ->
@@ -143,7 +143,7 @@ final class XmlSlurperTest {
     }
 
     @Test
-    void testNamespacedName() {
+    void namespacedName() {
         def wsdl = '''
         <definitions name="AgencyManagementService"
             xmlns:ns1="http://www.example.org/NS1"
@@ -165,7 +165,7 @@ final class XmlSlurperTest {
 
     // GROOVY-4637
     @Test
-    void testNamespacedAttributes() {
+    void namespacedAttributes() {
         def xml = """
         <RootElement xmlns="http://www.ivan.com/ns1" xmlns:two="http://www.ivan.com/ns2">
             <ChildElement ItemId="FirstItemId" two:ItemId="SecondItemId">Child element data</ChildElement>
@@ -180,7 +180,7 @@ final class XmlSlurperTest {
 
     // GROOVY-6255
     @Test
-    void testXmlNamespacedAttributes() {
+    void xmlNamespacedAttributes() {
         def xml = '''
         <appendix version="5.0" xmlns="http://docbook.org/ns/docbook" xmlns:xml="http://www.w3.org/XML/1998/namespace">
             <section xml:id="a"/>
@@ -194,7 +194,7 @@ final class XmlSlurperTest {
 
     // GROOVY-6356
     @Test
-    void testSetAndRemoveAttributesWithNamespace() {
+    void setAndRemoveAttributesWithNamespace() {
         def xmlSource = '''<bob:root
                 xmlns:bob="stuff"
                 xmlns:gmi="http://www.isotc211.org/2005/gmi"
@@ -217,7 +217,7 @@ final class XmlSlurperTest {
 
     // GROOVY-6356
     @Test
-    void testSetAndRemoveAttributesNamespaceUnaware() {
+    void setAndRemoveAttributesNamespaceUnaware() {
         def xmlSource = '''<bob:root
                 xmlns:bob="stuff"
                 xmlns:gmi="http://www.isotc211.org/2005/gmi"
@@ -237,7 +237,7 @@ final class XmlSlurperTest {
 
     // GROOVY-5931
     @Test
-    void testIterableGPathResult() {
+    void iterableGPathResult() {
         def xml = '''
             <RootElement>
                 <ChildElement ItemId="FirstItemId">Child element data</ChildElement>
@@ -256,7 +256,7 @@ final class XmlSlurperTest {
 
     // GROOVY-7781
     @Test
-    void testNamespacedAttributesAccessedWithDifferentPrefix() {
+    void namespacedAttributesAccessedWithDifferentPrefix() {
         def xml = '''
             <x:root xmlns:x="blah">
                 <x:child x:id="1">c</x:child>
@@ -269,7 +269,7 @@ final class XmlSlurperTest {
     }
 
     @Test
-    void testParsePath() {
+    void parsePath() {
         File file = File.createTempFile('test','xml')
         file.deleteOnExit()
         file.text = '''
@@ -301,7 +301,7 @@ final class XmlSlurperTest {
     }
 
     @Test
-    void testNamedParameterConstruction() {
+    void namedParameterConstruction() {
         def xml = '<root><item name="test">value</item></root>'
 
         // named parameters via setters
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlUtilTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlUtilTest.groovy
index 64c2429a80..fc1517ffb2 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlUtilTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlUtilTest.groovy
@@ -40,7 +40,7 @@ class XmlUtilTest {
 
     // GROOVY-5158
     @Test
-    void testSerializeOfGPathResultShouldRoundTrip() {
+    void serializeOfGPathResultShouldRoundTrip() {
         def source = new InputSource(new StringReader(xml))
         source.encoding = "UTF-8"
         assertXmlEquals(xml, XmlUtil.serialize(new XmlSlurper().parse(source)))
@@ -50,7 +50,7 @@ class XmlUtilTest {
 
     // GROOVY-10132
     @Test
-    void testSerializeOfSurrogate() {
+    void serializeOfSurrogate() {
         def source = new InputSource(new StringReader(xml2))
         source.encoding = "UTF-8"
         assertXmlEquals(xml2, XmlUtil.serialize(new XmlSlurper().parse(source)))
@@ -58,7 +58,7 @@ class XmlUtilTest {
 
     // GROOVY-5361
     @Test
-    void testSchemaValidationUtilityMethod() {
+    void schemaValidationUtilityMethod() {
         Locale dl = Locale.getDefault()
         Locale.setDefault(Locale.ENGLISH)
 
@@ -106,7 +106,7 @@ class XmlUtilTest {
 
     // GROOVY-5775
     @Test
-    void testEscaping() {
+    void escaping() {
       def ans = escapeControlCharacters(escapeXml('"bread" & "butter"\r\n\u0000\u001f'))
       assert ans == '&quot;bread&quot; &amp; &quot;butter&quot;&#13;&#10;&#0;&#31;'
     }
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/benchmark/BuilderPerfTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/benchmark/BuilderPerfTest.groovy
index a3fc201024..17344e0785 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/benchmark/BuilderPerfTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/benchmark/BuilderPerfTest.groovy
@@ -39,7 +39,7 @@ class BuilderPerfTest {
     }
 
     @Test
-    void testMe () {
+    void me () {
         long start = System.currentTimeMillis()
         def writer
         5000.times({
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy249_Bug.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy249_Bug.groovy
index 56facf857c..6ae10b8a9e 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy249_Bug.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy249_Bug.groovy
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test
 class Groovy249_Bug {
 
     @Test
-    void testBug() {
+    void bug() {
         def t = new Bean249()
         t.b = "hello"
 
@@ -44,7 +44,7 @@ class Groovy249_Bug {
 /** @todo don't know why this fails
 
     @Test
-    void testBugInScript() {
+    void bugInScript() {
         assertScript <<<EOF
             import groovy.xml.MarkupBuilder;
 
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy593_Bug.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy593_Bug.groovy
index 5a0a29d42c..701bf5362b 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy593_Bug.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy593_Bug.groovy
@@ -44,7 +44,7 @@ class Groovy593_Bug {
 </chars>"""
 
     @Test
-    void testBug() {
+    void bug() {
         // XML characters to test with
         chars.chars {
             ampersand(a: "&", "&")
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy_2473Bug.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy_2473Bug.groovy
index cf1790a3b2..e172ed0231 100755
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy_2473Bug.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy_2473Bug.groovy
@@ -25,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals
 
 class Groovy_2473Bug {
     @Test
-    void testBug() {
+    void bug() {
         def w = new StringWriter()
         def b = new StreamingMarkupBuilder()
 
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/MarkupInScriptBug.java b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/MarkupInScriptBug.java
index 326d6876ef..852573b67b 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/MarkupInScriptBug.java
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/MarkupInScriptBug.java
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
 final class MarkupInScriptBug extends TestSupport {
 
     @Test
-    void testBug() throws Exception {
+    void bug() throws Exception {
         assertScriptFile("src/test/groovy/groovy/xml/script/AtomTestScript.groovy");
     }
 }
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/SeansBug.java b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/SeansBug.java
index 48073347ad..d879dbf4a4 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/SeansBug.java
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/SeansBug.java
@@ -24,14 +24,14 @@ import org.junit.jupiter.api.Test;
 final class SeansBug {
 
     @Test
-    void testBug() throws Exception {
+    void bug() throws Exception {
         String code = "for (i in 1..10) \n{\n  println(i)\n}";
         GroovyShell shell = new GroovyShell();
         shell.evaluate(code);
     }
 
     @Test
-    void testMarkupBug() throws Exception {
+    void markupBug() throws Exception {
         String[] lines =
                 {
                         "package groovy.xml",
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/StaticMarkupBug.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/StaticMarkupBug.groovy
index 0f72e6d0fa..7eda2c7120 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/StaticMarkupBug.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/StaticMarkupBug.groovy
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test
 class StaticMarkupBug {
 
     @Test
-    void testBug() {
+    void bug() {
         doMarkup(new MarkupBuilder())
     }
 
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/TedsClosureBug.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/TedsClosureBug.groovy
index 68d2226ad5..1c75d88cd2 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/TedsClosureBug.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/TedsClosureBug.groovy
@@ -52,7 +52,7 @@ class TedsClosureBug {
 </atom>'''
 
     @Test
-    void testBug() {
+    void bug() {
         def f = new Feed()
         f.author = new Person(name:'Ted Leung',url:'http://www.sauria.com/blog', email:'twl@sauria.com')
         f.entries = [ new Entry(title:'one',summary:'first post'), new Entry(title:'two',summary:'the second post'), new Entry(title:'three', summary:'post the third'), new Entry(title:'four',summary:'the ponderous fourth post') ]
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/DOMCategoryTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/DOMCategoryTest.groovy
index ece7e0b56d..b4e3ea9163 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/DOMCategoryTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/DOMCategoryTest.groovy
@@ -40,7 +40,7 @@ class DOMCategoryTest {
     }
 
     @Test
-    void testReplacementsAndAdditions() {
+    void replacementsAndAdditions() {
         use(DOMCategory) {
             GpathSyntaxTestSupport.checkReplaceNode(getRoot)
             GpathSyntaxTestSupport.checkReplaceMultipleNodes(getRoot)
@@ -49,7 +49,7 @@ class DOMCategoryTest {
     }
 
     @Test
-    void testMixedMarkup() {
+    void mixedMarkup() {
         use(DOMCategory) {
             MixedMarkupTestSupport.checkMixedMarkup(getRoot)
             MixedMarkupTestSupport.checkMixedMarkupText(getRoot)
@@ -57,7 +57,7 @@ class DOMCategoryTest {
     }
 
     @Test
-    void testElement() {
+    void element() {
         use(DOMCategory) {
             GpathSyntaxTestSupport.checkUpdateElementValue(getRoot)
             GpathSyntaxTestSupport.checkElement(getRoot)
@@ -70,7 +70,7 @@ class DOMCategoryTest {
     }
 
     @Test
-    void testAttribute() {
+    void attribute() {
         use(DOMCategory) {
             GpathSyntaxTestSupport.checkAttribute(getRoot)
             GpathSyntaxTestSupport.checkAttributes(getRoot)
@@ -79,7 +79,7 @@ class DOMCategoryTest {
     }
 
     @Test
-    void testIndices() {
+    void indices() {
         use(DOMCategory) {
             GpathSyntaxTestSupport.checkNegativeIndices(getRoot)
             GpathSyntaxTestSupport.checkRangeIndex(getRoot)
@@ -87,7 +87,7 @@ class DOMCategoryTest {
     }
 
     @Test
-    void testNavigation() {
+    void navigation() {
         use(DOMCategory) {
             GpathSyntaxTestSupport.checkChildren(getRoot)
             GpathSyntaxTestSupport.checkParent(getRoot)
@@ -96,7 +96,7 @@ class DOMCategoryTest {
     }
 
     @Test
-    void testTraversal() {
+    void traversal() {
         use(DOMCategory) {
             TraversalTestSupport.checkDepthFirst(getRoot)
             TraversalTestSupport.checkBreadthFirst(getRoot)
@@ -104,7 +104,7 @@ class DOMCategoryTest {
     }
 
     @Test
-    void testGetOnMapWithDomCategory() {
+    void getOnMapWithDomCategory() {
         Map ids = [:]
         ids.put("try", "sample1")
         assert ids.get("try") == "sample1"
@@ -119,7 +119,7 @@ class DOMCategoryTest {
     }
 
     @Test
-    void testGetOnNonNodesWithDomCategory() {
+    void getOnNonNodesWithDomCategory() {
         def myFoo = new Foo()
         assert myFoo.get("bar") == 3
         use(DOMCategory) {
@@ -129,7 +129,7 @@ class DOMCategoryTest {
 
     /** Test for GROOVY-3109 */
     @Test
-    void testAccessToUnknownPropertyInAScriptWithDomCategory() {
+    void accessToUnknownPropertyInAScriptWithDomCategory() {
         assertScript """
             import groovy.xml.dom.DOMCategory
 
@@ -146,7 +146,7 @@ class DOMCategoryTest {
 
     /** Test for GROOVY-3109 */
     @Test
-    void testAccessToUnknownPropertyInAClassWithDomCategory() {
+    void accessToUnknownPropertyInAClassWithDomCategory() {
         assertScript """
             import groovy.xml.dom.DOMCategory
 
@@ -169,7 +169,7 @@ class DOMCategoryTest {
     }
 
     @Test
-    void testXPathWithDomCategory() {
+    void xPathWithDomCategory() {
         def reader = new StringReader('<a><b>B1</b><b>B2</b><c a1="4" a2="true">C</c></a>')
         def root = DOMBuilder.parse(reader).documentElement
         use(DOMCategory) {
@@ -184,7 +184,7 @@ class DOMCategoryTest {
     }
 
     @Test
-    void testDomCategoryNameWithNodes() {
+    void domCategoryNameWithNodes() {
         def reader = new StringReader('<a><b>B1</b><b>B2</b></a>')
         def a = DOMBuilder.parse(reader).documentElement
         use(DOMCategory) {
@@ -197,7 +197,7 @@ class DOMCategoryTest {
     }
 
     @Test
-    void testReplaceNode() {
+    void replaceNode() {
         def readerOld = new StringReader('<root><old/></root>')
         def oldDoc = DOMBuilder.parse(readerOld)
         def oldRoot = oldDoc.documentElement
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/DOMTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/DOMTest.groovy
index dccef911cd..9020a8a429 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/DOMTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/DOMTest.groovy
@@ -28,7 +28,7 @@ class DOMTest {
     def benchmark = false
 
     @Test
-    void testDOMParser() {
+    void domParser() {
         def xml = new StringReader("<html><head><title class='mytitle'>Test</title></head><body><p class='mystyle'>This is a test.</p></body></html>")
         def doc = DOMBuilder.parse(xml)
         def html = doc.documentElement
@@ -36,7 +36,7 @@ class DOMTest {
     }
 
     @Test
-    void testDOMBuilder() {
+    void domBuilder() {
         def html = DOMBuilder.newInstance().
                 html {
                     head {
@@ -50,7 +50,7 @@ class DOMTest {
     }
 
     @Test
-    void testDOMBuilderWithNullValue() {
+    void domBuilderWithNullValue() {
         def html = DOMBuilder.newInstance().
                 html {
                     head {
@@ -63,7 +63,7 @@ class DOMTest {
     }
 
     @Test
-    void testStreamingDOMBuilder() {
+    void streamingDomBuilder() {
         def builder = new StreamingDOMBuilder()
         def make = builder.bind {
             html {
@@ -100,9 +100,9 @@ class DOMTest {
         def mydomtest = new DOMTest()
         def standard = 0
         mydomtest.benchmark = true
-        [{ mydomtest.testDOMParser() },
-                { mydomtest.testDOMBuilder() },
-                { mydomtest.testStreamingDOMBuilder() }].eachWithIndex { testMethod, index ->
+        [{ mydomtest.dOMParser() },
+                { mydomtest.domBuilder() },
+                { mydomtest.streamingDomBuilder() }].eachWithIndex { testMethod, index ->
             // Run the method once to fill any caches and to load classes
             testMethod()
             def start = System.currentTimeMillis()
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/NamespaceDOMTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/NamespaceDOMTest.groovy
index b0d44f7b85..00abbf6889 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/NamespaceDOMTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/NamespaceDOMTest.groovy
@@ -62,7 +62,7 @@ final class NamespaceDOMTest extends TestXmlSupport {
     '''
 
     @Test
-    void testXsdSchemaWithBuilderHavingAutoPrefix() {
+    void xsdSchemaWithBuilderHavingAutoPrefix() {
         def builder = DOMBuilder.newInstance()
         def xsd = NamespaceBuilder.newInstance(builder, 'http://www.w3.org/2001/XMLSchema', 'xsd')
         def root = xsd.schema {
@@ -82,7 +82,7 @@ final class NamespaceDOMTest extends TestXmlSupport {
     }
 
     @Test
-    void testXsdSchemaWithBuilderHavingMultipleNamespaces() {
+    void xsdSchemaWithBuilderHavingMultipleNamespaces() {
         def builder = DOMBuilder.newInstance()
         def multi = NamespaceBuilder.newInstance(builder)
         multi.namespace('http://example.org/ord')
@@ -91,7 +91,7 @@ final class NamespaceDOMTest extends TestXmlSupport {
     }
 
     @Test
-    void testXsdSchemaWithBuilderHavingDeclareNamespace() {
+    void xsdSchemaWithBuilderHavingDeclareNamespace() {
         def builder = DOMBuilder.newInstance()
         def multi = NamespaceBuilder.newInstance(builder)
         multi.declareNamespace(
diff --git a/subprojects/groovy-xml/src/test/groovy/org/apache/groovy/xml/tools/DomToGroovyTest.groovy b/subprojects/groovy-xml/src/test/groovy/org/apache/groovy/xml/tools/DomToGroovyTest.groovy
index 2563389399..a5478859dd 100644
--- a/subprojects/groovy-xml/src/test/groovy/org/apache/groovy/xml/tools/DomToGroovyTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/org/apache/groovy/xml/tools/DomToGroovyTest.groovy
@@ -92,14 +92,14 @@ class DomToGroovyTest {
     protected File dir = new File("build/generated-groovyxml")
 
     @Test
-    void testConversion() {
+    void conversion() {
         convert("test1.xml", "test1.groovy")
         convert("po.xsd", "poSchema.groovy")
         convert("swing.xml", "swing.groovy")
     }
 
     @Test
-    void testConversionFormat() {
+    void conversionFormat() {
         checkConversion(TEST_XML_1, EXPECTED_BUILDER_SCRIPT_1)
         checkConversion(TEST_XML_2, EXPECTED_BUILDER_SCRIPT_2)
         checkConversion(TEST_XML_3, EXPECTED_BUILDER_SCRIPT_3)


(groovy) 01/06: GROOVY-7633: Add constructor with Map for SAXOptions to XmlSlurper

Posted by pa...@apache.org.
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

commit 59a9b97d672a4bed3a87f84e6de6f894053a6411
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Apr 13 13:55:55 2026 +1000

    GROOVY-7633: Add constructor with Map for SAXOptions to XmlSlurper
---
 .../src/main/java/groovy/xml/XmlSlurper.java       | 150 ++++++++++++++++++---
 .../test/groovy/groovy/xml/XmlSlurperTest.groovy   |  26 ++++
 2 files changed, 154 insertions(+), 22 deletions(-)

diff --git a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlSlurper.java b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlSlurper.java
index 3925a53352..9236c94ff1 100644
--- a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlSlurper.java
+++ b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlSlurper.java
@@ -85,22 +85,29 @@ import static groovy.xml.XmlUtil.setFeatureQuietly;
  * @see GPathResult
  */
 public class XmlSlurper extends DefaultHandler {
-    private final XMLReader reader;
+    private XMLReader reader;
     private Node currentNode = null;
     private final Stack<Node> stack = new Stack<>();
     private final StringBuilder charBuffer = new StringBuilder();
     private final Map<String, String> namespaceTagHints = new HashMap<>();
     private boolean keepIgnorableWhitespace = false;
-    private boolean namespaceAware = false;
+    private boolean namespaceAware = true;
+    private boolean validating = false;
+    private boolean allowDocTypeDeclaration = false;
 
     /**
      * Creates a non-validating and namespace-aware <code>XmlSlurper</code> which does not allow DOCTYPE declarations in documents.
+     * <p>
+     * Parser options can be configured via setters before the first parse call:
+     * <pre>
+     * // Using Groovy named parameters:
+     * def slurper = new XmlSlurper(namespaceAware: false, keepIgnorableWhitespace: true)
+     * </pre>
      *
      * @throws ParserConfigurationException if no parser which satisfies the requested configuration can be created.
      * @throws SAXException for SAX errors.
      */
     public XmlSlurper() throws ParserConfigurationException, SAXException {
-        this(false, true);
     }
 
     /**
@@ -127,21 +134,47 @@ public class XmlSlurper extends DefaultHandler {
      * @throws SAXException for SAX errors.
      */
     public XmlSlurper(final boolean validating, final boolean namespaceAware, boolean allowDocTypeDeclaration) throws ParserConfigurationException, SAXException {
+        this.validating = validating;
+        this.namespaceAware = namespaceAware;
+        this.allowDocTypeDeclaration = allowDocTypeDeclaration;
+    }
+
+    public XmlSlurper(final XMLReader reader) {
+        this.reader = reader;
+    }
+
+    public XmlSlurper(final SAXParser parser) throws SAXException {
+        this(parser.getXMLReader());
+    }
+
+    private void initReader() throws ParserConfigurationException, SAXException {
         SAXParserFactory factory = FactorySupport.createSaxParserFactory();
         factory.setNamespaceAware(namespaceAware);
-        this.namespaceAware = namespaceAware;
         factory.setValidating(validating);
         setFeatureQuietly(factory, XMLConstants.FEATURE_SECURE_PROCESSING, true);
         setFeatureQuietly(factory, "http://apache.org/xml/features/disallow-doctype-decl", !allowDocTypeDeclaration);
         reader = factory.newSAXParser().getXMLReader();
     }
 
-    public XmlSlurper(final XMLReader reader) {
-        this.reader = reader;
+    private XMLReader getReader() throws ParserConfigurationException, SAXException {
+        if (reader == null) {
+            initReader();
+        }
+        return reader;
     }
 
-    public XmlSlurper(final SAXParser parser) throws SAXException {
-        this(parser.getXMLReader());
+    private XMLReader ensureReader() {
+        try {
+            return getReader();
+        } catch (ParserConfigurationException | SAXException e) {
+            throw new RuntimeException("Failed to initialize XML reader", e);
+        }
+    }
+
+    private void checkNotInitialized(String property) {
+        if (reader != null) {
+            throw new IllegalStateException(property + " must be set before parsing");
+        }
     }
 
     /**
@@ -169,6 +202,74 @@ public class XmlSlurper extends DefaultHandler {
         return keepIgnorableWhitespace;
     }
 
+    /**
+     * Determine if namespace handling is enabled.
+     *
+     * @return true if namespace handling is enabled
+     */
+    public boolean isNamespaceAware() {
+        return namespaceAware;
+    }
+
+    /**
+     * Enable and/or disable namespace handling.
+     * Must be set before the first parse call.
+     *
+     * @param namespaceAware the new desired value
+     * @throws IllegalStateException if called after parsing has started
+     * @since 6.0.0
+     */
+    public void setNamespaceAware(boolean namespaceAware) {
+        checkNotInitialized("namespaceAware");
+        this.namespaceAware = namespaceAware;
+    }
+
+    /**
+     * Determine if the parser validates documents.
+     *
+     * @return true if validation is enabled
+     * @since 6.0.0
+     */
+    public boolean isValidating() {
+        return validating;
+    }
+
+    /**
+     * Enable and/or disable validation.
+     * Must be set before the first parse call.
+     *
+     * @param validating the new desired value
+     * @throws IllegalStateException if called after parsing has started
+     * @since 6.0.0
+     */
+    public void setValidating(boolean validating) {
+        checkNotInitialized("validating");
+        this.validating = validating;
+    }
+
+    /**
+     * Determine if DOCTYPE declarations are allowed.
+     *
+     * @return true if DOCTYPE declarations are allowed
+     * @since 6.0.0
+     */
+    public boolean isAllowDocTypeDeclaration() {
+        return allowDocTypeDeclaration;
+    }
+
+    /**
+     * Enable and/or disable DOCTYPE declaration support.
+     * Must be set before the first parse call.
+     *
+     * @param allowDocTypeDeclaration the new desired value
+     * @throws IllegalStateException if called after parsing has started
+     * @since 6.0.0
+     */
+    public void setAllowDocTypeDeclaration(boolean allowDocTypeDeclaration) {
+        checkNotInitialized("allowDocTypeDeclaration");
+        this.allowDocTypeDeclaration = allowDocTypeDeclaration;
+    }
+
     /**
      * @return The GPathResult instance created by consuming a stream of SAX events
      *         Note if one of the parse methods has been called then this returns null
@@ -196,9 +297,14 @@ public class XmlSlurper extends DefaultHandler {
      *         or character stream supplied by the application.
      */
     public GPathResult parse(final InputSource input) throws IOException, SAXException {
-        reader.setContentHandler(this);
-        reader.parse(input);
-        return getDocument();
+        try {
+            XMLReader r = getReader();
+            r.setContentHandler(this);
+            r.parse(input);
+            return getDocument();
+        } catch (ParserConfigurationException e) {
+            throw new SAXException(e);
+        }
     }
 
     /**
@@ -299,49 +405,49 @@ public class XmlSlurper extends DefaultHandler {
     * @see org.xml.sax.XMLReader#getDTDHandler()
     */
     public DTDHandler getDTDHandler() {
-        return reader.getDTDHandler();
+        return ensureReader().getDTDHandler();
     }
 
     /* (non-Javadoc)
     * @see org.xml.sax.XMLReader#getEntityResolver()
     */
     public EntityResolver getEntityResolver() {
-        return reader.getEntityResolver();
+        return ensureReader().getEntityResolver();
     }
 
     /* (non-Javadoc)
     * @see org.xml.sax.XMLReader#getErrorHandler()
     */
     public ErrorHandler getErrorHandler() {
-        return reader.getErrorHandler();
+        return ensureReader().getErrorHandler();
     }
 
     /* (non-Javadoc)
     * @see org.xml.sax.XMLReader#getFeature(java.lang.String)
     */
     public boolean getFeature(final String uri) throws SAXNotRecognizedException, SAXNotSupportedException {
-        return reader.getFeature(uri);
+        return ensureReader().getFeature(uri);
     }
 
     /* (non-Javadoc)
     * @see org.xml.sax.XMLReader#getProperty(java.lang.String)
     */
     public Object getProperty(final String uri) throws SAXNotRecognizedException, SAXNotSupportedException {
-        return reader.getProperty(uri);
+        return ensureReader().getProperty(uri);
     }
 
     /* (non-Javadoc)
     * @see org.xml.sax.XMLReader#setDTDHandler(org.xml.sax.DTDHandler)
     */
     public void setDTDHandler(final DTDHandler dtdHandler) {
-        reader.setDTDHandler(dtdHandler);
+        ensureReader().setDTDHandler(dtdHandler);
     }
 
     /* (non-Javadoc)
     * @see org.xml.sax.XMLReader#setEntityResolver(org.xml.sax.EntityResolver)
     */
     public void setEntityResolver(final EntityResolver entityResolver) {
-        reader.setEntityResolver(entityResolver);
+        ensureReader().setEntityResolver(entityResolver);
     }
 
     /**
@@ -350,7 +456,7 @@ public class XmlSlurper extends DefaultHandler {
      * @param base The URL used to resolve relative URLs
      */
     public void setEntityBaseUrl(final URL base) {
-        reader.setEntityResolver((publicId, systemId) -> {
+        ensureReader().setEntityResolver((publicId, systemId) -> {
             try {
                 return new InputSource(base.toURI().resolve(systemId).toURL().openStream());
             } catch (URISyntaxException e) {
@@ -363,21 +469,21 @@ public class XmlSlurper extends DefaultHandler {
     * @see org.xml.sax.XMLReader#setErrorHandler(org.xml.sax.ErrorHandler)
     */
     public void setErrorHandler(final ErrorHandler errorHandler) {
-        reader.setErrorHandler(errorHandler);
+        ensureReader().setErrorHandler(errorHandler);
     }
 
     /* (non-Javadoc)
     * @see org.xml.sax.XMLReader#setFeature(java.lang.String, boolean)
     */
     public void setFeature(final String uri, final boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
-        reader.setFeature(uri, value);
+        ensureReader().setFeature(uri, value);
     }
 
     /* (non-Javadoc)
     * @see org.xml.sax.XMLReader#setProperty(java.lang.String, java.lang.Object)
     */
     public void setProperty(final String uri, final Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
-        reader.setProperty(uri, value);
+        ensureReader().setProperty(uri, value);
     }
 
     // ContentHandler interface
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlSlurperTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlSlurperTest.groovy
index 63d4e13beb..f12863b7a8 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlSlurperTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlSlurperTest.groovy
@@ -299,4 +299,30 @@ final class XmlSlurperTest {
         assert xml.message.part.lookupNamespace("undefinedPrefix") == null
         xml.message.findAll { true }.each { assert it.name() == "message"}
     }
+
+    @Test
+    void testNamedParameterConstruction() {
+        def xml = '<root><item name="test">value</item></root>'
+
+        // named parameters via setters
+        def slurper = new XmlSlurper(namespaceAware: false, keepIgnorableWhitespace: true)
+        def result = slurper.parseText(xml)
+        assert result.item.text() == 'value'
+        assert result.item.@name == 'test'
+
+        // setter after boolean constructor, before first parse
+        def slurper2 = new XmlSlurper(false, false)
+        slurper2.allowDocTypeDeclaration = true
+        assert slurper2.parseText(xml).item.text() == 'value'
+
+        // setter after parse should fail
+        def slurper3 = new XmlSlurper()
+        slurper3.parseText(xml)
+        try {
+            slurper3.namespaceAware = false
+            assert false, 'should have thrown'
+        } catch (IllegalStateException e) {
+            assert e.message.contains('must be set before parsing')
+        }
+    }
 }


(groovy) 06/06: minor refactor: remove checkstyle warnings

Posted by pa...@apache.org.
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

commit e6e582aaed342d9577142abc09392c9ea24ccc5a
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Apr 13 14:49:57 2026 +1000

    minor refactor: remove checkstyle warnings
---
 .../groovy-xml/src/main/java/groovy/xml/MarkupBuilder.java     | 10 ++++++++++
 subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java   |  1 -
 .../src/main/java/org/apache/groovy/xml/tools/DomToGroovy.java |  2 ++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/subprojects/groovy-xml/src/main/java/groovy/xml/MarkupBuilder.java b/subprojects/groovy-xml/src/main/java/groovy/xml/MarkupBuilder.java
index 1acc9d9d4b..f0dbd05010 100644
--- a/subprojects/groovy-xml/src/main/java/groovy/xml/MarkupBuilder.java
+++ b/subprojects/groovy-xml/src/main/java/groovy/xml/MarkupBuilder.java
@@ -463,6 +463,8 @@ public class MarkupBuilder extends BuilderSupport {
                         break;
                     case 3:
                         throw new Error();
+                    default:
+                        break;
                 }
                 break;
             case 1:
@@ -491,6 +493,8 @@ public class MarkupBuilder extends BuilderSupport {
                             }
                         }
                         break;
+                    default:
+                        break;
                 }
                 break;
             case 2:
@@ -510,6 +514,8 @@ public class MarkupBuilder extends BuilderSupport {
                         print(name);
                         out.print(">");
                         break;
+                    default:
+                        break;
                 }
                 break;
             case 3:
@@ -537,8 +543,12 @@ public class MarkupBuilder extends BuilderSupport {
                         print(name);
                         out.print(">");
                         break;
+                    default:
+                        break;
                 }
                 break;
+            default:
+                break;
         }
         state = next;
     }
diff --git a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
index 21304f80e2..0a9842229f 100644
--- a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
+++ b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
@@ -55,7 +55,6 @@ import java.io.PrintWriter;
 import java.io.StringReader;
 import java.io.Writer;
 import java.net.URL;
-import java.nio.charset.Charset;
 
 /**
  * Used for pretty printing XML content and other XML related utilities.
diff --git a/subprojects/groovy-xml/src/main/java/org/apache/groovy/xml/tools/DomToGroovy.java b/subprojects/groovy-xml/src/main/java/org/apache/groovy/xml/tools/DomToGroovy.java
index 3abe115afd..154079253b 100644
--- a/subprojects/groovy-xml/src/main/java/org/apache/groovy/xml/tools/DomToGroovy.java
+++ b/subprojects/groovy-xml/src/main/java/org/apache/groovy/xml/tools/DomToGroovy.java
@@ -143,6 +143,8 @@ public class DomToGroovy {
             case Node.COMMENT_NODE :
                 printComment((Comment) node, endWithComma);
                 break;
+            default:
+                break;
         }
     }