Skip to content

Commit 35d9a93

Browse files
LarsEckartJayBazuziisidore
committed
- F DateScrubber.getScrubberFor("") returns empty scrubber
Co-authored-by: Jay Bazuzi <jay@bazuzi.com> Co-authored-by: Llewellyn Falco <llewellyn.falco@gmail.com>
1 parent fc55388 commit 35d9a93

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.spun.util.markdown.table.MarkdownTable;
55
import org.approvaltests.Approvals;
66
import org.approvaltests.core.Options;
7-
import org.approvaltests.velocity.VelocityApprovals;
87
import org.junit.jupiter.api.Disabled;
98
import org.junit.jupiter.api.Test;
109

@@ -72,4 +71,9 @@ void textExamples()
7271
""".split("\n");
7372
Approvals.verifyAll("Date scrubbing", examples, this::verifyScrubbing);
7473
}
74+
@Test
75+
void testBlank()
76+
{
77+
DateScrubber.getScrubberFor("");
78+
}
7579
}

approvaltests/src/main/java/org/approvaltests/scrubbers/DateScrubber.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.spun.util.ArrayUtils;
44
import com.spun.util.FormattedException;
5+
import com.spun.util.StringUtils;
56
import org.lambda.functions.Function1;
67
import org.lambda.query.Query;
78

@@ -56,6 +57,8 @@ private static SupportedFormat __(String regex, String... examples)
5657
}
5758
public static DateScrubber getScrubberFor(String formattedExample)
5859
{
60+
if (StringUtils.isEmpty(formattedExample))
61+
{ return DateScrubber.getNull(); }
5962
for (SupportedFormat pattern : getSupportedFormats())
6063
{
6164
DateScrubber scrubber = new DateScrubber(pattern.getRegex());
@@ -66,6 +69,17 @@ public static DateScrubber getScrubberFor(String formattedExample)
6669
"No match found for %s.\n Feel free to add your date at https://github.com/approvals/ApprovalTests.Java/issues/112 \n Current supported formats are: %s",
6770
formattedExample, Query.select(getSupportedFormats(), SupportedFormat::getRegex));
6871
}
72+
public static DateScrubber getNull()
73+
{
74+
return new DateScrubber("")
75+
{
76+
@Override
77+
public String scrub(String input)
78+
{
79+
return input;
80+
}
81+
};
82+
}
6983
public static class SupportedFormat
7084
{
7185
private final String[] examples;

0 commit comments

Comments
 (0)