Skip to content

Commit 75d68ef

Browse files
committed
#290 Expression builder test
1 parent 7100f55 commit 75d68ef

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

tests/test-base/src/main/java/net/javacrumbs/jsonunit/test/base/AbstractAssertJTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import static net.javacrumbs.jsonunit.core.Option.IGNORING_VALUES;
4848
import static net.javacrumbs.jsonunit.core.Option.TREATING_NULL_AS_ABSENT;
4949
import static net.javacrumbs.jsonunit.core.internal.JsonUtils.jsonSource;
50+
import static net.javacrumbs.jsonunit.test.base.RegexBuilder.regex;
5051
import static org.assertj.core.api.Assertions.assertThat;
5152
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
5253
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -705,7 +706,13 @@ void testAssertPathArray() {
705706
@Test
706707
void testLongRegexp() {
707708
assertThatJson("{\"test\": \"This is some text followed by: ABCD, followed by this\"}")
708-
.isEqualTo("{\"test\": \"${json-unit.regex}\\\\QThis is some text followed by: \\\\E[A-Z]+\\\\Q, followed by this\\\\E\"}");
709+
.isEqualTo("{\"test\": \"${json-unit.regex}^\\\\QThis is some text followed by: \\\\E[A-Z]+\\\\Q, followed by this\\\\E$\"}");
710+
}
711+
712+
@Test
713+
void testLongRegexpBuilder() {
714+
assertThatJson("{\"test\": \"This is some text followed by: ABCD, followed by this\"}")
715+
.isEqualTo("{\"test\": " + regex().str("This is some text followed by: ").exp("[A-Z]+").str(", followed by this") + "}");
709716
}
710717

711718
@Test
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package net.javacrumbs.jsonunit.test.base;
2+
3+
public class RegexBuilder {
4+
private final String expression;
5+
6+
private RegexBuilder(String expression) {
7+
this.expression = expression;
8+
}
9+
10+
static RegexBuilder regex() {
11+
return new RegexBuilder("\"${json-unit.regex}^");
12+
}
13+
14+
RegexBuilder str(String staticString) {
15+
return new RegexBuilder(expression + "\\\\Q" + staticString + "\\\\E");
16+
}
17+
18+
RegexBuilder exp(String regex) {
19+
return new RegexBuilder(expression + regex);
20+
}
21+
22+
public String toString() {
23+
return expression + "$\"";
24+
}
25+
26+
}

0 commit comments

Comments
 (0)