This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/commons-xml.git
commit 7261217aa5fc6023de221680af8e0830f9c2ec5d Author: Gary Gregory <[email protected]> AuthorDate: Sun Aug 30 11:49:33 2026 -0400 Use static imports for Assertions.assertX() calls. Organize imports in tests. --- .../commons/xml/AssociatedStylesheetTest.java | 3 +-- .../commons/xml/EntityResolverFloorTest.java | 3 +-- .../org/apache/commons/xml/ExternalDtdTest.java | 6 ++--- .../commons/xml/ExternalGeneralEntityTest.java | 6 ++--- .../commons/xml/ExternalParameterEntityTest.java | 10 ++++---- .../xml/FallbackIgnoreEntityResolver2Test.java | 3 +-- .../xml/FallbackIgnoreLSResourceResolverTest.java | 2 +- .../commons/xml/FallbackIgnoreURIResolverTest.java | 3 ++- .../commons/xml/FallbackIgnoreXMLResolverTest.java | 3 ++- .../org/apache/commons/xml/SaxonProviderTest.java | 27 +++++++++++----------- .../commons/xml/SaxonXPathExternalCallsTest.java | 2 -- .../commons/xml/SchemaFactoryLanguageTest.java | 4 ++-- .../commons/xml/SecureDocumentBuilderTest.java | 2 ++ .../apache/commons/xml/SecureExceptionTest.java | 1 + .../commons/xml/SecureSAXParserFactoryTest.java | 2 -- .../apache/commons/xml/SecureSAXParserTest.java | 25 +++++++++++--------- .../commons/xml/SecureSchemaFactoryTest.java | 9 ++++---- .../org/apache/commons/xml/SecureSchemaTest.java | 2 ++ .../apache/commons/xml/SecureTemplatesTest.java | 3 +-- .../commons/xml/SecureTransformerFactoryTest.java | 20 ++++++++-------- .../commons/xml/SecureTransformerHandlerTest.java | 1 - .../apache/commons/xml/SecureTransformerTest.java | 7 +++--- .../commons/xml/SecureValidatorHandlerTest.java | 2 +- .../apache/commons/xml/SecureValidatorTest.java | 12 +++++----- .../apache/commons/xml/SecureXMLFilterTest.java | 22 +++++++++--------- .../apache/commons/xml/SecureXMLReaderTest.java | 15 +++++++----- .../commons/xml/SecureXPathExpressionTest.java | 4 +--- .../apache/commons/xml/SecureXPathFactoryTest.java | 10 ++++---- .../org/apache/commons/xml/SecureXPathTest.java | 9 ++++---- .../apache/commons/xml/XPathInputSourceTest.java | 1 - 30 files changed, 109 insertions(+), 110 deletions(-) diff --git a/src/test/java/org/apache/commons/xml/AssociatedStylesheetTest.java b/src/test/java/org/apache/commons/xml/AssociatedStylesheetTest.java index 8467611..a417207 100644 --- a/src/test/java/org/apache/commons/xml/AssociatedStylesheetTest.java +++ b/src/test/java/org/apache/commons/xml/AssociatedStylesheetTest.java @@ -24,13 +24,12 @@ import javax.xml.transform.Source; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerFactory; +import javax.xml.transform.sax.SAXSource; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import javax.xml.transform.sax.SAXSource; - /** * Checks that {@code getAssociatedStylesheet} scans for {@code xml-stylesheet} PIs without fetching an external DTD declared in the document prolog. * diff --git a/src/test/java/org/apache/commons/xml/EntityResolverFloorTest.java b/src/test/java/org/apache/commons/xml/EntityResolverFloorTest.java index 6005d9a..f89f8cb 100644 --- a/src/test/java/org/apache/commons/xml/EntityResolverFloorTest.java +++ b/src/test/java/org/apache/commons/xml/EntityResolverFloorTest.java @@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.IOException; import java.io.StringWriter; import java.net.URL; @@ -53,8 +54,6 @@ import org.xml.sax.SAXException; import org.xml.sax.XMLReader; -import java.io.IOException; - /** * Checks that a caller-supplied resolver cannot remove the secure ignore-all floor on any factory. * diff --git a/src/test/java/org/apache/commons/xml/ExternalDtdTest.java b/src/test/java/org/apache/commons/xml/ExternalDtdTest.java index f500087..92f6650 100644 --- a/src/test/java/org/apache/commons/xml/ExternalDtdTest.java +++ b/src/test/java/org/apache/commons/xml/ExternalDtdTest.java @@ -17,13 +17,13 @@ package org.apache.commons.xml; +import javax.xml.transform.Source; +import javax.xml.validation.Validator; + import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import javax.xml.transform.Source; -import javax.xml.validation.Validator; - /** * Checks whether parsers can pull in an external DTD declared via {@code <!DOCTYPE root SYSTEM "...">}. * diff --git a/src/test/java/org/apache/commons/xml/ExternalGeneralEntityTest.java b/src/test/java/org/apache/commons/xml/ExternalGeneralEntityTest.java index f5f74c9..e07c70f 100644 --- a/src/test/java/org/apache/commons/xml/ExternalGeneralEntityTest.java +++ b/src/test/java/org/apache/commons/xml/ExternalGeneralEntityTest.java @@ -17,13 +17,13 @@ package org.apache.commons.xml; +import javax.xml.transform.Source; +import javax.xml.validation.Validator; + import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import javax.xml.transform.Source; -import javax.xml.validation.Validator; - /** * Checks whether parsers can pull in an external general entity declared inline in the internal subset. * diff --git a/src/test/java/org/apache/commons/xml/ExternalParameterEntityTest.java b/src/test/java/org/apache/commons/xml/ExternalParameterEntityTest.java index 5cc684b..a11fe21 100644 --- a/src/test/java/org/apache/commons/xml/ExternalParameterEntityTest.java +++ b/src/test/java/org/apache/commons/xml/ExternalParameterEntityTest.java @@ -17,13 +17,16 @@ package org.apache.commons.xml; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + import java.io.StringReader; import java.util.concurrent.atomic.AtomicBoolean; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.Source; +import javax.xml.validation.Validator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -31,9 +34,6 @@ import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; -import javax.xml.transform.Source; -import javax.xml.validation.Validator; - /** * Checks whether parsers can pull in an external DTD via a parameter-entity reference inside the internal subset. * @@ -109,7 +109,7 @@ private static boolean probeDomAcceptsParameterEntities() { private static boolean probeSaxResolvesParameterEntities() { final AtomicBoolean called = new AtomicBoolean(); - Assertions.assertDoesNotThrow(() -> { + assertDoesNotThrow(() -> { final XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); reader.setEntityResolver((publicId, systemId) -> { if ("about:invalid".equals(systemId)) { diff --git a/src/test/java/org/apache/commons/xml/FallbackIgnoreEntityResolver2Test.java b/src/test/java/org/apache/commons/xml/FallbackIgnoreEntityResolver2Test.java index 5f0e80f..30ff875 100644 --- a/src/test/java/org/apache/commons/xml/FallbackIgnoreEntityResolver2Test.java +++ b/src/test/java/org/apache/commons/xml/FallbackIgnoreEntityResolver2Test.java @@ -25,11 +25,10 @@ import org.junit.jupiter.api.Test; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; +import org.xml.sax.SAXException; import org.xml.sax.ext.DefaultHandler2; import org.xml.sax.ext.EntityResolver2; -import org.xml.sax.SAXException; - class FallbackIgnoreEntityResolver2Test { @Test diff --git a/src/test/java/org/apache/commons/xml/FallbackIgnoreLSResourceResolverTest.java b/src/test/java/org/apache/commons/xml/FallbackIgnoreLSResourceResolverTest.java index 2df0487..ac5c8aa 100644 --- a/src/test/java/org/apache/commons/xml/FallbackIgnoreLSResourceResolverTest.java +++ b/src/test/java/org/apache/commons/xml/FallbackIgnoreLSResourceResolverTest.java @@ -20,8 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.ls.LSException; import org.w3c.dom.ls.LSInput; import org.w3c.dom.ls.LSResourceResolver; diff --git a/src/test/java/org/apache/commons/xml/FallbackIgnoreURIResolverTest.java b/src/test/java/org/apache/commons/xml/FallbackIgnoreURIResolverTest.java index d150f60..34a3287 100644 --- a/src/test/java/org/apache/commons/xml/FallbackIgnoreURIResolverTest.java +++ b/src/test/java/org/apache/commons/xml/FallbackIgnoreURIResolverTest.java @@ -19,12 +19,13 @@ import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Test; import javax.xml.transform.TransformerException; import javax.xml.transform.URIResolver; import javax.xml.transform.dom.DOMSource; +import org.junit.jupiter.api.Test; + class FallbackIgnoreURIResolverTest { @Test diff --git a/src/test/java/org/apache/commons/xml/FallbackIgnoreXMLResolverTest.java b/src/test/java/org/apache/commons/xml/FallbackIgnoreXMLResolverTest.java index ee67a54..4a71043 100644 --- a/src/test/java/org/apache/commons/xml/FallbackIgnoreXMLResolverTest.java +++ b/src/test/java/org/apache/commons/xml/FallbackIgnoreXMLResolverTest.java @@ -20,11 +20,12 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Test; import javax.xml.stream.XMLResolver; import javax.xml.stream.XMLStreamException; +import org.junit.jupiter.api.Test; + class FallbackIgnoreXMLResolverTest { @Test diff --git a/src/test/java/org/apache/commons/xml/SaxonProviderTest.java b/src/test/java/org/apache/commons/xml/SaxonProviderTest.java index 15973ea..bbe275c 100644 --- a/src/test/java/org/apache/commons/xml/SaxonProviderTest.java +++ b/src/test/java/org/apache/commons/xml/SaxonProviderTest.java @@ -19,18 +19,20 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.xml.transform.TransformerFactory; -import javax.xml.xpath.XPathFactory; -import org.junit.jupiter.api.Test; - import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; + +import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactoryConfigurationError; -import org.junit.jupiter.api.Assertions; +import javax.xml.xpath.XPathFactory; + import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.xml.sax.SAXNotSupportedException; import org.xml.sax.helpers.XMLFilterImpl; @@ -82,9 +84,9 @@ void recognizesOpenSourceAndCommercialSaxonClasses() { @Test @Tag("xpath3") void rejectsFactoriesThatDoNotImplementSaxonApis() { - Assertions.assertThrows(SecureException.class, + assertThrows(SecureException.class, () -> SaxonProvider.configure(TransformerFactory.newInstance("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl", null))); - Assertions.assertThrows(SecureException.class, () -> SaxonProvider + assertThrows(SecureException.class, () -> SaxonProvider .configure(XPathFactory.newInstance(XPathFactory.DEFAULT_OBJECT_MODEL_URI, "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl", null))); } @@ -100,8 +102,7 @@ void rejectsSaxonCollectionResolutionWhenConfiguredToThrow() throws Exception { final String previous = System.getProperty(SecureException.THROW_ON_UNRESOLVED); try { System.setProperty(SecureException.THROW_ON_UNRESOLVED, "true"); - final InvocationTargetException exception = Assertions - .assertThrows(InvocationTargetException.class, () -> findCollection.invoke(finder, null, "urn:collection")); + final InvocationTargetException exception = assertThrows(InvocationTargetException.class, () -> findCollection.invoke(finder, null, "urn:collection")); assertEquals("net.sf.saxon.trans.XPathException", exception.getCause().getClass().getName()); } finally { if (previous == null) { @@ -119,10 +120,8 @@ void translatesSecureParserFailuresToSaxonConfigurationErrors() throws Exception SaxonProvider.configure(factory); final Object configuration = factory.getClass().getMethod("getConfiguration").invoke(factory); final Method makeParser = configuration.getClass().getMethod("makeParser", String.class); - final InvocationTargetException exception = Assertions - .assertThrows(InvocationTargetException.class, () -> makeParser.invoke(configuration, FailingXMLReader.class.getName())); - final TransformerFactoryConfigurationError error = Assertions - .assertInstanceOf(TransformerFactoryConfigurationError.class, exception.getCause()); - Assertions.assertInstanceOf(SecureException.class, error.getException()); + final InvocationTargetException exception = assertThrows(InvocationTargetException.class, () -> makeParser.invoke(configuration, FailingXMLReader.class.getName())); + final TransformerFactoryConfigurationError error = assertInstanceOf(TransformerFactoryConfigurationError.class, exception.getCause()); + assertInstanceOf(SecureException.class, error.getException()); } } diff --git a/src/test/java/org/apache/commons/xml/SaxonXPathExternalCallsTest.java b/src/test/java/org/apache/commons/xml/SaxonXPathExternalCallsTest.java index 26463f0..a6e6043 100644 --- a/src/test/java/org/apache/commons/xml/SaxonXPathExternalCallsTest.java +++ b/src/test/java/org/apache/commons/xml/SaxonXPathExternalCallsTest.java @@ -29,8 +29,6 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import javax.xml.xpath.XPath; - /** * Checks whether Saxon's XPath 3.1 URI-fetching functions can pull external resources into the result. * diff --git a/src/test/java/org/apache/commons/xml/SchemaFactoryLanguageTest.java b/src/test/java/org/apache/commons/xml/SchemaFactoryLanguageTest.java index cbcc7d8..8fd04bb 100644 --- a/src/test/java/org/apache/commons/xml/SchemaFactoryLanguageTest.java +++ b/src/test/java/org/apache/commons/xml/SchemaFactoryLanguageTest.java @@ -19,11 +19,11 @@ import static org.junit.jupiter.api.Assertions.assertThrows; +import javax.xml.validation.SchemaFactory; + import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import javax.xml.validation.Schema; - /** * Checks that {@link SecureSchemaFactory#newInstance(String)} passes the schema language through to {@link SchemaFactory#newInstance}. * diff --git a/src/test/java/org/apache/commons/xml/SecureDocumentBuilderTest.java b/src/test/java/org/apache/commons/xml/SecureDocumentBuilderTest.java index 1dd599b..7f8ad71 100644 --- a/src/test/java/org/apache/commons/xml/SecureDocumentBuilderTest.java +++ b/src/test/java/org/apache/commons/xml/SecureDocumentBuilderTest.java @@ -21,7 +21,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; + import javax.xml.parsers.DocumentBuilderFactory; + import org.junit.jupiter.api.Test; class SecureDocumentBuilderTest { diff --git a/src/test/java/org/apache/commons/xml/SecureExceptionTest.java b/src/test/java/org/apache/commons/xml/SecureExceptionTest.java index 56dd97e..b7b714c 100644 --- a/src/test/java/org/apache/commons/xml/SecureExceptionTest.java +++ b/src/test/java/org/apache/commons/xml/SecureExceptionTest.java @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.Test; class SecureExceptionTest { diff --git a/src/test/java/org/apache/commons/xml/SecureSAXParserFactoryTest.java b/src/test/java/org/apache/commons/xml/SecureSAXParserFactoryTest.java index 71eb6ed..e5ee56b 100644 --- a/src/test/java/org/apache/commons/xml/SecureSAXParserFactoryTest.java +++ b/src/test/java/org/apache/commons/xml/SecureSAXParserFactoryTest.java @@ -37,8 +37,6 @@ import org.xml.sax.InputSource; import org.xml.sax.XMLReader; -import javax.xml.parsers.SAXParser; - class SecureSAXParserFactoryTest { @Test diff --git a/src/test/java/org/apache/commons/xml/SecureSAXParserTest.java b/src/test/java/org/apache/commons/xml/SecureSAXParserTest.java index 7da57f1..2b9e71a 100644 --- a/src/test/java/org/apache/commons/xml/SecureSAXParserTest.java +++ b/src/test/java/org/apache/commons/xml/SecureSAXParserTest.java @@ -17,15 +17,18 @@ package org.apache.commons.xml; -import java.util.Locale; - import static org.junit.jupiter.api.Assertions.assertNotNull; -import javax.xml.parsers.SAXParserFactory; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; + +import java.util.Locale; import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; import javax.xml.validation.Schema; -import org.junit.jupiter.api.Assertions; + +import org.junit.jupiter.api.Test; import org.xml.sax.DocumentHandler; import org.xml.sax.Parser; import org.xml.sax.SAXNotRecognizedException; @@ -107,13 +110,13 @@ void cachesSecureViewsThenRecreatesThemAfterReset() throws Exception { final SecureSAXParser parser = new SecureSAXParser(SAXParserFactory.newInstance().newSAXParser()); final XMLReader firstReader = parser.getXMLReader(); final Parser firstParser = parser.getParser(); - Assertions.assertSame(firstReader, parser.getXMLReader()); - Assertions.assertSame(firstParser, parser.getParser()); + assertSame(firstReader, parser.getXMLReader()); + assertSame(firstParser, parser.getParser()); parser.setProperty("http://xml.org/sax/properties/lexical-handler", null); - Assertions.assertNull(parser.getProperty("http://xml.org/sax/properties/lexical-handler")); + assertNull(parser.getProperty("http://xml.org/sax/properties/lexical-handler")); parser.reset(); - Assertions.assertNotSame(firstReader, parser.getXMLReader()); - Assertions.assertNotSame(firstParser, parser.getParser()); + assertNotSame(firstReader, parser.getXMLReader()); + assertNotSame(firstParser, parser.getParser()); } @Test @@ -132,6 +135,6 @@ void exposesSecureParserViewsAndState() throws Exception { void reusesAReaderThatAlreadyImplementsSax1Parser() throws Exception { final ParserSecureReader reader = new ParserSecureReader(SAXParserFactory.newInstance().newSAXParser().getXMLReader()); final SecureSAXParser parser = new SecureSAXParser(new ReaderSAXParser(reader)); - Assertions.assertSame(reader, parser.getParser()); + assertSame(reader, parser.getParser()); } } diff --git a/src/test/java/org/apache/commons/xml/SecureSchemaFactoryTest.java b/src/test/java/org/apache/commons/xml/SecureSchemaFactoryTest.java index 087683d..e1ebc2d 100644 --- a/src/test/java/org/apache/commons/xml/SecureSchemaFactoryTest.java +++ b/src/test/java/org/apache/commons/xml/SecureSchemaFactoryTest.java @@ -22,18 +22,19 @@ import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.xml.XMLConstants; -import javax.xml.validation.SchemaFactory; -import org.junit.jupiter.api.Test; -import org.xml.sax.helpers.DefaultHandler; +import javax.xml.XMLConstants; import javax.xml.transform.Source; import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.junit.jupiter.api.Test; import org.w3c.dom.ls.LSResourceResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.helpers.DefaultHandler; class SecureSchemaFactoryTest { diff --git a/src/test/java/org/apache/commons/xml/SecureSchemaTest.java b/src/test/java/org/apache/commons/xml/SecureSchemaTest.java index 69ea9b4..e63c6f2 100644 --- a/src/test/java/org/apache/commons/xml/SecureSchemaTest.java +++ b/src/test/java/org/apache/commons/xml/SecureSchemaTest.java @@ -18,8 +18,10 @@ package org.apache.commons.xml; import static org.junit.jupiter.api.Assertions.assertInstanceOf; + import javax.xml.XMLConstants; import javax.xml.validation.SchemaFactory; + import org.junit.jupiter.api.Test; class SecureSchemaTest { diff --git a/src/test/java/org/apache/commons/xml/SecureTemplatesTest.java b/src/test/java/org/apache/commons/xml/SecureTemplatesTest.java index 79fae25..2879c51 100644 --- a/src/test/java/org/apache/commons/xml/SecureTemplatesTest.java +++ b/src/test/java/org/apache/commons/xml/SecureTemplatesTest.java @@ -24,9 +24,8 @@ import java.io.StringReader; import java.util.Properties; -import javax.xml.transform.Transformer; - import javax.xml.transform.Templates; +import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamSource; diff --git a/src/test/java/org/apache/commons/xml/SecureTransformerFactoryTest.java b/src/test/java/org/apache/commons/xml/SecureTransformerFactoryTest.java index 186c847..327846f 100644 --- a/src/test/java/org/apache/commons/xml/SecureTransformerFactoryTest.java +++ b/src/test/java/org/apache/commons/xml/SecureTransformerFactoryTest.java @@ -17,14 +17,18 @@ package org.apache.commons.xml; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.StringReader; import java.util.HashMap; import java.util.Map; +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.ErrorListener; import javax.xml.transform.Source; import javax.xml.transform.Templates; @@ -32,6 +36,8 @@ import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.URIResolver; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TemplatesHandler; import javax.xml.transform.sax.TransformerHandler; @@ -39,14 +45,8 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.xml.sax.XMLFilter; - -import javax.xml.XMLConstants; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.sax.SAXSource; -import org.junit.jupiter.api.Assertions; import org.xml.sax.InputSource; +import org.xml.sax.XMLFilter; class SecureTransformerFactoryTest { @@ -182,13 +182,13 @@ void preservesNullResultsFromEveryWrappableProduct() throws Exception { assertNull(factory.newTransformerHandler(templates)); assertNull(factory.newXMLFilter(stylesheet())); factory.setAttribute("test", "value"); - Assertions.assertEquals("value", factory.getAttribute("test")); + assertEquals("value", factory.getAttribute("test")); factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); } @Test void rejectsDelegatesThatCannotEnableSecureProcessing() { - Assertions.assertThrows(SecureException.class, () -> SecureTransformerFactory.secure(new RejectingFeatureFactory())); + assertThrows(SecureException.class, () -> SecureTransformerFactory.secure(new RejectingFeatureFactory())); } @Test @@ -213,7 +213,7 @@ void wrapsEveryStandardAndSaxFactoryProduct() throws Exception { assertSame(resolver, factory.getURIResolver()); factory.setErrorListener(factory.getErrorListener()); factory.setAttribute("indent-number", 2); - Assertions.assertThrows(IllegalArgumentException.class, () -> factory.getAttribute("indent-number")); + assertThrows(IllegalArgumentException.class, () -> factory.getAttribute("indent-number")); final Templates templates = factory.newTemplates(stylesheet()); assertInstanceOf(SecureTemplates.class, templates); assertInstanceOf(SecureTransformer.class, factory.newTransformer()); diff --git a/src/test/java/org/apache/commons/xml/SecureTransformerHandlerTest.java b/src/test/java/org/apache/commons/xml/SecureTransformerHandlerTest.java index 78d1015..3e872dc 100644 --- a/src/test/java/org/apache/commons/xml/SecureTransformerHandlerTest.java +++ b/src/test/java/org/apache/commons/xml/SecureTransformerHandlerTest.java @@ -28,7 +28,6 @@ import org.junit.jupiter.api.Test; import org.xml.sax.helpers.AttributesImpl; - import org.xml.sax.helpers.LocatorImpl; class SecureTransformerHandlerTest { diff --git a/src/test/java/org/apache/commons/xml/SecureTransformerTest.java b/src/test/java/org/apache/commons/xml/SecureTransformerTest.java index ba3f6c0..3393e6e 100644 --- a/src/test/java/org/apache/commons/xml/SecureTransformerTest.java +++ b/src/test/java/org/apache/commons/xml/SecureTransformerTest.java @@ -23,18 +23,17 @@ import java.io.StringWriter; import java.util.Properties; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.ErrorListener; import javax.xml.transform.OutputKeys; +import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import javax.xml.parsers.DocumentBuilderFactory; import org.junit.jupiter.api.Test; -import javax.xml.transform.ErrorListener; -import javax.xml.transform.TransformerException; - class SecureTransformerTest { @Test diff --git a/src/test/java/org/apache/commons/xml/SecureValidatorHandlerTest.java b/src/test/java/org/apache/commons/xml/SecureValidatorHandlerTest.java index 6bc46ff..f3d4721 100644 --- a/src/test/java/org/apache/commons/xml/SecureValidatorHandlerTest.java +++ b/src/test/java/org/apache/commons/xml/SecureValidatorHandlerTest.java @@ -26,6 +26,7 @@ import javax.xml.XMLConstants; import javax.xml.validation.SchemaFactory; +import javax.xml.validation.TypeInfoProvider; import javax.xml.validation.ValidatorHandler; import org.junit.jupiter.api.Test; @@ -39,7 +40,6 @@ import org.xml.sax.SAXParseException; import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.DefaultHandler; -import javax.xml.validation.TypeInfoProvider; class SecureValidatorHandlerTest { diff --git a/src/test/java/org/apache/commons/xml/SecureValidatorTest.java b/src/test/java/org/apache/commons/xml/SecureValidatorTest.java index 651bab1..4003d2f 100644 --- a/src/test/java/org/apache/commons/xml/SecureValidatorTest.java +++ b/src/test/java/org/apache/commons/xml/SecureValidatorTest.java @@ -23,21 +23,21 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.xml.XMLConstants; -import javax.xml.validation.SchemaFactory; - -import org.junit.jupiter.api.Test; -import org.xml.sax.helpers.DefaultHandler; - import java.io.IOException; + +import javax.xml.XMLConstants; import javax.xml.transform.Result; import javax.xml.transform.Source; +import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; + +import org.junit.jupiter.api.Test; import org.w3c.dom.ls.LSResourceResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.helpers.DefaultHandler; class SecureValidatorTest { diff --git a/src/test/java/org/apache/commons/xml/SecureXMLFilterTest.java b/src/test/java/org/apache/commons/xml/SecureXMLFilterTest.java index c4530e4..8ff4b79 100644 --- a/src/test/java/org/apache/commons/xml/SecureXMLFilterTest.java +++ b/src/test/java/org/apache/commons/xml/SecureXMLFilterTest.java @@ -17,6 +17,8 @@ package org.apache.commons.xml; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -25,25 +27,23 @@ import java.util.Properties; import java.util.concurrent.atomic.AtomicInteger; +import javax.xml.transform.ErrorListener; import javax.xml.transform.Result; +import javax.xml.transform.Source; import javax.xml.transform.Templates; import javax.xml.transform.Transformer; -import javax.xml.transform.URIResolver; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; +import javax.xml.transform.URIResolver; import javax.xml.transform.stream.StreamSource; import org.junit.jupiter.api.Test; +import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; -import org.xml.sax.helpers.DefaultHandler; - -import javax.xml.transform.ErrorListener; -import javax.xml.transform.Source; -import org.junit.jupiter.api.Assertions; -import org.xml.sax.Attributes; import org.xml.sax.ext.DefaultHandler2; +import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.XMLFilterImpl; class SecureXMLFilterTest { @@ -66,7 +66,7 @@ public void startElement(final String uri, final String localName, final String } }); final SAXException exception = assertThrows(SAXException.class, () -> filter.parse(new InputSource(new StringReader("<root/>")))); - Assertions.assertEquals("handler", exception.getMessage()); + assertEquals("handler", exception.getMessage()); } @Test @@ -94,7 +94,7 @@ public void warning(final SAXParseException e) { filter.error(new TransformerException("error", new SAXParseException("cause", null))); final TransformerException fatal = new TransformerException("fatal"); assertSame(fatal, assertThrows(TransformerException.class, () -> filter.fatalError(fatal))); - Assertions.assertEquals(3, reports.get()); + assertEquals(3, reports.get()); } @Test @@ -189,7 +189,7 @@ public void transform(final Source source, final Result result) throws Transform final SecureXMLFilter filter = new SecureXMLFilter(new SecureTemplates(templates, null, null, false)); filter.setContentHandler(new DefaultHandler()); final IOException exception = assertThrows(IOException.class, () -> filter.parse(new InputSource(new StringReader("<root/>")))); - Assertions.assertEquals("transform", exception.getMessage()); + assertEquals("transform", exception.getMessage()); } @Test @@ -229,6 +229,6 @@ public void parse(final InputSource input) throws IOException { } }); final SAXException exception = assertThrows(SAXException.class, () -> filter.parse(new InputSource(new StringReader("<root/>")))); - Assertions.assertNotNull(exception.getCause()); + assertNotNull(exception.getCause()); } } diff --git a/src/test/java/org/apache/commons/xml/SecureXMLReaderTest.java b/src/test/java/org/apache/commons/xml/SecureXMLReaderTest.java index 0016602..f7be826 100644 --- a/src/test/java/org/apache/commons/xml/SecureXMLReaderTest.java +++ b/src/test/java/org/apache/commons/xml/SecureXMLReaderTest.java @@ -17,14 +17,17 @@ package org.apache.commons.xml; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; import java.io.StringReader; + import javax.xml.parsers.SAXParserFactory; + import org.junit.jupiter.api.Test; import org.xml.sax.InputSource; import org.xml.sax.helpers.DefaultHandler; - -import java.io.IOException; -import org.junit.jupiter.api.Assertions; import org.xml.sax.helpers.XMLFilterImpl; class SecureXMLReaderTest { @@ -52,8 +55,8 @@ void forwardsBothParseOverloads() throws Exception { final SecureXMLReader reader = new SecureXMLReader(delegate); reader.parse(new InputSource()); reader.parse("system"); - Assertions.assertTrue(delegate.inputSourceParsed); - Assertions.assertTrue(delegate.systemIdParsed); + assertTrue(delegate.inputSourceParsed); + assertTrue(delegate.systemIdParsed); } @Test @@ -69,6 +72,6 @@ void forwardsReaderConfigurationAndParse() throws Exception { reader.getErrorHandler(); reader.getEntityResolver(); reader.parse(new InputSource(new StringReader("<root/>"))); - Assertions.assertThrows(IOException.class, () -> reader.parse("file:/definitely-not-present-commons-xml-test.xml")); + assertThrows(IOException.class, () -> reader.parse("file:/definitely-not-present-commons-xml-test.xml")); } } diff --git a/src/test/java/org/apache/commons/xml/SecureXPathExpressionTest.java b/src/test/java/org/apache/commons/xml/SecureXPathExpressionTest.java index d0f29b0..4622fbc 100644 --- a/src/test/java/org/apache/commons/xml/SecureXPathExpressionTest.java +++ b/src/test/java/org/apache/commons/xml/SecureXPathExpressionTest.java @@ -21,14 +21,12 @@ import java.io.StringReader; +import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; import org.junit.jupiter.api.Test; import org.xml.sax.InputSource; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; - class SecureXPathExpressionTest { @Test diff --git a/src/test/java/org/apache/commons/xml/SecureXPathFactoryTest.java b/src/test/java/org/apache/commons/xml/SecureXPathFactoryTest.java index 1fe8bea..170d8a0 100644 --- a/src/test/java/org/apache/commons/xml/SecureXPathFactoryTest.java +++ b/src/test/java/org/apache/commons/xml/SecureXPathFactoryTest.java @@ -20,16 +20,16 @@ import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.xml.xpath.XPathFactory; - -import org.junit.jupiter.api.Test; import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathFactoryConfigurationException; import javax.xml.xpath.XPathFunctionResolver; import javax.xml.xpath.XPathVariableResolver; -import org.junit.jupiter.api.Assertions; + +import org.junit.jupiter.api.Test; class SecureXPathFactoryTest { @@ -118,6 +118,6 @@ public void setXPathFunctionResolver(final XPathFunctionResolver resolver) { public void setXPathVariableResolver(final XPathVariableResolver resolver) { } }; - Assertions.assertThrows(SecureException.class, () -> SecureXPathFactory.secure(rejectingFactory)); + assertThrows(SecureException.class, () -> SecureXPathFactory.secure(rejectingFactory)); } } diff --git a/src/test/java/org/apache/commons/xml/SecureXPathTest.java b/src/test/java/org/apache/commons/xml/SecureXPathTest.java index 0c05576..87cac5d 100644 --- a/src/test/java/org/apache/commons/xml/SecureXPathTest.java +++ b/src/test/java/org/apache/commons/xml/SecureXPathTest.java @@ -28,19 +28,18 @@ import javax.xml.XMLConstants; import javax.xml.namespace.NamespaceContext; -import javax.xml.xpath.XPathFactory; - -import org.junit.jupiter.api.Test; -import org.xml.sax.InputSource; - import javax.xml.namespace.QName; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathFunctionResolver; import javax.xml.xpath.XPathVariableResolver; +import org.junit.jupiter.api.Test; +import org.xml.sax.InputSource; + class SecureXPathTest { @Test diff --git a/src/test/java/org/apache/commons/xml/XPathInputSourceTest.java b/src/test/java/org/apache/commons/xml/XPathInputSourceTest.java index 34bb534..d276434 100644 --- a/src/test/java/org/apache/commons/xml/XPathInputSourceTest.java +++ b/src/test/java/org/apache/commons/xml/XPathInputSourceTest.java @@ -25,7 +25,6 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; - import org.xml.sax.InputSource; /**
