Enhanced: reformatted code to synchronized it with the article
This commit is contained in:
parent
78cb7a3a3f
commit
7a9738b4bb
|
@ -75,23 +75,27 @@ public class CharacterEncodingExamplesUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenUTF8String_whenDecodeByUS_ASCII_thenIgnoreMalformedInputSequence() throws IOException {
|
public void givenUTF8String_whenDecodeByUS_ASCII_thenIgnoreMalformedInputSequence() throws IOException {
|
||||||
Assertions.assertEquals("The faade pattern is a software design pattern.",
|
Assertions.assertEquals("The faade pattern is a software design pattern.", CharacterEncodingExamples.decodeText("The façade pattern is a software design pattern.", StandardCharsets.US_ASCII, CodingErrorAction.IGNORE));
|
||||||
CharacterEncodingExamples.decodeText(
|
|
||||||
"The façade pattern is a software design pattern.", StandardCharsets.US_ASCII, CodingErrorAction.IGNORE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenUTF8String_whenDecodeByUS_ASCII_thenReplaceMalformedInputSequence() throws IOException {
|
public void givenUTF8String_whenDecodeByUS_ASCII_thenReplaceMalformedInputSequence() throws IOException {
|
||||||
Assertions.assertEquals("The fa<66><61>ade pattern is a software design pattern.",
|
Assertions.assertEquals(
|
||||||
|
"The fa<66><61>ade pattern is a software design pattern.",
|
||||||
CharacterEncodingExamples.decodeText(
|
CharacterEncodingExamples.decodeText(
|
||||||
"The façade pattern is a software design pattern.", StandardCharsets.US_ASCII, CodingErrorAction.REPLACE));
|
"The façade pattern is a software design pattern.",
|
||||||
|
StandardCharsets.US_ASCII,
|
||||||
|
CodingErrorAction.REPLACE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenUTF8String_whenDecodeByUS_ASCII_thenReportMalformedInputSequence() {
|
public void givenUTF8String_whenDecodeByUS_ASCII_thenReportMalformedInputSequence() {
|
||||||
Assertions.assertThrows(MalformedInputException.class,
|
Assertions.assertThrows(
|
||||||
|
MalformedInputException.class,
|
||||||
() -> CharacterEncodingExamples.decodeText(
|
() -> CharacterEncodingExamples.decodeText(
|
||||||
"The façade pattern is a software design pattern.", StandardCharsets.US_ASCII, CodingErrorAction.REPORT));
|
"The façade pattern is a software design pattern.",
|
||||||
|
StandardCharsets.US_ASCII,
|
||||||
|
CodingErrorAction.REPORT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -99,6 +103,7 @@ public class CharacterEncodingExamplesUnitTest {
|
||||||
Path path = Paths.get("src/test/resources/encoding.txt");
|
Path path = Paths.get("src/test/resources/encoding.txt");
|
||||||
List<Charset> allCandidateCharSets = Arrays.asList(
|
List<Charset> allCandidateCharSets = Arrays.asList(
|
||||||
StandardCharsets.US_ASCII, StandardCharsets.UTF_8, StandardCharsets.ISO_8859_1);
|
StandardCharsets.US_ASCII, StandardCharsets.UTF_8, StandardCharsets.ISO_8859_1);
|
||||||
|
|
||||||
List<Charset> suitableCharsets = new ArrayList<>();
|
List<Charset> suitableCharsets = new ArrayList<>();
|
||||||
allCandidateCharSets.forEach(charset -> {
|
allCandidateCharSets.forEach(charset -> {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue