Skip to content

Commit 1343ab3

Browse files
committed
fixing #78 (test added)
1 parent 3daeedd commit 1343ab3

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

core/src/main/java/org/everit/json/schema/ArraySchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private Optional<ValidationException> testItemCount(final JSONArray subject) {
201201
+ ", found: " + actualLength, "minItems"));
202202
}
203203
if (maxItems != null && maxItems < actualLength) {
204-
return Optional.of(new ValidationException(this, "expected maximum item count: " + minItems
204+
return Optional.of(new ValidationException(this, "expected maximum item count: " + maxItems
205205
+ ", found: " + actualLength, "maxItems"));
206206
}
207207
return Optional.empty();

core/src/test/java/org/everit/json/schema/ArraySchemaTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void maxItems() {
7373
.subject(subject)
7474
.expectedPointer("#")
7575
.expectedKeyword("maxItems")
76+
.expectedMessageFragment("expected maximum item count: 0, found: 1")
7677
.input(ARRAYS.get("onlyOneItem"))
7778
.expect();
7879
}

core/src/test/java/org/everit/json/schema/TestSupport.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
import java.util.List;
2121

22+
import static org.hamcrest.CoreMatchers.containsString;
23+
import static org.junit.Assert.assertEquals;
24+
import static org.junit.Assert.assertThat;
25+
2226
public class TestSupport {
2327

2428
public static class Failure {
@@ -33,6 +37,8 @@ public static class Failure {
3337

3438
private Object input;
3539

40+
private String expectedMessageFragment;
41+
3642
public Failure subject(final Schema subject) {
3743
this.subject = subject;
3844
return this;
@@ -72,6 +78,10 @@ public String expectedKeyword() {
7278
return expectedKeyword;
7379
}
7480

81+
public String expectedMessageFragment() {
82+
return expectedMessageFragment;
83+
}
84+
7585
public Failure input(final Object input) {
7686
this.input = input;
7787
return this;
@@ -84,6 +94,11 @@ public Object input() {
8494
public void expect() {
8595
expectFailure(this);
8696
}
97+
98+
public Failure expectedMessageFragment(String expectedFragment) {
99+
this.expectedMessageFragment = expectedFragment;
100+
return this;
101+
}
87102
}
88103

89104
public static Failure failureOf(final Schema subject) {
@@ -138,9 +153,12 @@ public static void expectFailure(final Failure failure) {
138153
Assert.fail(failure.subject() + " did not fail for " + failure.input());
139154
} catch (ValidationException e) {
140155
Assert.assertSame(failure.expectedViolatedSchema(), e.getViolatedSchema());
141-
Assert.assertEquals(failure.expectedPointer(), e.getPointerToViolation());
156+
assertEquals(failure.expectedPointer(), e.getPointerToViolation());
142157
if (failure.expectedKeyword() != null) {
143-
Assert.assertEquals(failure.expectedKeyword(), e.getKeyword());
158+
assertEquals(failure.expectedKeyword(), e.getKeyword());
159+
}
160+
if (failure.expectedMessageFragment() != null) {
161+
assertThat(e.getMessage(), containsString(failure.expectedMessageFragment()));
144162
}
145163
}
146164
}
@@ -152,7 +170,7 @@ private static void test(final Schema failingSchema, final String expectedPointe
152170
Assert.fail(failingSchema + " did not fail for " + input);
153171
} catch (ValidationException e) {
154172
if (expectedPointer != null) {
155-
Assert.assertEquals(expectedPointer, e.getPointerToViolation());
173+
assertEquals(expectedPointer, e.getPointerToViolation());
156174
}
157175
throw e;
158176
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"message" : "#: expected maximum item count: 1, found 2"
2+
"message" : "#: expected maximum item count: 1, found: 2"
33
}

0 commit comments

Comments
 (0)