1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import org.junit.Rule;
|
---|
5 | import org.junit.Test;
|
---|
6 | import org.junit.Assert;
|
---|
7 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
8 | import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
|
---|
9 |
|
---|
10 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
11 | import java.util.Date;
|
---|
12 | import java.util.Set;
|
---|
13 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
14 | import org.openstreetmap.josm.data.osm.history.HistoryNode;
|
---|
15 | import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Unit tests for class {@link ChangesetDataSet}.
|
---|
19 | */
|
---|
20 | public class ChangesetDataSetTest {
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Setup test.
|
---|
24 | */
|
---|
25 | @Rule
|
---|
26 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
27 | public JOSMTestRules test = new JOSMTestRules();
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Unit test of method {@link ChangesetDataSet#getPrimitivesByModificationType}.
|
---|
31 | */
|
---|
32 | @Test
|
---|
33 | public void testGetPrimitivesByModificationType() {
|
---|
34 | final ChangesetDataSet cds = new ChangesetDataSet();
|
---|
35 | // empty object, null parameter => IllegalArgumentException
|
---|
36 | try {
|
---|
37 | cds.getPrimitivesByModificationType(null);
|
---|
38 | Assert.fail("Should have thrown an IllegalArgumentException as we gave a null argument.");
|
---|
39 | } catch (IllegalArgumentException e) {
|
---|
40 | // Was expected
|
---|
41 | }
|
---|
42 |
|
---|
43 | // empty object, a modification type => empty list
|
---|
44 | Assert.assertTrue(
|
---|
45 | "Empty data set should produce an empty list.",
|
---|
46 | cds.getPrimitivesByModificationType(
|
---|
47 | ChangesetModificationType.CREATED).isEmpty()
|
---|
48 | );
|
---|
49 |
|
---|
50 | // object with various items and modification types, fetch for CREATED
|
---|
51 | // => list containing only the CREATED item
|
---|
52 | HistoryOsmPrimitive prim1 = new HistoryNode(1, 1, true, User.getAnonymous(), 1, new Date(), LatLon.ZERO);
|
---|
53 | HistoryOsmPrimitive prim2 = new HistoryNode(2, 1, true, User.createLocalUser("test"), 1, new Date(), LatLon.NORTH_POLE);
|
---|
54 | HistoryOsmPrimitive prim3 = new HistoryNode(3, 1, true, User.getAnonymous(), 1, new Date(), LatLon.SOUTH_POLE);
|
---|
55 | cds.put(prim1, ChangesetModificationType.CREATED);
|
---|
56 | cds.put(prim2, ChangesetModificationType.DELETED);
|
---|
57 | cds.put(prim3, ChangesetModificationType.UPDATED);
|
---|
58 | Set<HistoryOsmPrimitive> result = cds.getPrimitivesByModificationType(
|
---|
59 | ChangesetModificationType.CREATED);
|
---|
60 | Assert.assertEquals("We should have found only one item.", 1, result.size());
|
---|
61 | Assert.assertTrue("The item found is prim1.", result.contains(prim1));
|
---|
62 |
|
---|
63 | }
|
---|
64 | }
|
---|