• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fslev / json-compare / #683

30 Apr 2026 01:14PM UTC coverage: 97.396% (-0.2%) from 97.612%
#683

push

web-flow
Merge 2a848d411 into 4691206c7

271 of 280 new or added lines in 13 files covered. (96.79%)

1 existing line in 1 file now uncovered.

374 of 384 relevant lines covered (97.4%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/src/main/java/io/json/compare/matcher/JsonValueMatcher.java
1
package io.json.compare.matcher;
2

3
import com.fasterxml.jackson.databind.JsonNode;
4
import io.json.compare.CompareMode;
5
import io.json.compare.JsonComparator;
6

7
import java.util.List;
8
import java.util.Set;
9

10
class JsonValueMatcher extends AbstractJsonMatcher {
11

12
    JsonValueMatcher(JsonNode expected, JsonNode actual, JsonComparator comparator, Set<CompareMode> compareModes) {
13
        super(expected, actual, comparator, compareModes);
1✔
14
    }
1✔
15

16
    @Override
17
    public List<String> match() {
18
        String typeDiff = detectTypeMismatch(expected, actual);
1✔
19
        if (typeDiff != null) {
1✔
20
            return List.of(typeDiff);
1✔
21
        }
22

23
        UseCase useCase = UseCase.of(expected.asText());
1✔
24
        if (useCase == UseCase.MATCH_ANY) {
1✔
25
            return List.of();
1✔
26
        }
27

28
        String expectedText = UseCase.sanitize(expected.asText());
1✔
29
        String actualText = actual.asText();
1✔
30
        boolean matches = comparator.compareValues(expectedText, actualText);
1✔
31

32
        if (matches != (useCase == UseCase.MATCH)) {
1✔
33
            return List.of(diffMsg("value", expected, actual));
1✔
34
        }
35
        return List.of();
1✔
36
    }
37

38
    private static String detectTypeMismatch(JsonNode expected, JsonNode actual) {
39
        if (expected.isNull() && !actual.isNull()) {
1✔
40
            return LS + "Expected null:  But got: " + actual;
1✔
41
        }
42
        if (expected.isNumber() && !actual.isNumber()) {
1✔
43
            return diffMsg("number", expected, actual);
1✔
44
        }
45
        if (expected.isBoolean() && !actual.isBoolean()) {
1✔
46
            return diffMsg("boolean", expected, actual);
1✔
47
        }
48
        if (actual.isTextual() && !expected.isTextual()) {
1✔
NEW
49
            return diffMsg("text", expected, actual);
×
50
        }
51
        return null;
1✔
52
    }
53

54
    private static String diffMsg(String kind, Object expected, Object actual) {
55
        return LS + "Expected " + kind + ": " + expected + " But got: " + actual;
1✔
56
    }
57
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc