Skip to content

Commit 18b76b6

Browse files
committed
Use StandardCharsets instead of magic string
1 parent a3e2330 commit 18b76b6

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/test/java/org/apache/commons/codec/CharsetsTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,31 @@ public void testToCharset() {
6060
@SuppressWarnings("deprecation")
6161
@Test
6262
public void testUsAscii() {
63-
assertEquals("US-ASCII", Charsets.US_ASCII.name());
63+
assertEquals(StandardCharsets.US_ASCII.name(), Charsets.US_ASCII.name());
6464
}
6565

6666
@SuppressWarnings("deprecation")
6767
@Test
6868
public void testUtf16() {
69-
assertEquals("UTF-16", Charsets.UTF_16.name());
69+
assertEquals(StandardCharsets.UTF_16.name(), Charsets.UTF_16.name());
7070
}
7171

7272
@SuppressWarnings("deprecation")
7373
@Test
7474
public void testUtf16Be() {
75-
assertEquals("UTF-16BE", Charsets.UTF_16BE.name());
75+
assertEquals(StandardCharsets.UTF_16BE.name(), Charsets.UTF_16BE.name());
7676
}
7777

7878
@SuppressWarnings("deprecation")
7979
@Test
8080
public void testUtf16Le() {
81-
assertEquals("UTF-16LE", Charsets.UTF_16LE.name());
81+
assertEquals(StandardCharsets.UTF_16LE.name(), Charsets.UTF_16LE.name());
8282
}
8383

8484
@SuppressWarnings("deprecation")
8585
@Test
8686
public void testUtf8() {
87-
assertEquals("UTF-8", Charsets.UTF_8.name());
87+
assertEquals(StandardCharsets.UTF_8.name(), Charsets.UTF_8.name());
8888
}
8989

9090
}

src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void testGetBytesUsAscii() throws UnsupportedEncodingException {
127127

128128
@Test
129129
public void testGetBytesUtf16() throws UnsupportedEncodingException {
130-
final String charsetName = "UTF-16";
130+
final String charsetName = StandardCharsets.UTF_16.name();
131131
testGetBytesUnchecked(charsetName);
132132
final byte[] expected = STRING_FIXTURE.getBytes(charsetName);
133133
final byte[] actual = StringUtils.getBytesUtf16(STRING_FIXTURE);
@@ -136,7 +136,7 @@ public void testGetBytesUtf16() throws UnsupportedEncodingException {
136136

137137
@Test
138138
public void testGetBytesUtf16Be() throws UnsupportedEncodingException {
139-
final String charsetName = "UTF-16BE";
139+
final String charsetName = StandardCharsets.UTF_16BE.name();
140140
testGetBytesUnchecked(charsetName);
141141
final byte[] expected = STRING_FIXTURE.getBytes(charsetName);
142142
final byte[] actual = StringUtils.getBytesUtf16Be(STRING_FIXTURE);
@@ -145,7 +145,7 @@ public void testGetBytesUtf16Be() throws UnsupportedEncodingException {
145145

146146
@Test
147147
public void testGetBytesUtf16Le() throws UnsupportedEncodingException {
148-
final String charsetName = "UTF-16LE";
148+
final String charsetName = StandardCharsets.UTF_16LE.name();
149149
testGetBytesUnchecked(charsetName);
150150
final byte[] expected = STRING_FIXTURE.getBytes(charsetName);
151151
final byte[] actual = StringUtils.getBytesUtf16Le(STRING_FIXTURE);

0 commit comments

Comments
 (0)