1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.notes;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
---|
6 |
|
---|
7 | import java.util.Date;
|
---|
8 |
|
---|
9 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
10 | import org.junit.jupiter.api.Test;
|
---|
11 | import org.openstreetmap.josm.TestUtils;
|
---|
12 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
13 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
14 |
|
---|
15 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
16 | import nl.jqno.equalsverifier.EqualsVerifier;
|
---|
17 | import nl.jqno.equalsverifier.Warning;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Unit tests for class {@link NoteComment}.
|
---|
21 | */
|
---|
22 | class NoteTest {
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Setup test.
|
---|
26 | */
|
---|
27 | @RegisterExtension
|
---|
28 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
29 | public JOSMTestRules test = new JOSMTestRules();
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Unit test of {@link Note#toString} method.
|
---|
33 | */
|
---|
34 | @Test
|
---|
35 | void testToString() {
|
---|
36 | Note note = new Note(LatLon.ZERO);
|
---|
37 | assertEquals("Note 0: null", note.toString());
|
---|
38 | note.addComment(new NoteComment(new Date(), null, "foo", null, true));
|
---|
39 | assertEquals("Note 0: foo", note.toString());
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Unit test of {@link Note#updateWith} method.
|
---|
44 | */
|
---|
45 | @Test
|
---|
46 | void testUpdateWith() {
|
---|
47 | Note n1 = new Note(LatLon.ZERO);
|
---|
48 | n1.setId(1);
|
---|
49 | Note n2 = new Note(LatLon.ZERO);
|
---|
50 | n1.setId(2);
|
---|
51 | assertNotEquals(n1, n2);
|
---|
52 | n1.updateWith(n2);
|
---|
53 | assertEquals(n1, n2);
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Unit test of methods {@link Note#equals} and {@link Note#hashCode}.
|
---|
58 | */
|
---|
59 | @Test
|
---|
60 | void testEqualsContract() {
|
---|
61 | TestUtils.assumeWorkingEqualsVerifier();
|
---|
62 | EqualsVerifier.forClass(Note.class).usingGetClass()
|
---|
63 | .withIgnoredFields("latLon", "createdAt", "closedAt", "state", "comments")
|
---|
64 | .suppress(Warning.NONFINAL_FIELDS)
|
---|
65 | .withPrefabValues(LatLon.class, LatLon.ZERO, new LatLon(1, 1))
|
---|
66 | .withPrefabValues(NoteComment.class,
|
---|
67 | new NoteComment(new Date(), null, "foo", null, true),
|
---|
68 | new NoteComment(new Date(), null, "bar", null, false))
|
---|
69 | .verify();
|
---|
70 | }
|
---|
71 | }
|
---|