Skip to content

Commit 9dabbbf

Browse files
Rename DualKey to DualValue
1 parent faf981b commit 9dabbbf

9 files changed

+201
-218
lines changed

src/main/java/org/assertj/core/api/AbstractObjectAssert.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,6 @@ public RecursiveComparisonAssert<?> usingRecursiveComparison() {
828828
return usingRecursiveComparison(new RecursiveComparisonConfiguration());
829829
}
830830

831-
// TODO soft assertion tests: add to method changing the object under tests
832-
833831
/**
834832
* Same as {@link #usingRecursiveComparison()} but allows to specify your own {@link RecursiveComparisonConfiguration}.
835833
* @param recursiveComparisonConfiguration the {@link RecursiveComparisonConfiguration} used in the chained {@link RecursiveComparisonAssert#isEqualTo(Object) isEqualTo} assertion.

src/main/java/org/assertj/core/api/RecursiveComparisonAssert.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ void setRecursiveComparisonConfiguration(RecursiveComparisonConfiguration recurs
5050
* Asserts that the object under test (actual) is equal to the given object when compared field by field recursively (including
5151
* inherited fields are included in the comparison). If the comparison fails it will report all the differences found and which
5252
* effective {@link RecursiveComparisonConfiguration} was used to help users understand the failure.
53-
* TODO add link to assertj website documentation
5453
* <p>
5554
* This is typically useful when actual's {@code equals} was not overridden.
5655
* <p>

src/main/java/org/assertj/core/api/recursive/comparison/DualKey.java renamed to src/main/java/org/assertj/core/api/recursive/comparison/DualValue.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,58 @@
1212
*/
1313
package org.assertj.core.api.recursive.comparison;
1414

15+
import static java.lang.String.format;
16+
import static java.util.Collections.unmodifiableList;
1517
import static org.assertj.core.util.Strings.join;
1618

1719
import java.util.List;
1820

19-
final class DualKey { // TODO rename DualValue
21+
// logically immutable
22+
final class DualValue {
2023

2124
final List<String> path;
2225
final String concatenatedPath;
23-
final Object key1; // TODO rename to actual
24-
final Object key2; // TODO rename to expected
26+
final Object actual;
27+
final Object expected;
28+
private final int hashCode;
2529

26-
DualKey(List<String> path, Object key1, Object key2) {
30+
DualValue(List<String> path, Object actual, Object expected) {
2731
this.path = path;
2832
this.concatenatedPath = join(path).with(".");
29-
this.key1 = key1;
30-
this.key2 = key2;
33+
this.actual = actual;
34+
this.expected = expected;
35+
int h1 = actual != null ? actual.hashCode() : 0;
36+
int h2 = expected != null ? expected.hashCode() : 0;
37+
hashCode = h1 + h2;
3138
}
3239

3340
@Override
3441
public boolean equals(Object other) {
35-
if (!(other instanceof DualKey)) {
36-
return false;
37-
}
38-
39-
DualKey that = (DualKey) other;
40-
return key1 == that.key1 && key2 == that.key2;
42+
if (!(other instanceof DualValue)) return false;
43+
DualValue that = (DualValue) other;
44+
return actual == that.actual && expected == that.expected;
4145
}
4246

4347
@Override
4448
public int hashCode() {
45-
int h1 = key1 != null ? key1.hashCode() : 0;
46-
int h2 = key2 != null ? key2.hashCode() : 0;
47-
return h1 + h2;
49+
return hashCode;
4850
}
4951

50-
5152
@Override
5253
public String toString() {
53-
return String.format("DualKey [path=%s, key1=%s, key2=%s]", concatenatedPath, key1, key2);
54+
return format("DualValue [path=%s, actual=%s, expected=%s]", concatenatedPath, actual, expected);
5455
}
5556

5657
public List<String> getPath() {
57-
return path;
58+
return unmodifiableList(path);
5859
}
5960

6061
public String getConcatenatedPath() {
6162
return concatenatedPath;
6263
}
6364

6465
public boolean isJavaType() {
65-
return key1.getClass().getName().startsWith("java.");
66+
if (actual == null) return false;
67+
return actual.getClass().getName().startsWith("java.");
6668
}
6769
}

src/main/java/org/assertj/core/api/recursive/comparison/DualKeyDeque.java renamed to src/main/java/org/assertj/core/api/recursive/comparison/DualValueDeque.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,48 @@
1818
import java.util.LinkedList;
1919

2020
// special deque that can ignore DualKey according to RecursiveComparisonConfiguration.
21-
// TODO: keep track of ignored fields ?
2221
@SuppressWarnings("serial")
23-
class DualKeyDeque extends LinkedList<DualKey> {
22+
class DualValueDeque extends LinkedList<DualValue> {
2423
private RecursiveComparisonConfiguration recursiveComparisonConfiguration;
2524

26-
public DualKeyDeque(RecursiveComparisonConfiguration recursiveComparisonConfiguration) {
25+
public DualValueDeque(RecursiveComparisonConfiguration recursiveComparisonConfiguration) {
2726
this.recursiveComparisonConfiguration = recursiveComparisonConfiguration;
2827
}
2928

3029
@Override
31-
public boolean add(DualKey dualKey) {
30+
public boolean add(DualValue dualKey) {
3231
if (shouldIgnore(dualKey)) return false;
3332
return super.add(dualKey);
3433
}
3534

3635
@Override
37-
public void add(int index, DualKey dualKey) {
36+
public void add(int index, DualValue dualKey) {
3837
if (shouldIgnore(dualKey)) return;
3938
super.add(index, dualKey);
4039
}
4140

4241
@Override
43-
public boolean addAll(int index, Collection<? extends DualKey> collection) {
42+
public boolean addAll(int index, Collection<? extends DualValue> collection) {
4443
return super.addAll(index, collection.stream().filter(this::shouldAddDualKey).collect(toList()));
4544
}
4645

4746
@Override
48-
public void addFirst(DualKey dualKey) {
47+
public void addFirst(DualValue dualKey) {
4948
if (shouldIgnore(dualKey)) return;
5049
super.addFirst(dualKey);
5150
}
5251

5352
@Override
54-
public void addLast(DualKey dualKey) {
53+
public void addLast(DualValue dualKey) {
5554
if (shouldIgnore(dualKey)) return;
5655
super.addLast(dualKey);
5756
}
5857

59-
private boolean shouldIgnore(DualKey dualKey) {
58+
private boolean shouldIgnore(DualValue dualKey) {
6059
return recursiveComparisonConfiguration.shouldIgnore(dualKey);
6160
}
6261

63-
private boolean shouldAddDualKey(DualKey dualKey) {
62+
private boolean shouldAddDualKey(DualValue dualKey) {
6463
return !shouldIgnore(dualKey);
6564
}
6665

src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonConfiguration.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public String multiLineDescription(Representation representation) {
270270

271271
// non public stuff
272272

273-
boolean shouldIgnore(DualKey dualKey) {
273+
boolean shouldIgnore(DualValue dualKey) {
274274
return matchesAnIgnoredNullField(dualKey)
275275
|| matchesAnIgnoredField(dualKey)
276276
|| matchesAnIgnoredFieldRegex(dualKey);
@@ -289,11 +289,11 @@ private static String concatenatedPath(String parentPath, String name) {
289289
return parentPath.isEmpty() ? name : format("%s.%s", parentPath, name);
290290
}
291291

292-
boolean shouldIgnoreOverriddenEqualsOf(DualKey dualKey) {
292+
boolean shouldIgnoreOverriddenEqualsOf(DualValue dualKey) {
293293
if (dualKey.isJavaType()) return false; // we must compare basic types otherwise the recursive comparison loops infinitely!
294294
return ignoreAllOverriddenEquals
295295
|| matchesAnIgnoredOverriddenEqualsField(dualKey)
296-
|| shouldIgnoreOverriddenEqualsOf(dualKey.key1.getClass());
296+
|| shouldIgnoreOverriddenEqualsOf(dualKey.actual.getClass());
297297
}
298298

299299
@VisibleForTesting
@@ -367,25 +367,25 @@ private boolean matchesAnIgnoredOverriddenEqualsType(Class<?> clazz) {
367367
return ignoredOverriddenEqualsForTypes.contains(clazz);
368368
}
369369

370-
private boolean matchesAnIgnoredOverriddenEqualsField(DualKey dualKey) {
370+
private boolean matchesAnIgnoredOverriddenEqualsField(DualValue dualKey) {
371371
return ignoredOverriddenEqualsForFields.stream()
372372
.anyMatch(fieldLocation -> fieldLocation.matches(dualKey.concatenatedPath));
373373
}
374374

375-
private boolean matchesAnIgnoredNullField(DualKey dualKey) {
376-
return ignoreAllActualNullFields && dualKey.key1 == null;
375+
private boolean matchesAnIgnoredNullField(DualValue dualKey) {
376+
return ignoreAllActualNullFields && dualKey.actual == null;
377377
}
378378

379379
private boolean matchesAnIgnoredFieldRegex(String fieldConcatenatedPath) {
380380
return ignoredFieldsRegexes.stream()
381381
.anyMatch(regex -> regex.matcher(fieldConcatenatedPath).matches());
382382
}
383383

384-
private boolean matchesAnIgnoredFieldRegex(DualKey dualKey) {
384+
private boolean matchesAnIgnoredFieldRegex(DualValue dualKey) {
385385
return matchesAnIgnoredFieldRegex(dualKey.concatenatedPath);
386386
}
387387

388-
private boolean matchesAnIgnoredField(DualKey dualKey) {
388+
private boolean matchesAnIgnoredField(DualValue dualKey) {
389389
return matchesAnIgnoredField(dualKey.concatenatedPath);
390390
}
391391

0 commit comments

Comments
 (0)