4242import java .util .Map ;
4343
4444import org .apache .commons .io .IOUtils ;
45+ import org .apache .commons .io .function .IOFunction ;
4546import org .junit .jupiter .api .Test ;
4647import org .junitpioneer .jupiter .DefaultLocale ;
4748
@@ -573,11 +574,10 @@ public void testRawNoBomUtf8() throws Exception {
573574 testRawNoBomValid (UTF_8 );
574575 }
575576
576- private void parseCharset (final String hdr , final String enc ) throws Exception {
577+ private void parseCharset (final String hdr , final String enc , final IOFunction < InputStream , XmlStreamReader > factory ) throws Exception {
577578 try (final InputStream stream = new ByteArrayInputStream (hdr .getBytes (StandardCharsets .UTF_8 ))) {
578- try (final XmlStreamReader xml = new XmlStreamReader (stream )) {
579- final String getenc = xml .getEncoding ();
580- assertEquals (enc .toUpperCase (Locale .ROOT ), getenc , enc );
579+ try (final XmlStreamReader xml = factory .apply (stream )) {
580+ assertEquals (enc .toUpperCase (Locale .ROOT ), xml .getEncoding (), enc );
581581 }
582582 }
583583 }
@@ -587,9 +587,13 @@ public void testIO_815() throws Exception {
587587 final MessageFormat fmt = new MessageFormat ("<?xml version=\" 1.0\" encoding=''{0}''?>\n <root>text</root>" );
588588 for (final Map .Entry <String , Charset > entry : Charset .availableCharsets ().entrySet ()) {
589589 final String csName = entry .getKey ();
590- parseCharset (fmt .format (new Object [] { csName }), csName );
590+ final IOFunction <InputStream , XmlStreamReader > factoryCtor = XmlStreamReader ::new ;
591+ final IOFunction <InputStream , XmlStreamReader > factoryBuilder = stream -> XmlStreamReader .builder ().setInputStream (stream ).get ();
592+ parseCharset (fmt .format (new Object [] { csName }), csName , factoryCtor );
593+ parseCharset (fmt .format (new Object [] { csName }), csName , factoryBuilder );
591594 for (final String alias : entry .getValue ().aliases ()) {
592- parseCharset (fmt .format (new Object [] { alias }), alias );
595+ parseCharset (fmt .format (new Object [] { alias }), alias , factoryCtor );
596+ parseCharset (fmt .format (new Object [] { alias }), alias , factoryBuilder );
593597 }
594598 }
595599 }
0 commit comments