1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
7 | import static org.junit.jupiter.api.Assertions.fail;
|
---|
8 |
|
---|
9 | import java.util.Date;
|
---|
10 | import java.util.Iterator;
|
---|
11 |
|
---|
12 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
13 | import org.junit.jupiter.api.Test;
|
---|
14 | import org.openstreetmap.josm.TestUtils;
|
---|
15 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
16 | import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetDataSetEntry;
|
---|
17 | import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
|
---|
18 | import org.openstreetmap.josm.data.osm.history.HistoryNode;
|
---|
19 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
20 | import org.openstreetmap.josm.tools.Logging;
|
---|
21 |
|
---|
22 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Unit tests for class {@link ChangesetDataSet}.
|
---|
26 | */
|
---|
27 | class ChangesetDataSetTest {
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Setup test.
|
---|
31 | */
|
---|
32 | @RegisterExtension
|
---|
33 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
34 | public JOSMTestRules test = new JOSMTestRules();
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Unit test of method {@link ChangesetDataSet#iterator}.
|
---|
38 | */
|
---|
39 | @Test
|
---|
40 | void testIterator() {
|
---|
41 | final ChangesetDataSet cds = new ChangesetDataSet();
|
---|
42 | HistoryNode prim1 = new HistoryNode(1, 1, true, User.getAnonymous(), 1, new Date(), LatLon.ZERO);
|
---|
43 | cds.put(prim1, ChangesetModificationType.CREATED);
|
---|
44 | Iterator<ChangesetDataSetEntry> it = cds.iterator();
|
---|
45 | assertTrue(it.hasNext());
|
---|
46 | ChangesetDataSetEntry cdse = it.next();
|
---|
47 | assertEquals(ChangesetModificationType.CREATED, cdse.getModificationType());
|
---|
48 | assertEquals(prim1, cdse.getPrimitive());
|
---|
49 | assertFalse(it.hasNext());
|
---|
50 | try {
|
---|
51 | it.remove();
|
---|
52 | fail("remove should throw UnsupportedOperationException");
|
---|
53 | } catch (UnsupportedOperationException e) {
|
---|
54 | Logging.trace(e.getMessage());
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Unit test of method {@link ChangesetDataSet#getFirstEntry(PrimitiveId)} and {@link ChangesetDataSet#getLastEntry(PrimitiveId)}.
|
---|
60 | */
|
---|
61 | @Test
|
---|
62 | void testGetEntry() {
|
---|
63 | final ChangesetDataSet cds = new ChangesetDataSet();
|
---|
64 | HistoryNode prim1 = new HistoryNode(1, 1, true, User.getAnonymous(), 1, new Date(), LatLon.ZERO);
|
---|
65 | cds.put(prim1, ChangesetModificationType.CREATED);
|
---|
66 | HistoryNode prim2 = new HistoryNode(1, 2, true, User.getAnonymous(), 1, new Date(), LatLon.ZERO);
|
---|
67 | prim2.put("highway", "stop");
|
---|
68 | cds.put(prim2, ChangesetModificationType.UPDATED);
|
---|
69 | assertEquals(prim1, cds.getFirstEntry(prim1.getPrimitiveId()).getPrimitive());
|
---|
70 | assertEquals(prim2, cds.getLastEntry(prim1.getPrimitiveId()).getPrimitive());
|
---|
71 | HistoryNode prim3 = new HistoryNode(1, 3, false, User.getAnonymous(), 1, new Date(), null);
|
---|
72 |
|
---|
73 | cds.put(prim3, ChangesetModificationType.DELETED);
|
---|
74 | assertEquals(prim1, cds.getFirstEntry(prim1.getPrimitiveId()).getPrimitive());
|
---|
75 | assertEquals(prim3, cds.getLastEntry(prim1.getPrimitiveId()).getPrimitive());
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Unit test of {@link ChangesetModificationType} enum.
|
---|
80 | */
|
---|
81 | @Test
|
---|
82 | void testEnumChangesetModificationType() {
|
---|
83 | TestUtils.superficialEnumCodeCoverage(ChangesetModificationType.class);
|
---|
84 | }
|
---|
85 | }
|
---|