-
Notifications
You must be signed in to change notification settings - Fork 59
/
AbstractEqualsTest.java
43 lines (36 loc) · 1.17 KB
/
AbstractEqualsTest.java
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 edu.hm.hafner.util;
import org.junit.jupiter.api.Test;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import static org.assertj.core.api.Assertions.*;
/**
* Verifies that objects of any Java class comply with the contract in {@link Object#equals(Object)}.
*
* @author Ullrich Hafner
*/
public abstract class AbstractEqualsTest {
/**
* Creates the subject under test.
*
* @return the SUT
*/
protected abstract Object createSut();
/**
* Verifies that for any non-null reference value {@code x}, {@code x.equals(null)} should return {@code false}.
*/
@Test
@SuppressFBWarnings("EC")
@SuppressWarnings({"PMD.EqualsNull", "checkstyle:equalsavoidnull", "ConstantConditions"})
void shouldReturnFalseOnEqualsNull() {
assertThat(createSut().equals(null)).isFalse();
}
/**
* Verifies that equals is <i>reflexive</i>: for any non-null reference value {@code x}, {@code x.equals(x)} should
* return {@code true}.
*/
@SuppressWarnings("EqualsWithItself")
@Test
void shouldReturnTrueOnEqualsThis() {
var sut = createSut();
assertThat(sut.equals(sut)).isTrue();
}
}