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