Skip to content

Commit 794630f

Browse files
committed
F Scrubbers.scrubAll to allow scrubbing multiple things inside one string
1 parent af8c250 commit 794630f

File tree

7 files changed

+50
-2
lines changed

7 files changed

+50
-2
lines changed

approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTests.supportedFormats.approved.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
| 2020-9-10T08:07Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}Z |
1111
| 2020-09-10T08:07:89Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}:\d{2}Z |
1212
| 2020-09-10T01:23:45.678Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}\:\d{2}\.\d{3}Z |
13+
| 20210505T091112Z | \d{8}T\d{6}Z |

approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTests.testGetDateScrubber.approved.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,8 @@ RegExScrubber[\d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}\:\d{2}\.\d{3}Z]
6666
Example: {'date':"[Date1]"}
6767

6868

69+
Scrubbing for 20210505T091112Z:
70+
RegExScrubber[\d{8}T\d{6}Z]
71+
Example: {'date':"[Date1]"}
72+
73+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://127.0.0.1:[port]/foo/bar?Date=[Date1]&Signature=[signature]

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import org.approvaltests.Approvals;
66
import org.approvaltests.core.Options;
7+
import org.approvaltests.core.Scrubber;
78
import org.junit.jupiter.api.Test;
89

910
class ScrubberTest
@@ -39,4 +40,14 @@ void scrubGuids()
3940
Approvals.verifyAll("guids", guids, new Options(Scrubbers::scrubGuid));
4041
// end-snippet
4142
}
43+
@Test
44+
void scrubMultipleThings()
45+
{
46+
final Scrubber portScrubber = new RegExScrubber(":\\d+/", ":[port]/");
47+
final Scrubber dateScrubber = DateScrubber.getScrubberFor("20210505T091112Z");
48+
final Scrubber signatureScrubber = new RegExScrubber("Signature=.+", "Signature=[signature]");
49+
Scrubber scrubber = Scrubbers.scrubAll(portScrubber, dateScrubber, signatureScrubber);
50+
Approvals.verify("http://127.0.0.1:55079/foo/bar?Date=20210505T091112Z&Signature=4a7dd6f09c1e",
51+
new Options(scrubber));
52+
}
4253
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.approvaltests.scrubbers;
22

3-
import com.spun.util.ArrayUtils;
43
import org.lambda.functions.Function1;
54
import org.lambda.query.Query;
65

6+
import com.spun.util.ArrayUtils;
77
import com.spun.util.FormattedException;
88

99
public class DateScrubber extends RegExScrubber
@@ -34,7 +34,8 @@ public static SupportedFormat[] getSupportedFormats()
3434
"2020-09-9T08:07Z", "2020-09-10T8:07Z", "2020-09-10T08:07Z"),
3535
_("\\d{4}-\\d{1,2}-\\d{1,2}T\\d{1,2}:\\d{2}:\\d{2}Z", "2020-09-10T08:07:89Z"),
3636
_("\\d{4}-\\d{1,2}-\\d{1,2}T\\d{1,2}:\\d{2}\\:\\d{2}\\.\\d{3}Z",
37-
"2020-09-10T01:23:45.678Z")};
37+
"2020-09-10T01:23:45.678Z"),
38+
_("\\d{8}T\\d{6}Z", "20210505T091112Z")};
3839
}
3940
private static SupportedFormat _(String regex, String... examples)
4041
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.approvaltests.scrubbers;
2+
3+
import org.approvaltests.core.Scrubber;
4+
5+
import com.spun.util.ArrayUtils;
6+
7+
public class MultiScrubber implements Scrubber
8+
{
9+
private final Scrubber[] scrubbers;
10+
public MultiScrubber(Scrubber one, Scrubber[] others)
11+
{
12+
this.scrubbers = ArrayUtils.combine(new Scrubber[]{one}, others);
13+
}
14+
@Override
15+
public String scrub(String input)
16+
{
17+
for (Scrubber scrubber : scrubbers)
18+
{
19+
input = scrubber.scrub(input);
20+
}
21+
return input;
22+
}
23+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package org.approvaltests.scrubbers;
22

3+
import org.approvaltests.core.Scrubber;
4+
35
public class Scrubbers
46
{
57
public static String scrubGuid(String input)
68
{
79
return new GuidScrubber().scrub(input);
810
}
11+
public static Scrubber scrubAll(Scrubber one, Scrubber... others)
12+
{
13+
return new MultiScrubber(one, others);
14+
}
915
/**
1016
* Provides methods that can be inlined as example code.
1117
*/

0 commit comments

Comments
 (0)