Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,47 +51,29 @@ private void analyze(ContainAnalyzer containAnalyzer, ValuePath actualPath,
Object expectedKey = expectedEntry.getKey();

ValuePath propertyPath = actualPath.property(expectedKey.toString());

if (isNegative) {
analyzeNegative(containAnalyzer, actualMap, propertyPath, expectedEntry);
} else {
analyzePositive(containAnalyzer, actualMap, propertyPath, expectedEntry);
}
analyzePositiveNegative(containAnalyzer, actualMap, propertyPath, expectedEntry, isNegative);
}
}

private void analyzePositive(ContainAnalyzer containAnalyzer,
Map<?, ?> actualMap,
ValuePath propertyPath,
Map.Entry<?, ?> expectedEntry) {
private void analyzePositiveNegative(ContainAnalyzer containAnalyzer,
Map<?, ?> actualMap,
ValuePath propertyPath,
Map.Entry<?, ?> expectedEntry,
boolean isNegative) {
if (!actualMap.containsKey(expectedEntry.getKey())) {
containAnalyzer.reportMismatch(this, propertyPath, tokenizedMessage().matcher("is missing"));
} else {
CompareToComparator comparator = CompareToComparator.comparator();

Object actualValue = actualMap.get(expectedEntry.getKey());
boolean actualValueEqual = comparator.compareIsEqual(propertyPath,
actualValue, expectedEntry.getValue());
boolean actualValueEqual = isNegative ?
!comparator.compareIsNotEqual(propertyPath, actualValue, expectedEntry.getValue()):
comparator.compareIsEqual(propertyPath, actualValue, expectedEntry.getValue());

if (!actualValueEqual) {
containAnalyzer.reportMismatch(this, propertyPath, comparator.generateEqualMismatchReport());
}
}
}

private void analyzeNegative(ContainAnalyzer containAnalyzer,
Map<?, ?> actualMap,
ValuePath propertyPath,
Map.Entry<?, ?> expectedEntry) {
if (actualMap.containsKey(expectedEntry.getKey())) {
CompareToComparator comparator = CompareToComparator.comparator();

Object actualValue = actualMap.get(expectedEntry.getKey());
boolean actualValueNotEqual = comparator.compareIsNotEqual(propertyPath,
actualValue, expectedEntry.getValue());

if (!actualValueNotEqual) {
containAnalyzer.reportMatch(this, propertyPath, comparator.generateNotEqualMismatchReport());
} else {
containAnalyzer.reportMatch(this, propertyPath, comparator.generateEqualMatchReport());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public boolean handle(Object actual, Object expected) {

@Override
public void analyzeContain(ContainAnalyzer containAnalyzer, ValuePath actualPath, Object actual, Object expected) {
analyze(containAnalyzer, actualPath, actual, expected, false);
analyze(containAnalyzer, actualPath, actual, expected);
}

@Override
public void analyzeNotContain(ContainAnalyzer containAnalyzer, ValuePath actualPath, Object actual, Object expected) {
analyze(containAnalyzer, actualPath, actual, expected, true);
analyze(containAnalyzer, actualPath, actual, expected);
}

private void analyze(ContainAnalyzer containAnalyzer, ValuePath actualPath, Object actual, Object expected, boolean isNegative) {
private void analyze(ContainAnalyzer containAnalyzer, ValuePath actualPath, Object actual, Object expected) {
CharSequence actualText = (CharSequence) actual;
CharSequence expectedText = (CharSequence) expected;

Expand Down