Changeset 13485 in josm for trunk/test


Ignore:
Timestamp:
2018-03-03T16:20:56+01:00 (18 months ago)
Author:
Don-vip
Message:

see #8039, see #10456 - keep layer download/upload/locked flags when saving to .osm file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/io/OsmWriterTest.java

    r10717 r13485  
    33
    44import static org.junit.Assert.assertArrayEquals;
     5import static org.junit.Assert.assertEquals;
    56
     7import java.io.ByteArrayOutputStream;
     8import java.io.IOException;
     9import java.io.PrintWriter;
    610import java.util.ArrayList;
    711import java.util.Arrays;
     
    1014
    1115import org.junit.Test;
     16import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
     17import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    1218import org.openstreetmap.josm.data.osm.NodeData;
    1319
     
    3743        }, longIds);
    3844    }
     45
     46    /**
     47     * Unit test of {@link OsmWriter#header(DownloadPolicy, UploadPolicy)}.
     48     * @throws IOException if an I/O error occurs
     49     */
     50    @Test
     51    public void testHeader() throws IOException {
     52        doTestHeader(null, null,
     53                "<osm version='0.6' generator='JOSM'>");
     54        doTestHeader(DownloadPolicy.NORMAL, UploadPolicy.NORMAL,
     55                "<osm version='0.6' generator='JOSM'>");
     56        doTestHeader(DownloadPolicy.BLOCKED, UploadPolicy.BLOCKED,
     57                "<osm version='0.6' download='never' upload='never' generator='JOSM'>");
     58    }
     59
     60    private static void doTestHeader(DownloadPolicy download, UploadPolicy upload, String expected) throws IOException {
     61        ByteArrayOutputStream baos = new ByteArrayOutputStream();
     62        try (PrintWriter out = new PrintWriter(baos);
     63             OsmWriter writer = OsmWriterFactory.createOsmWriter(out, true, OsmWriter.DEFAULT_API_VERSION)) {
     64            writer.header(download, upload);
     65        }
     66        assertEquals("<?xml version='1.0' encoding='UTF-8'?>" + expected,
     67                baos.toString("UTF-8").replaceAll("\r", "").replaceAll("\n", ""));
     68    }
    3969}
Note: See TracChangeset for help on using the changeset viewer.