Skip to content

Commit 2f86c6f

Browse files
committed
Merge pull request #935 from kcooney/ParameterizedAssertionError-hashCode
Make ParameterizedAssertionError override hashCode()
2 parents e1315c7 + a1f68c6 commit 2f86c6f

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/main/java/org/junit/experimental/theories/internal/ParameterizedAssertionError.java

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public boolean equals(Object obj) {
1818
return obj instanceof ParameterizedAssertionError && toString().equals(obj.toString());
1919
}
2020

21+
@Override
22+
public int hashCode() {
23+
return toString().hashCode();
24+
}
25+
2126
public static String join(String delimiter, Object... params) {
2227
return join(delimiter, Arrays.asList(params));
2328
}

src/test/java/org/junit/tests/experimental/theories/internal/ParameterizedAssertionErrorTest.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,28 @@ public void differentParameterizedAssertionErrorsHaveDifferentToStrings(
5454
@Theory
5555
public void equalsReturnsTrue(Throwable targetException, String methodName,
5656
Object[] params) {
57-
assertThat(new ParameterizedAssertionError(targetException, methodName,
58-
params), is(new ParameterizedAssertionError(targetException,
59-
methodName, params)));
57+
assertThat(
58+
new ParameterizedAssertionError(targetException, methodName, params),
59+
is(new ParameterizedAssertionError(targetException, methodName, params)));
60+
}
61+
62+
@Theory
63+
public void sameHashCodeWhenEquals(Throwable targetException, String methodName,
64+
Object[] params) {
65+
ParameterizedAssertionError one = new ParameterizedAssertionError(
66+
targetException, methodName, params);
67+
ParameterizedAssertionError two = new ParameterizedAssertionError(
68+
targetException, methodName, params);
69+
assumeThat(one, is(two));
70+
71+
assertThat(one.hashCode(), is(two.hashCode()));
6072
}
6173

6274
@Theory(nullsAccepted = false)
6375
public void buildParameterizedAssertionError(String methodName, String param) {
64-
assertThat(new ParameterizedAssertionError(new RuntimeException(),
65-
methodName, param).toString(), containsString(methodName));
76+
assertThat(new ParameterizedAssertionError(
77+
new RuntimeException(), methodName, param).toString(),
78+
containsString(methodName));
6679
}
6780

6881
@Theory

0 commit comments

Comments
 (0)