Changeset 12479 in josm


Ignore:
Timestamp:
2017-07-16T20:12:45+02:00 (4 months ago)
Author:
Don-vip
Message:

see #14833 - fix DataSet copy constructor, add unit test

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r12329 r12479  
    234234            Collection<Relation> relations = copyFrom.getRelations();
    235235            for (Relation r : relations) {
    236                 Relation newRelation = new Relation(r, r.isNew());
     236                Relation newRelation = new Relation(r);
    237237                newRelation.setMembers(null);
    238238                primMap.put(r, newRelation);
     
    251251            }
    252252            version = copyFrom.version;
     253            uploadPolicy = copyFrom.uploadPolicy;
    253254        } finally {
    254255            copyFrom.getReadLock().unlock();
  • trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetTest.java

    r12069 r12479  
    1414import org.junit.Test;
    1515import org.openstreetmap.josm.data.coor.LatLon;
     16import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    1617import org.openstreetmap.josm.testutils.JOSMTestRules;
    1718
     
    164165        ds.toggleSelected(n2.getPrimitiveId());
    165166        assertEquals(Arrays.asList(n3, n1), new ArrayList<>(ds.getSelected()));
    166 
     167    }
     168
     169    /**
     170     * Unit test for {@link DataSet#DataSet(DataSet)}.
     171     */
     172    @Test
     173    public void testCopyConstructor() {
     174        DataSet ds = new DataSet();
     175        assertEqualsDataSet(ds, new DataSet(ds));
     176
     177        ds.setVersion("fake_version");
     178        ds.setUploadPolicy(UploadPolicy.BLOCKED);
     179        Node n1 = new Node(LatLon.SOUTH_POLE);
     180        Node n2 = new Node(LatLon.NORTH_POLE);
     181        Way w = new Way(1);
     182        w.setNodes(Arrays.asList(n1, n2));
     183        ds.addPrimitive(n1);
     184        ds.addPrimitive(n2);
     185        ds.addPrimitive(w);
     186        Relation r1 = new Relation(1);
     187        Relation r2 = new Relation(2);
     188        r2.addMember(new RelationMember("role1", n1));
     189        r2.addMember(new RelationMember("role2", w));
     190        r2.addMember(new RelationMember("role3", r1));
     191        ds.addPrimitive(r1);
     192        ds.addPrimitive(r2);
     193        assertEqualsDataSet(ds, new DataSet(ds));
     194    }
     195
     196    private static void assertEqualsDataSet(DataSet ds1, DataSet ds2) {
     197        assertEquals(new ArrayList<>(ds1.getNodes()), new ArrayList<>(ds2.getNodes()));
     198        assertEquals(new ArrayList<>(ds1.getWays()), new ArrayList<>(ds2.getWays()));
     199        assertEquals(new ArrayList<>(ds1.getRelations()), new ArrayList<>(ds2.getRelations()));
     200        assertEquals(new ArrayList<>(ds1.getDataSources()), new ArrayList<>(ds2.getDataSources()));
     201        assertEquals(ds1.getUploadPolicy(), ds2.getUploadPolicy());
     202        assertEquals(ds1.getVersion(), ds2.getVersion());
    167203    }
    168204}
Note: See TracChangeset for help on using the changeset viewer.