Skip to content

Commit 0729b1e

Browse files
committed
removing dead code and adding some tests to ObjectComparator
1 parent 43287ea commit 0729b1e

File tree

2 files changed

+39
-46
lines changed

2 files changed

+39
-46
lines changed

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

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package org.everit.json.schema;
22

3-
import static java.lang.String.format;
43
import static java.util.Objects.requireNonNull;
54
import static org.everit.json.schema.FormatValidator.NONE;
65

7-
import java.util.Arrays;
8-
import java.util.List;
96
import java.util.Objects;
107
import java.util.regex.Pattern;
118

@@ -121,53 +118,10 @@ public Pattern getPattern() {
121118
return pattern;
122119
}
123120

124-
private void testLength(final String subject, List<ValidationException> validationExceptions) {
125-
int actualLength = subject.codePointCount(0, subject.length());
126-
if (minLength != null && actualLength < minLength.intValue()) {
127-
validationExceptions.add(
128-
failure("expected minLength: " + minLength + ", actual: "
129-
+ actualLength, "minLength"));
130-
}
131-
if (maxLength != null && actualLength > maxLength.intValue()) {
132-
validationExceptions.add(
133-
failure("expected maxLength: " + maxLength + ", actual: "
134-
+ actualLength, "maxLength"));
135-
}
136-
}
137-
138-
private void testPattern(final String subject, List<ValidationException> validationExceptions) {
139-
if (pattern != null && !pattern.matcher(subject).find()) {
140-
String message = format("string [%s] does not match pattern %s",
141-
subject, pattern.pattern());
142-
validationExceptions.addAll(Arrays.asList(failure(message, "pattern")));
143-
}
144-
}
145-
146121
@Override void accept(Visitor visitor) {
147122
visitor.visitStringSchema(this);
148123
}
149124

150-
// @Override
151-
// public void validate(final Object subject) {
152-
// if (!(subject instanceof String)) {
153-
// if (requiresString) {
154-
// throw failure(String.class, subject);
155-
// }
156-
// } else {
157-
// List<ValidationException> validationExceptions = new ArrayList<>();
158-
// String stringSubject = (String) subject;
159-
// testLength(stringSubject, validationExceptions);
160-
// testPattern(stringSubject, validationExceptions);
161-
// Optional<String> failure = formatValidator.validate(stringSubject);
162-
// if (failure.isPresent()) {
163-
// validationExceptions.add(failure(failure.get(), "format"));
164-
// }
165-
// if (null != validationExceptions) {
166-
// ValidationException.throwFor(this, validationExceptions);
167-
// }
168-
// }
169-
// }
170-
171125
@Override
172126
public boolean equals(Object o) {
173127
if (this == o)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.everit.json.schema;
2+
3+
import static org.junit.Assert.assertFalse;
4+
5+
import org.json.JSONArray;
6+
import org.json.JSONObject;
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import junitparams.JUnitParamsRunner;
11+
import junitparams.Parameters;
12+
import junitparams.naming.TestCaseName;
13+
14+
@RunWith(JUnitParamsRunner.class)
15+
public class ObjectComparatorTest {
16+
17+
public static final JSONArray EMPTY_ARRAY = new JSONArray();
18+
public static final JSONObject EMPTY_OBJECT = new JSONObject();
19+
20+
private Object[][] failingCases() {
21+
return new Object[][] {
22+
{ "array, null", EMPTY_ARRAY, null },
23+
{ "array, object", EMPTY_ARRAY, EMPTY_OBJECT },
24+
{ "object, null", EMPTY_OBJECT, null },
25+
{ "arrays with different length", EMPTY_ARRAY, new JSONArray("[null]") },
26+
{ "arrays with different elems", new JSONArray("[true, false]"), new JSONArray("[false, true]") },
27+
{ "objects with different length", EMPTY_OBJECT, new JSONObject("{\"a\":true}") }
28+
};
29+
}
30+
31+
@Test
32+
@Parameters(method = "failingCases")
33+
@TestCaseName("{0} (false)")
34+
public void array_Null_failure(String testcaseName, Object arg1, Object arg2) {
35+
assertFalse(ObjectComparator.deepEquals(arg1, arg2));
36+
assertFalse(ObjectComparator.deepEquals(arg2, arg1));
37+
}
38+
39+
}

0 commit comments

Comments
 (0)