1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertFalse;
|
---|
6 | import static org.junit.Assert.assertTrue;
|
---|
7 | import static org.junit.Assert.fail;
|
---|
8 |
|
---|
9 | import java.util.Date;
|
---|
10 | import java.util.Iterator;
|
---|
11 | import java.util.Set;
|
---|
12 |
|
---|
13 | import org.junit.Rule;
|
---|
14 | import org.junit.Test;
|
---|
15 | import org.openstreetmap.josm.TestUtils;
|
---|
16 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
17 | import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetDataSetEntry;
|
---|
18 | import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
|
---|
19 | import org.openstreetmap.josm.data.osm.history.HistoryNode;
|
---|
20 | import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
|
---|
21 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
22 | import org.openstreetmap.josm.tools.Logging;
|
---|
23 |
|
---|
24 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Unit tests for class {@link ChangesetDataSet}.
|
---|
28 | */
|
---|
29 | public class ChangesetDataSetTest {
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Setup test.
|
---|
33 | */
|
---|
34 | @Rule
|
---|
35 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
36 | public JOSMTestRules test = new JOSMTestRules();
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Unit test of method {@link ChangesetDataSet#getPrimitivesByModificationType}.
|
---|
40 | */
|
---|
41 | @Test
|
---|
42 | public void testGetPrimitivesByModificationType() {
|
---|
43 | final ChangesetDataSet cds = new ChangesetDataSet();
|
---|
44 | // empty object, null parameter => IllegalArgumentException
|
---|
45 | try {
|
---|
46 | cds.getPrimitivesByModificationType(null);
|
---|
47 | fail("Should have thrown an IllegalArgumentException as we gave a null argument.");
|
---|
48 | } catch (IllegalArgumentException e) {
|
---|
49 | Logging.trace(e);
|
---|
50 | // Was expected
|
---|
51 | }
|
---|
52 |
|
---|
53 | // empty object, a modification type => empty list
|
---|
54 | assertTrue(
|
---|
55 | "Empty data set should produce an empty list.",
|
---|
56 | cds.getPrimitivesByModificationType(
|
---|
57 | ChangesetModificationType.CREATED).isEmpty()
|
---|
58 | );
|
---|
59 |
|
---|
60 | // object with various items and modification types, fetch for CREATED
|
---|
61 | // => list containing only the CREATED item
|
---|
62 | HistoryNode prim1 = new HistoryNode(1, 1, true, User.getAnonymous(), 1, new Date(), LatLon.ZERO);
|
---|
63 | HistoryNode prim2 = new HistoryNode(2, 1, true, User.createLocalUser("test"), 1, new Date(), LatLon.NORTH_POLE);
|
---|
64 | HistoryNode prim3 = new HistoryNode(3, 1, true, User.getAnonymous(), 1, new Date(), LatLon.SOUTH_POLE);
|
---|
65 | cds.put(prim1, ChangesetModificationType.CREATED);
|
---|
66 | cds.put(prim2, ChangesetModificationType.DELETED);
|
---|
67 | cds.put(prim3, ChangesetModificationType.UPDATED);
|
---|
68 | Set<HistoryOsmPrimitive> result = cds.getPrimitivesByModificationType(
|
---|
69 | ChangesetModificationType.CREATED);
|
---|
70 | assertEquals("We should have found only one item.", 1, result.size());
|
---|
71 | assertTrue("The item found is prim1.", result.contains(prim1));
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Unit test of method {@link ChangesetDataSet#iterator}.
|
---|
76 | */
|
---|
77 | @Test
|
---|
78 | public void testIterator() {
|
---|
79 | final ChangesetDataSet cds = new ChangesetDataSet();
|
---|
80 | HistoryNode prim1 = new HistoryNode(1, 1, true, User.getAnonymous(), 1, new Date(), LatLon.ZERO);
|
---|
81 | cds.put(prim1, ChangesetModificationType.CREATED);
|
---|
82 | Iterator<ChangesetDataSetEntry> it = cds.iterator();
|
---|
83 | assertTrue(it.hasNext());
|
---|
84 | ChangesetDataSetEntry cdse = it.next();
|
---|
85 | assertEquals(ChangesetModificationType.CREATED, cdse.getModificationType());
|
---|
86 | assertEquals(prim1, cdse.getPrimitive());
|
---|
87 | assertFalse(it.hasNext());
|
---|
88 | try {
|
---|
89 | it.remove();
|
---|
90 | fail("remove should throw UnsupportedOperationException");
|
---|
91 | } catch (UnsupportedOperationException e) {
|
---|
92 | Logging.trace(e.getMessage());
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Unit test of {@link ChangesetModificationType} enum.
|
---|
98 | */
|
---|
99 | @Test
|
---|
100 | public void testEnumChangesetModificationType() {
|
---|
101 | TestUtils.superficialEnumCodeCoverage(ChangesetModificationType.class);
|
---|
102 | }
|
---|
103 | }
|
---|