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 <garydgreg...@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); } }