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 <[email protected]> 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() {
