Changeset 12479 in josm for trunk/test


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.