3131import java .net .URL ;
3232import java .net .URLConnection ;
3333import java .nio .charset .StandardCharsets ;
34+ import java .nio .file .Files ;
3435import java .nio .file .Path ;
36+ import java .nio .file .Paths ;
3537import java .text .MessageFormat ;
3638import java .util .HashMap ;
3739import java .util .Map ;
@@ -163,6 +165,7 @@ public void testAlternateDefaultEncoding(final String cT, final String bomEnc, f
163165 throws Exception {
164166 try (InputStream is = getXmlInputStream (bomEnc , prologEnc == null ? XML1 : XML3 , streamEnc , prologEnc );
165167 XmlStreamReader xmlReader = new XmlStreamReader (is , cT , false , alternateEnc )) {
168+ assertEquals (xmlReader .getDefaultEncoding (), alternateEnc );
166169 if (!streamEnc .equals (UTF_16 )) {
167170 // we can not assert things here because UTF-8, US-ASCII and
168171 // ISO-8859-1 look alike for the chars used for detection
@@ -176,6 +179,65 @@ public void testAlternateDefaultEncoding(final String cT, final String bomEnc, f
176179 }
177180 }
178181
182+ @ Test
183+ protected void testConstructorFileInput () throws IOException {
184+ try (XmlStreamReader reader = new XmlStreamReader (new File ("pom.xml" ))) {
185+ // do nothing
186+ }
187+ }
188+
189+ @ Test
190+ protected void testConstructorFileInputNull () {
191+ assertThrows (NullPointerException .class , () -> new XmlStreamReader ((File ) null ));
192+ }
193+
194+ @ Test
195+ protected void testConstructorInputStreamInput () throws IOException {
196+ try (XmlStreamReader reader = new XmlStreamReader (Files .newInputStream (Paths .get ("pom.xml" )))) {
197+ // do nothing
198+ }
199+ }
200+
201+ @ Test
202+ protected void testConstructorInputStreamInputNull () {
203+ assertThrows (NullPointerException .class , () -> new XmlStreamReader ((InputStream ) null ));
204+ }
205+
206+ protected void testConstructorPathInput () throws IOException {
207+ try (XmlStreamReader reader = new XmlStreamReader (Paths .get ("pom.xml" ))) {
208+ // do nothing
209+ }
210+ }
211+
212+ @ Test
213+ protected void testConstructorPathInputNull () {
214+ assertThrows (NullPointerException .class , () -> new XmlStreamReader ((Path ) null ));
215+ }
216+
217+ @ Test
218+ protected void testConstructorURLConnectionInput () throws IOException {
219+ try (XmlStreamReader reader = new XmlStreamReader (new URL ("https://www.apache.org/" ).openConnection (), UTF_8 )) {
220+ // do nothing
221+ }
222+ }
223+
224+ @ Test
225+ protected void testConstructorURLConnectionInputNull () {
226+ assertThrows (NullPointerException .class , () -> new XmlStreamReader ((URLConnection ) null , US_ASCII ));
227+ }
228+
229+ @ Test
230+ protected void testConstructorURLInput () throws IOException {
231+ try (XmlStreamReader reader = new XmlStreamReader (new URL ("https://www.apache.org/" ))) {
232+ // do nothing
233+ }
234+ }
235+
236+ @ Test
237+ protected void testConstructorURLInputNull () throws IOException {
238+ assertThrows (NullPointerException .class , () -> new XmlStreamReader ((URL ) null ));
239+ }
240+
179241 @ Test
180242 public void testEncodingAttributeXML () throws Exception {
181243 try (InputStream is = new ByteArrayInputStream (ENCODING_ATTRIBUTE_XML .getBytes (StandardCharsets .UTF_8 ));
@@ -184,6 +246,8 @@ public void testEncodingAttributeXML() throws Exception {
184246 }
185247 }
186248
249+ // XML Stream generator
250+
187251 @ Test
188252 public void testHttp () throws Exception {
189253 // niallp 2010-10-06 - remove following 2 tests - I reinstated
@@ -333,33 +397,6 @@ public void testLowerCaseEncodingWithTurkishLocale_IO_557() throws Exception {
333397 }
334398 }
335399
336- @ Test
337- protected void testNullFileInput () {
338- assertThrows (NullPointerException .class , () -> new XmlStreamReader ((File ) null ));
339- }
340-
341- @ Test
342- protected void testNullInputStreamInput () {
343- assertThrows (NullPointerException .class , () -> new XmlStreamReader ((InputStream ) null ));
344- }
345-
346- @ Test
347- protected void testNullPathInput () {
348- assertThrows (NullPointerException .class , () -> new XmlStreamReader ((Path ) null ));
349- }
350-
351- // XML Stream generator
352-
353- @ Test
354- protected void testNullURLConnectionInput () {
355- assertThrows (NullPointerException .class , () -> new XmlStreamReader ((URLConnection ) null , US_ASCII ));
356- }
357-
358- @ Test
359- protected void testNullURLInput () {
360- assertThrows (NullPointerException .class , () -> new XmlStreamReader ((URL ) null ));
361- }
362-
363400 protected void testRawBomInvalid (final String bomEnc , final String streamEnc ,
364401 final String prologEnc ) throws Exception {
365402 final InputStream is = getXmlInputStream (bomEnc , XML3 , streamEnc , prologEnc );
0 commit comments