Skip to content

Commit 98ac6e4

Browse files
committed
fix: add test
1 parent 1cb07e2 commit 98ac6e4

File tree

1 file changed

+84
-0
lines changed
  • src/test/java/fr/insee/pearljam/domain/surveyunit/model/contacthistory

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package fr.insee.pearljam.domain.surveyunit.model.contacthistory;
2+
3+
import fr.insee.pearljam.api.domain.Source;
4+
import fr.insee.pearljam.api.domain.Title;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.HashSet;
8+
import java.util.Set;
9+
10+
import static org.junit.jupiter.api.Assertions.*;
11+
12+
class PersonTest {
13+
14+
private ContactHistory contactHistory(String comment) {
15+
return new ContactHistory(ContactHistoryType.PREVIOUS,
16+
comment,
17+
HistoryContactOutcomeType.IMP,
18+
new HashSet<>()
19+
);
20+
}
21+
22+
private final ContactHistory niceCH = contactHistory("nice comment");
23+
private final ContactHistory otherNiceCH = contactHistory("other nice comment");
24+
25+
private Person base(ContactHistory ch) {
26+
Person person = new Person(1L,
27+
Title.MISTER,
28+
"John",
29+
"Doe",
30+
"john@doe.fr",
31+
123456789L,
32+
true,
33+
Boolean.TRUE,
34+
Set.of(new PhoneNumber(Source.INTERVIEWER, true, "0600000000")),
35+
ch
36+
);
37+
ch.persons().add(person);
38+
return person;
39+
}
40+
41+
@Test
42+
void equals_sameInstance_true() {
43+
Person p = base(niceCH);
44+
assertEquals(p, p);
45+
}
46+
47+
@Test
48+
void equals_null_false() {
49+
Person p = base(niceCH);
50+
assertNotEquals(null, p);
51+
}
52+
53+
@Test
54+
void equals_otherType_false() {
55+
Person p = base(niceCH);
56+
assertNotEquals("not a person", p);
57+
}
58+
59+
@Test
60+
void equals_sameFields_true_evenIfContactHistoryDiffers() {
61+
Person p1 = base(niceCH);
62+
Person p2 = base(otherNiceCH);
63+
64+
assertEquals(p1, p2);
65+
assertEquals(p1.hashCode(), p2.hashCode(), "hashCode must match when equals is true");
66+
}
67+
68+
@Test
69+
void equals_oneFieldDifferent_false() {
70+
Person p1 = base(niceCH);
71+
Person p2 = new Person(2L, // id differs
72+
Title.MISTER,
73+
"John",
74+
"Doe",
75+
"john@doe.fr",
76+
123456789L,
77+
true,
78+
Boolean.TRUE,
79+
Set.of(new PhoneNumber(Source.INTERVIEWER, true, "0600000000")), otherNiceCH);
80+
81+
assertNotEquals(p1, p2);
82+
}
83+
}
84+

0 commit comments

Comments
 (0)