Enhanced: given_when_then pattern naming and formatting problems are resolved

This commit is contained in:
Afshin 2019-10-07 11:52:22 +02:00
parent da1ac659fb
commit 78cb7a3a3f
1 changed files with 15 additions and 15 deletions

View File

@ -74,29 +74,28 @@ public class CharacterEncodingExamplesUnitTest {
} }
@Test @Test
public void givenUTF8String_decodeByUS_ASCII_ReplaceMalformedInputSequence() throws IOException { public void givenUTF8String_whenDecodeByUS_ASCII_thenIgnoreMalformedInputSequence() throws IOException {
String input = "The façade 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));
}
@Test
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(input, StandardCharsets.US_ASCII, CodingErrorAction.REPLACE)); CharacterEncodingExamples.decodeText(
"The façade pattern is a software design pattern.", StandardCharsets.US_ASCII, CodingErrorAction.REPLACE));
} }
@Test @Test
public void givenUTF8String_decodeByUS_ASCII_IgnoreMalformedInputSequence() throws IOException { public void givenUTF8String_whenDecodeByUS_ASCII_thenReportMalformedInputSequence() {
String input = "The façade pattern is a software design pattern.";
Assertions.assertEquals(
"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, Assertions.assertThrows(MalformedInputException.class,
() -> CharacterEncodingExamples.decodeText(input, StandardCharsets.US_ASCII, CodingErrorAction.REPORT)); () -> CharacterEncodingExamples.decodeText(
"The façade pattern is a software design pattern.", StandardCharsets.US_ASCII, CodingErrorAction.REPORT));
} }
@Test @Test
public void givenTextFile_FindSuitableCandidateEncodings() { public void givenTextFile_whenFindSuitableCandidateEncodings_thenProduceSuitableCandidateEncodings() {
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);
@ -113,6 +112,7 @@ public class CharacterEncodingExamplesUnitTest {
ex.printStackTrace(); ex.printStackTrace();
} }
}); });
Assertions.assertEquals(suitableCharsets, Arrays.asList(StandardCharsets.UTF_8, StandardCharsets.ISO_8859_1)); Assertions.assertEquals(suitableCharsets, Arrays.asList(StandardCharsets.UTF_8, StandardCharsets.ISO_8859_1));
} }