forked from skyscreamer/JSONassert
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomization.java
More file actions
71 lines (65 loc) · 2.48 KB
/
Customization.java
File metadata and controls
71 lines (65 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package org.skyscreamer.jsonassert;
/**
* Associates a custom matcher to a specific jsonpath.
*/
public final class Customization {
private final String path;
private final ValueMatcher<Object> comparator;
public Customization(String path, ValueMatcher<Object> comparator) {
assert path != null;
assert comparator != null;
this.path = path;
this.comparator = comparator;
}
public static Customization customization(String path, ValueMatcher<Object> comparator) {
return new Customization(path, comparator);
}
public boolean appliesToPath(String path) {
return this.path.equals(path);
}
/**
* Return true if actual value matches expected value using this
* Customization's comparator. Calls to this method should be replaced by
* calls to matches(String prefix, Object actual, Object expected,
* JSONCompareResult result).
*
* @param actual
* JSON value being tested
* @param expected
* expected JSON value
* @return true if actual value matches expected value
*/
@Deprecated
public boolean matches(Object actual, Object expected) {
return comparator.equal(actual, expected);
}
/**
* Return true if actual value matches expected value using this
* Customization's comparator. The equal method used for comparison depends
* on type of comparator.
*
* @param prefix
* JSON path of the JSON item being tested (only used if
* comparator is a LocationAwareValueMatcher)
* @param actual
* JSON value being tested
* @param expected
* expected JSON value
* @param result
* JSONCompareResult to which match failure may be passed (only
* used if comparator is a LocationAwareValueMatcher)
* @return true if expected and actual equal or any difference has already
* been passed to specified result instance, false otherwise.
* @throws ValueMatcherException
* if expected and actual values not equal and ValueMatcher
* needs to override default comparison failure message that
* would be generated if this method returned false.
*/
public boolean matches(String prefix, Object actual, Object expected,
JSONCompareResult result) throws ValueMatcherException {
if (comparator instanceof LocationAwareValueMatcher) {
return ((LocationAwareValueMatcher<Object>)comparator).equal(prefix, actual, expected, result);
}
return comparator.equal(actual, expected);
}
}