This repository was archived by the owner on Apr 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathEqualsAndHashCodeTest.java
More file actions
43 lines (37 loc) · 1.57 KB
/
EqualsAndHashCodeTest.java
File metadata and controls
43 lines (37 loc) · 1.57 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
package me.alidg.errors;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static me.alidg.Params.p;
import static me.alidg.errors.Argument.arg;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Generic unit test that checks equals and hashCode contract.
*/
public class EqualsAndHashCodeTest {
@ParameterizedTest
@MethodSource("provideParams")
public void testEqualsAndHashCode(Object obj, Object equalObj, Object notEqualObj) {
assertThat(obj).isNotEqualTo(null);
assertThat(obj).isEqualTo(obj);
assertThat(obj).isEqualTo(equalObj);
assertThat(obj).isNotEqualTo(notEqualObj);
assertThat(obj.hashCode()).isEqualTo(equalObj.hashCode());
}
private static Object[] provideParams() {
return p(
p(arg("name", "value"), arg("name", "value"), arg("differentName", "differentValue")),
p(
new HttpError.CodedMessage("code", "message", emptyList()),
new HttpError.CodedMessage("code", "message", emptyList()),
new HttpError.CodedMessage("code", "differentMessage", emptyList())
),
p(
new HttpError.CodedMessage("code", "message", emptyList()),
new HttpError.CodedMessage("code", "message", emptyList()),
new HttpError.CodedMessage("code", "message", singletonList(arg("foo", "bar")))
)
);
}
}