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.time.Instant;
|
---|
10 | import java.util.Iterator;
|
---|
11 |
|
---|
12 | import org.junit.jupiter.api.Test;
|
---|
13 | import org.openstreetmap.josm.TestUtils;
|
---|
14 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
15 | import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetDataSetEntry;
|
---|
16 | import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
|
---|
17 | import org.openstreetmap.josm.data.osm.history.HistoryNode;
|
---|
18 | import org.openstreetmap.josm.tools.Logging;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit tests for class {@link ChangesetDataSet}.
|
---|
22 | */
|
---|
23 | class ChangesetDataSetTest {
|
---|
24 | /**
|
---|
25 | * Unit test of method {@link ChangesetDataSet#iterator}.
|
---|
26 | */
|
---|
27 | @Test
|
---|
28 | void testIterator() {
|
---|
29 | final ChangesetDataSet cds = new ChangesetDataSet();
|
---|
30 | HistoryNode prim1 = new HistoryNode(1, 1, true, User.getAnonymous(), 1, Instant.now(), LatLon.ZERO);
|
---|
31 | cds.put(prim1, ChangesetModificationType.CREATED);
|
---|
32 | Iterator<ChangesetDataSetEntry> it = cds.iterator();
|
---|
33 | assertTrue(it.hasNext());
|
---|
34 | ChangesetDataSetEntry cdse = it.next();
|
---|
35 | assertEquals(ChangesetModificationType.CREATED, cdse.getModificationType());
|
---|
36 | assertEquals(prim1, cdse.getPrimitive());
|
---|
37 | assertFalse(it.hasNext());
|
---|
38 | try {
|
---|
39 | it.remove();
|
---|
40 | fail("remove should throw UnsupportedOperationException");
|
---|
41 | } catch (UnsupportedOperationException e) {
|
---|
42 | Logging.trace(e.getMessage());
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Unit test of method {@link ChangesetDataSet#getFirstEntry(PrimitiveId)} and {@link ChangesetDataSet#getLastEntry(PrimitiveId)}.
|
---|
48 | */
|
---|
49 | @Test
|
---|
50 | void testGetEntry() {
|
---|
51 | final ChangesetDataSet cds = new ChangesetDataSet();
|
---|
52 | HistoryNode prim1 = new HistoryNode(1, 1, true, User.getAnonymous(), 1, Instant.now(), LatLon.ZERO);
|
---|
53 | cds.put(prim1, ChangesetModificationType.CREATED);
|
---|
54 | HistoryNode prim2 = new HistoryNode(1, 2, true, User.getAnonymous(), 1, Instant.now(), LatLon.ZERO);
|
---|
55 | prim2.put("highway", "stop");
|
---|
56 | cds.put(prim2, ChangesetModificationType.UPDATED);
|
---|
57 | assertEquals(prim1, cds.getFirstEntry(prim1.getPrimitiveId()).getPrimitive());
|
---|
58 | assertEquals(prim2, cds.getLastEntry(prim1.getPrimitiveId()).getPrimitive());
|
---|
59 | HistoryNode prim3 = new HistoryNode(1, 3, false, User.getAnonymous(), 1, Instant.now(), null);
|
---|
60 |
|
---|
61 | cds.put(prim3, ChangesetModificationType.DELETED);
|
---|
62 | assertEquals(prim1, cds.getFirstEntry(prim1.getPrimitiveId()).getPrimitive());
|
---|
63 | assertEquals(prim3, cds.getLastEntry(prim1.getPrimitiveId()).getPrimitive());
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Unit test of {@link ChangesetModificationType} enum.
|
---|
68 | */
|
---|
69 | @Test
|
---|
70 | void testEnumChangesetModificationType() {
|
---|
71 | TestUtils.superficialEnumCodeCoverage(ChangesetModificationType.class);
|
---|
72 | }
|
---|
73 | }
|
---|