indentations are adjusted
This commit is contained in:
parent
2bb48cbedc
commit
750aab063e
|
@ -76,37 +76,37 @@ public class CharacterEncodingExamplesUnitTest {
|
|||
@Test
|
||||
public void givenUTF8String_decodeByUS_ASCII_ReplaceMalformedInputSequence() throws IOException {
|
||||
String input = "The façade pattern is a software design pattern.";
|
||||
Assertions.assertEquals(CharacterEncodingExamples.decodeText(input, StandardCharsets.US_ASCII, CodingErrorAction.REPLACE),
|
||||
"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(input, StandardCharsets.US_ASCII, CodingErrorAction.REPLACE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUTF8String_decodeByUS_ASCII_IgnoreMalformedInputSequence() throws IOException {
|
||||
String input = "The façade pattern is a software design pattern.";
|
||||
Assertions.assertEquals(
|
||||
CharacterEncodingExamples.decodeText(input, StandardCharsets.US_ASCII, CodingErrorAction.IGNORE),
|
||||
"The faade pattern is a software design pattern.");
|
||||
"The faade pattern is a software design pattern.",
|
||||
CharacterEncodingExamples.decodeText(input, StandardCharsets.US_ASCII, CodingErrorAction.IGNORE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUTF8String_decodeByUS_ASCII_ReportMalformedInputSequence() {
|
||||
String input = "The façade pattern is a software design pattern.";
|
||||
Assertions.assertThrows(MalformedInputException.class,
|
||||
() -> CharacterEncodingExamples.decodeText(input, StandardCharsets.US_ASCII, CodingErrorAction.REPORT));
|
||||
() -> CharacterEncodingExamples.decodeText(input, StandardCharsets.US_ASCII, CodingErrorAction.REPORT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTextFile_FindSuitableCandidateEncodings() {
|
||||
Path path = Paths.get("src/test/resources/encoding.txt");
|
||||
List<Charset> allCandidateCharSets = Arrays.asList(StandardCharsets.US_ASCII, StandardCharsets.UTF_8, StandardCharsets.ISO_8859_1);
|
||||
List<Charset> allCandidateCharSets = Arrays.asList(
|
||||
StandardCharsets.US_ASCII, StandardCharsets.UTF_8, StandardCharsets.ISO_8859_1);
|
||||
List<Charset> suitableCharsets = new ArrayList<>();
|
||||
allCandidateCharSets.forEach(charset -> {
|
||||
try {
|
||||
CharsetDecoder charsetDecoder = charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT);
|
||||
Reader reader = new InputStreamReader(Files.newInputStream(path), charsetDecoder);
|
||||
BufferedReader bufferedReader = new BufferedReader(reader);
|
||||
while (bufferedReader.readLine() != null) {
|
||||
}
|
||||
bufferedReader.readLine();
|
||||
suitableCharsets.add(charset);
|
||||
} catch (MalformedInputException ignored) {
|
||||
} catch (IOException ex) {
|
||||
|
|
Loading…
Reference in New Issue