source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetDataSetTest.java@ 11115

Last change on this file since 11115 was 11115, checked in by simon04, 8 years ago

fix #13785 - Use streams, add unit tests (patch by alno, modified)

File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import org.junit.Rule;
5import org.junit.Test;
6import org.junit.Assert;
7import org.openstreetmap.josm.testutils.JOSMTestRules;
8import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
9
10import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11import java.util.Date;
12import java.util.Set;
13import org.openstreetmap.josm.data.coor.LatLon;
14import org.openstreetmap.josm.data.osm.history.HistoryNode;
15import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
16
17/**
18 * Unit tests for class {@link ChangesetDataSet}.
19 */
20public 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}
Note: See TracBrowser for help on using the repository browser.