You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/10/04 12:49:43 UTC

[commons-io] branch master updated (9aa8605b -> e47f5ade)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


    from 9aa8605b [IO-815] More XmlStreamReader testing: ctor and builder
     new cdf60c96 Tests using JUnit 5 constructs
     new aaad426a Tests using JUnit 5 constructs
     new e47f5ade Tests using JUnit 5 constructs

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/commons/io/CharsetsTest.java   | 15 +++++++++
 .../io/input/CharSequenceInputStreamTest.java      | 39 +++++++++++-----------
 .../commons/io/input/XmlStreamReaderTest.java      | 25 +++++++-------
 3 files changed, 48 insertions(+), 31 deletions(-)


[commons-io] 03/03: Tests using JUnit 5 constructs

Posted by gg...@apache.org.
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

commit e47f5ade7f004ef404e0011b7ecebccc65c29da6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Oct 4 08:49:38 2023 -0400

    Tests using JUnit 5 constructs
---
 .../commons/io/input/XmlStreamReaderTest.java      | 25 +++++++++++-----------
 1 file changed, 13 insertions(+), 12 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 1b40d09f..4c9fc0ad 100644
--- a/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
+++ b/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
@@ -41,9 +41,12 @@ import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 
+import org.apache.commons.io.CharsetsTest;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.function.IOFunction;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.junitpioneer.jupiter.DefaultLocale;
 
 public class XmlStreamReaderTest {
@@ -582,19 +585,17 @@ public class XmlStreamReaderTest {
         }
     }
 
-    @Test
-    public void testIO_815() throws Exception {
+    @ParameterizedTest(name = "{0}")
+    @MethodSource(CharsetsTest.AVAIL_CHARSETS)
+    public void testIO_815(final String csName) throws Exception {
         final MessageFormat fmt = new MessageFormat("<?xml version=\"1.0\" encoding=''{0}''?>\n<root>text</root>");
-        for (final Map.Entry<String, Charset> entry : Charset.availableCharsets().entrySet()) {
-            final String csName = entry.getKey();
-            final IOFunction<InputStream, XmlStreamReader> factoryCtor = XmlStreamReader::new;
-            final IOFunction<InputStream, XmlStreamReader> factoryBuilder = stream ->  XmlStreamReader.builder().setInputStream(stream).get();
-            parseCharset(fmt.format(new Object[] { csName }), csName, factoryCtor);
-            parseCharset(fmt.format(new Object[] { csName }), csName, factoryBuilder);
-            for (final String alias : entry.getValue().aliases()) {
-                parseCharset(fmt.format(new Object[] { alias }), alias, factoryCtor);
-                parseCharset(fmt.format(new Object[] { alias }), alias, factoryBuilder);
-            }
+        final IOFunction<InputStream, XmlStreamReader> factoryCtor = XmlStreamReader::new;
+        final IOFunction<InputStream, XmlStreamReader> factoryBuilder = stream -> XmlStreamReader.builder().setInputStream(stream).get();
+        parseCharset(fmt.format(new Object[] { csName }), csName, factoryCtor);
+        parseCharset(fmt.format(new Object[] { csName }), csName, factoryBuilder);
+        for (final String alias : Charset.forName(csName).aliases()) {
+            parseCharset(fmt.format(new Object[] { alias }), alias, factoryCtor);
+            parseCharset(fmt.format(new Object[] { alias }), alias, factoryBuilder);
         }
     }
 


[commons-io] 02/03: Tests using JUnit 5 constructs

Posted by gg...@apache.org.
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

commit aaad426aae8bda4e7b2978829f1bd1b1219df944
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Oct 4 08:48:05 2023 -0400

    Tests using JUnit 5 constructs
---
 .../commons/io/input/CharSequenceInputStreamTest.java       | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java b/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
index df627061..a8e06b81 100644
--- a/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
@@ -159,13 +159,12 @@ public class CharSequenceInputStreamTest {
 //        at sun.nio.cs.ext.COMPOUND_TEXT_Encoder.encodeLoop(COMPOUND_TEXT_Encoder.java:75)
 //        at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:544)
 //        at org.apache.commons.io.input.CharSequenceInputStream.fillBuffer(CharSequenceInputStream.java:111)
-    @Test
-    public void testBufferedRead_AvailableCharset() throws IOException {
-        for (final String csName : Charset.availableCharsets().keySet()) {
-            // prevent java.lang.UnsupportedOperationException at sun.nio.cs.ext.ISO2022_CN.newEncoder.
-            if (isAvailabilityTestableForCharset(csName)) {
-                testBufferedRead(TEST_STRING, csName);
-            }
+    @ParameterizedTest(name = "{0}")
+    @MethodSource(CharsetsTest.AVAIL_CHARSETS)
+    public void testBufferedRead_AvailableCharset(final String csName) throws IOException {
+        // prevent java.lang.UnsupportedOperationException at sun.nio.cs.ext.ISO2022_CN.newEncoder.
+        if (isAvailabilityTestableForCharset(csName)) {
+            testBufferedRead(TEST_STRING, csName);
         }
     }
 


[commons-io] 01/03: Tests using JUnit 5 constructs

Posted by gg...@apache.org.
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

commit cdf60c96f6fdc3050eb75325601b386f068ae0b5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Oct 4 08:47:15 2023 -0400

    Tests using JUnit 5 constructs
---
 .../java/org/apache/commons/io/CharsetsTest.java   | 15 +++++++++++++
 .../io/input/CharSequenceInputStreamTest.java      | 26 ++++++++++++----------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/CharsetsTest.java b/src/test/java/org/apache/commons/io/CharsetsTest.java
index b68b90b6..7c988978 100644
--- a/src/test/java/org/apache/commons/io/CharsetsTest.java
+++ b/src/test/java/org/apache/commons/io/CharsetsTest.java
@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
+import java.util.Set;
 import java.util.SortedMap;
 
 import org.junit.jupiter.api.Test;
@@ -31,6 +32,20 @@ import org.junit.jupiter.api.Test;
 @SuppressWarnings("deprecation") // testing deprecated code
 public class CharsetsTest {
 
+    /**
+     * For parameterized tests.
+     */
+    public static final String AVAIL_CHARSETS = "org.apache.commons.io.CharsetsTest#availableCharsetsKeySet";
+
+    /**
+     * For parameterized tests.
+     *
+     * @return {@code Charset.availableCharsets().keySet()}.
+     */
+    public static Set<String> availableCharsetsKeySet() {
+        return Charset.availableCharsets().keySet();
+    }
+
     @Test
     public void testIso8859_1() {
         assertEquals("ISO-8859-1", Charsets.ISO_8859_1.name());
diff --git a/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java b/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
index 7bc997e0..df627061 100644
--- a/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
@@ -32,9 +32,12 @@ import java.util.Random;
 import java.util.Set;
 
 import org.apache.commons.io.Charsets;
+import org.apache.commons.io.CharsetsTest;
 import org.apache.commons.io.IOUtils;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 
 public class CharSequenceInputStreamTest {
 
@@ -78,11 +81,11 @@ public class CharSequenceInputStreamTest {
                 "Shift_JIS".equalsIgnoreCase(csName);
     }
 
-    @Test
-    public void testAvailable() throws Exception {
-        for (final String csName : Charset.availableCharsets().keySet()) {
-            // prevent java.lang.UnsupportedOperationException at sun.nio.cs.ext.ISO2022_CN.newEncoder.
-            // also try and avoid the following exception
+    @ParameterizedTest(name = "{0}")
+    @MethodSource(CharsetsTest.AVAIL_CHARSETS)
+    public void testAvailable(final String csName) throws Exception {
+        // prevent java.lang.UnsupportedOperationException at sun.nio.cs.ext.ISO2022_CN.newEncoder.
+        // also try and avoid the following exception
 //            java.lang.UnsupportedOperationException: null
 //            at java.nio.CharBuffer.array(CharBuffer.java:940)
 //            at sun.nio.cs.ext.COMPOUND_TEXT_Encoder.encodeLoop(COMPOUND_TEXT_Encoder.java:75)
@@ -92,14 +95,13 @@ public class CharSequenceInputStreamTest {
 //            at org.apache.commons.io.input.CharSequenceInputStreamTest.testAvailableRead(CharSequenceInputStreamTest.java:412)
 //            at org.apache.commons.io.input.CharSequenceInputStreamTest.testAvailable(CharSequenceInputStreamTest.java:424)
 
-            try {
-                if (isAvailabilityTestableForCharset(csName)) {
-                    testAvailableSkip(csName);
-                    testAvailableRead(csName);
-                }
-            } catch (final UnsupportedOperationException e){
-                fail("Operation not supported for " + csName);
+        try {
+            if (isAvailabilityTestableForCharset(csName)) {
+                testAvailableSkip(csName);
+                testAvailableRead(csName);
             }
+        } catch (final UnsupportedOperationException e) {
+            fail("Operation not supported for " + csName);
         }
     }