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