[LANG-1563] use StandardCharsets.UTF_8 (#548)
* use_StandardCharsets_UTF_8 * Update StringEscapeUtilsTest.java
This commit is contained in:
parent
1c00d14d37
commit
011c8bdc92
|
@ -18,6 +18,7 @@
|
|||
package org.apache.commons.lang3;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -31,14 +32,14 @@ public class CharsetsTestCase {
|
|||
public void testToCharset_Charset() {
|
||||
Assertions.assertEquals(Charset.defaultCharset(), Charsets.toCharset((Charset) null));
|
||||
Assertions.assertEquals(Charset.defaultCharset(), Charsets.toCharset(Charset.defaultCharset()));
|
||||
Assertions.assertEquals(Charset.forName("UTF-8"), Charsets.toCharset(Charset.forName("UTF-8")));
|
||||
Assertions.assertEquals(StandardCharsets.UTF_8, Charsets.toCharset(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToCharset_String() {
|
||||
Assertions.assertEquals(Charset.defaultCharset(), Charsets.toCharset((String) null));
|
||||
Assertions.assertEquals(Charset.defaultCharset(), Charsets.toCharset(Charset.defaultCharset().name()));
|
||||
Assertions.assertEquals(Charset.forName("UTF-8"), Charsets.toCharset("UTF-8"));
|
||||
Assertions.assertEquals(StandardCharsets.UTF_8, Charsets.toCharset("UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -31,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -488,7 +489,7 @@ public class RandomStringUtilsTest {
|
|||
@Test
|
||||
public void testLang100() {
|
||||
final int size = 5000;
|
||||
final Charset charset = Charset.forName("UTF-8");
|
||||
final Charset charset = StandardCharsets.UTF_8;
|
||||
final String orig = RandomStringUtils.random(size);
|
||||
final byte[] bytes = orig.getBytes(charset);
|
||||
final String copy = new String(bytes, charset);
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.io.IOException;
|
|||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
@ -479,7 +478,7 @@ public class StringEscapeUtilsTest {
|
|||
// codepoint: U+1D362
|
||||
final byte[] data = new byte[] { (byte) 0xF0, (byte) 0x9D, (byte) 0x8D, (byte) 0xA2 };
|
||||
|
||||
final String original = new String(data, Charset.forName("UTF8"));
|
||||
final String original = new String(data, StandardCharsets.UTF_8);
|
||||
|
||||
final String escaped = StringEscapeUtils.escapeHtml4( original );
|
||||
assertEquals(original, escaped, "High Unicode should not have been escaped");
|
||||
|
|
Loading…
Reference in New Issue