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
public void givenUTF8String_decodeByUS_ASCII_ReplaceMalformedInputSequence() throws IOException {
String input = "The façade pattern is a software design pattern.";
public void givenUTF8String_whenDecodeByUS_ASCII_thenIgnoreMalformedInputSequence() throws IOException {
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.",
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
public void givenUTF8String_decodeByUS_ASCII_IgnoreMalformedInputSequence() 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(input, StandardCharsets.US_ASCII, CodingErrorAction.IGNORE));
}
@Test
public void givenUTF8String_decodeByUS_ASCII_ReportMalformedInputSequence() {
String input = "The façade pattern is a software design pattern.";
public void givenUTF8String_whenDecodeByUS_ASCII_thenReportMalformedInputSequence() {
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
public void givenTextFile_FindSuitableCandidateEncodings() {
public void givenTextFile_whenFindSuitableCandidateEncodings_thenProduceSuitableCandidateEncodings() {
Path path = Paths.get("src/test/resources/encoding.txt");
List<Charset> allCandidateCharSets = Arrays.asList(
StandardCharsets.US_ASCII, StandardCharsets.UTF_8, StandardCharsets.ISO_8859_1);
@ -113,6 +112,7 @@ public class CharacterEncodingExamplesUnitTest {
ex.printStackTrace();
}
});
Assertions.assertEquals(suitableCharsets, Arrays.asList(StandardCharsets.UTF_8, StandardCharsets.ISO_8859_1));
}