Ignore:
Timestamp:
2019-04-01T07:46:58+02:00 (5 years ago)
Author:
GerdP
Message:

see #17459: remove duplicated code in reverter corehacks
Step 1: Add needed code to core methods.
Major changes:
1) If a changeset contains multiple versions for a primitive, class ChangesetDataSet keeps the first and the last version (not just the last) and provides methods to access them, unused method getPrimitivesByModificationType() was removed
2) The changeset reader classes have a new field useAnonymousUser. If set, the user found in a changeset is replaced by the anonymous user.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetDataSetTest.java

    r12620 r14946  
    99import java.util.Date;
    1010import java.util.Iterator;
    11 import java.util.Set;
    1211
    1312import org.junit.Rule;
     
    1817import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
    1918import org.openstreetmap.josm.data.osm.history.HistoryNode;
    20 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
    2119import org.openstreetmap.josm.testutils.JOSMTestRules;
    2220import org.openstreetmap.josm.tools.Logging;
     
    3533    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3634    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     }
    7335
    7436    /**
Note: See TracChangeset for help on using the changeset viewer.