This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push: new 10079fda Add missing XmlStreamReader test 10079fda is described below commit 10079fda26607ce4591fe65e6e0447ca1bd10900 Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Tue Jul 26 09:01:07 2022 -0400 Add missing XmlStreamReader test --- .../commons/io/input/XmlStreamReaderTest.java | 91 +++++++++++++++------- 1 file changed, 64 insertions(+), 27 deletions(-) diff --git a/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java b/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java index 4acb4d9b..312577c7 100644 --- a/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java +++ b/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java @@ -31,7 +31,9 @@ import java.io.Writer; import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; @@ -163,6 +165,7 @@ public class XmlStreamReaderTest { throws Exception { try (InputStream is = getXmlInputStream(bomEnc, prologEnc == null ? XML1 : XML3, streamEnc, prologEnc); XmlStreamReader xmlReader = new XmlStreamReader(is, cT, false, alternateEnc)) { + assertEquals(xmlReader.getDefaultEncoding(), alternateEnc); if (!streamEnc.equals(UTF_16)) { // we can not assert things here because UTF-8, US-ASCII and // ISO-8859-1 look alike for the chars used for detection @@ -176,6 +179,65 @@ public class XmlStreamReaderTest { } } + @Test + protected void testConstructorFileInput() throws IOException { + try (XmlStreamReader reader = new XmlStreamReader(new File("pom.xml"))) { + // do nothing + } + } + + @Test + protected void testConstructorFileInputNull() { + assertThrows(NullPointerException.class, () -> new XmlStreamReader((File) null)); + } + + @Test + protected void testConstructorInputStreamInput() throws IOException { + try (XmlStreamReader reader = new XmlStreamReader(Files.newInputStream(Paths.get("pom.xml")))) { + // do nothing + } + } + + @Test + protected void testConstructorInputStreamInputNull() { + assertThrows(NullPointerException.class, () -> new XmlStreamReader((InputStream) null)); + } + + protected void testConstructorPathInput() throws IOException { + try (XmlStreamReader reader = new XmlStreamReader(Paths.get("pom.xml"))) { + // do nothing + } + } + + @Test + protected void testConstructorPathInputNull() { + assertThrows(NullPointerException.class, () -> new XmlStreamReader((Path) null)); + } + + @Test + protected void testConstructorURLConnectionInput() throws IOException { + try (XmlStreamReader reader = new XmlStreamReader(new URL("https://www.apache.org/").openConnection(), UTF_8)) { + // do nothing + } + } + + @Test + protected void testConstructorURLConnectionInputNull() { + assertThrows(NullPointerException.class, () -> new XmlStreamReader((URLConnection) null, US_ASCII)); + } + + @Test + protected void testConstructorURLInput() throws IOException { + try (XmlStreamReader reader = new XmlStreamReader(new URL("https://www.apache.org/"))) { + // do nothing + } + } + + @Test + protected void testConstructorURLInputNull() throws IOException { + assertThrows(NullPointerException.class, () -> new XmlStreamReader((URL) null)); + } + @Test public void testEncodingAttributeXML() throws Exception { try (InputStream is = new ByteArrayInputStream(ENCODING_ATTRIBUTE_XML.getBytes(StandardCharsets.UTF_8)); @@ -184,6 +246,8 @@ public class XmlStreamReaderTest { } } + // XML Stream generator + @Test public void testHttp() throws Exception { // niallp 2010-10-06 - remove following 2 tests - I reinstated @@ -333,33 +397,6 @@ public class XmlStreamReaderTest { } } - @Test - protected void testNullFileInput() { - assertThrows(NullPointerException.class, () -> new XmlStreamReader((File) null)); - } - - @Test - protected void testNullInputStreamInput() { - assertThrows(NullPointerException.class, () -> new XmlStreamReader((InputStream) null)); - } - - @Test - protected void testNullPathInput() { - assertThrows(NullPointerException.class, () -> new XmlStreamReader((Path) null)); - } - - // XML Stream generator - - @Test - protected void testNullURLConnectionInput() { - assertThrows(NullPointerException.class, () -> new XmlStreamReader((URLConnection) null, US_ASCII)); - } - - @Test - protected void testNullURLInput() { - assertThrows(NullPointerException.class, () -> new XmlStreamReader((URL) null)); - } - protected void testRawBomInvalid(final String bomEnc, final String streamEnc, final String prologEnc) throws Exception { final InputStream is = getXmlInputStream(bomEnc, XML3, streamEnc, prologEnc);