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-codec.git


The following commit(s) were added to refs/heads/master by this push:
     new 299d22b8 Use StandardCharsets instead of magic string
299d22b8 is described below

commit 299d22b8b6f0c02fa67de6ff2757cc9c8771a275
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Fri Dec 15 16:21:28 2023 -0500

    Use StandardCharsets instead of magic string
---
 .../java/org/apache/commons/codec/CharEncodingTest.java    | 14 ++++++++------
 .../org/apache/commons/codec/binary/StringUtilsTest.java   |  8 ++++----
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/test/java/org/apache/commons/codec/CharEncodingTest.java 
b/src/test/java/org/apache/commons/codec/CharEncodingTest.java
index 0e8f74a3..9f2ee604 100644
--- a/src/test/java/org/apache/commons/codec/CharEncodingTest.java
+++ b/src/test/java/org/apache/commons/codec/CharEncodingTest.java
@@ -19,6 +19,8 @@ package org.apache.commons.codec;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+import java.nio.charset.StandardCharsets;
+
 import org.junit.jupiter.api.Test;
 
 /**
@@ -36,32 +38,32 @@ public class CharEncodingTest {
 
     @Test
     public void testIso8859_1() {
-        assertEquals("ISO-8859-1", CharEncoding.ISO_8859_1);
+        assertEquals(StandardCharsets.ISO_8859_1.name(), 
CharEncoding.ISO_8859_1);
     }
 
     @Test
     public void testUsAscii() {
-        assertEquals("US-ASCII", CharEncoding.US_ASCII);
+        assertEquals(StandardCharsets.US_ASCII.name(), CharEncoding.US_ASCII);
     }
 
     @Test
     public void testUtf16() {
-        assertEquals("UTF-16", CharEncoding.UTF_16);
+        assertEquals(StandardCharsets.UTF_16.name(), CharEncoding.UTF_16);
     }
 
     @Test
     public void testUtf16Be() {
-        assertEquals("UTF-16BE", CharEncoding.UTF_16BE);
+        assertEquals(StandardCharsets.UTF_16BE.name(), CharEncoding.UTF_16BE);
     }
 
     @Test
     public void testUtf16Le() {
-        assertEquals("UTF-16LE", CharEncoding.UTF_16LE);
+        assertEquals(StandardCharsets.UTF_16LE.name(), CharEncoding.UTF_16LE);
     }
 
     @Test
     public void testUtf8() {
-        assertEquals("UTF-8", CharEncoding.UTF_8);
+        assertEquals(StandardCharsets.UTF_8.name(), CharEncoding.UTF_8);
     }
 
 }
diff --git a/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java 
b/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java
index af115d8d..878e0473 100644
--- a/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java
@@ -198,7 +198,7 @@ public class StringUtilsTest {
 
     @Test
     public void testNewStringUsAscii() throws UnsupportedEncodingException {
-        final String charsetName = "US-ASCII";
+        final String charsetName = StandardCharsets.US_ASCII.name();
         testNewString(charsetName);
         final String expected = new String(BYTES_FIXTURE, charsetName);
         final String actual = StringUtils.newStringUsAscii(BYTES_FIXTURE);
@@ -207,7 +207,7 @@ public class StringUtilsTest {
 
     @Test
     public void testNewStringUtf16() throws UnsupportedEncodingException {
-        final String charsetName = "UTF-16";
+        final String charsetName = StandardCharsets.UTF_16.name();
         testNewString(charsetName);
         final String expected = new String(BYTES_FIXTURE, charsetName);
         final String actual = StringUtils.newStringUtf16(BYTES_FIXTURE);
@@ -216,7 +216,7 @@ public class StringUtilsTest {
 
     @Test
     public void testNewStringUtf16Be() throws UnsupportedEncodingException {
-        final String charsetName = "UTF-16BE";
+        final String charsetName = StandardCharsets.UTF_16BE.name();
         testNewString(charsetName);
         final String expected = new String(BYTES_FIXTURE_16BE, charsetName);
         final String actual = StringUtils.newStringUtf16Be(BYTES_FIXTURE_16BE);
@@ -225,7 +225,7 @@ public class StringUtilsTest {
 
     @Test
     public void testNewStringUtf16Le() throws UnsupportedEncodingException {
-        final String charsetName = "UTF-16LE";
+        final String charsetName = StandardCharsets.UTF_16LE.name();
         testNewString(charsetName);
         final String expected = new String(BYTES_FIXTURE_16LE, charsetName);
         final String actual = StringUtils.newStringUtf16Le(BYTES_FIXTURE_16LE);

Reply via email to