TSK-1781: replace tests in LogSanitizerTest by a test factory

This commit is contained in:
ryzheboka 2021-12-22 12:32:56 +01:00 committed by Mustapha Zorgati
parent 0fb845c273
commit 121339c273
1 changed files with 31 additions and 35 deletions

View File

@ -2,7 +2,12 @@ package pro.taskana.common.internal.util;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.function.ThrowingConsumer;
class LogSanitizerTest {
@ -31,40 +36,31 @@ class LogSanitizerTest {
assertThat(output).isEqualTo(input.toString());
}
@Test
void should_ReplaceMultipleLineBreaksWithUnderscore_When_InputContainsLineBreaks() {
String input = "This\nis\na\nstring\nwith\na\nlot\nof\nlinebreaks\n";
String output = LogSanitizer.stripLineBreakingChars(input);
assertThat(output).isEqualTo("This_is_a_string_with_a_lot_of_linebreaks_");
}
@Test
void should_ReplaceMultipleTabsWithUnderscore_When_InputContainsTabs() {
String input = "This\tis\ta\tstring\twith\ta\tlot\tof\ttabs\t";
String output = LogSanitizer.stripLineBreakingChars(input);
assertThat(output).isEqualTo("This_is_a_string_with_a_lot_of_tabs_");
}
@Test
void should_ReplaceMultipleWindowsLineBreaksWithUnderscore_When_InputContainsWindowsLineBreaks() {
String input = "This\r\nis\r\na\r\nstring\r\nwith\r\na\r\nlot\r\nof\r\nwindows\r\nlinebreaks";
String output = LogSanitizer.stripLineBreakingChars(input);
assertThat(output).isEqualTo("This__is__a__string__with__a__lot__of__windows__linebreaks");
}
@Test
void should_ReplaceAllLinebreaksAndTabsWithUnderscore_When_InputContainsDifferentCharacters() {
String input = "This\tis\r\na\nstring\twith\r\ntaps,\nlinebreaks\tand\r\nwindows\tlinebreaks";
String output = LogSanitizer.stripLineBreakingChars(input);
assertThat(output)
.isEqualTo("This_is__a_string_with__taps,_linebreaks_and__windows_linebreaks");
@TestFactory
Stream<DynamicTest> should_ReplaceWithUnderscore() {
List<Triplet<String, String, String>> testValues =
List.of(
Triplet.of(
"Replace linebreaks",
"This\nis\na\nstring\nwith\na\nlot\nof\nlinebreaks\n",
"This_is_a_string_with_a_lot_of_linebreaks_"),
Triplet.of(
"Replace windows linebreaks",
"This\r\nis\r\na\r\nstring\r\nwith\r\na\r\nlot\r\nof\r\nwindows\r\nlinebreaks",
"This__is__a__string__with__a__lot__of__windows__linebreaks"),
Triplet.of(
"Replace tabs",
"This\tis\ta\tstring\twith\ta\tlot\tof\ttabs\t",
"This_is_a_string_with_a_lot_of_tabs_"),
Triplet.of(
"Replace linebreaks, windows linebreaks and tabs",
"This\tis\r\na\nstring\twith\r\ntaps,\nlinebreaks\tand\r\nwindows\tlinebreaks",
"This_is__a_string_with__taps,_linebreaks_and__windows_linebreaks"));
ThrowingConsumer<Triplet<String, String, String>> test =
t -> {
String output = LogSanitizer.stripLineBreakingChars(t.getMiddle());
assertThat(output).isEqualTo(t.getRight());
};
return DynamicTest.stream(testValues.iterator(), Triplet::getLeft, test);
}
}