Changeset 17658 in josm


Ignore:
Timestamp:
2021-03-24T23:04:25+01:00 (3 months ago)
Author:
simon04
Message:

see #20233 - SessionWriterTest.testWriteGpxAndMarkerJoz

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java

    r16913 r17658  
    1212import java.util.HashMap;
    1313import java.util.List;
     14import java.util.Locale;
    1415import java.util.Map;
    1516import java.util.Objects;
     
    271272        viewportEl.appendChild(scale);
    272273        double dist100px = mapView.getDist100Pixel();
    273         scale.setAttribute("meter-per-pixel", Double.toString(dist100px / 100));
     274        scale.setAttribute("meter-per-pixel", String.format(Locale.ROOT, "%6f", dist100px / 100));
    274275    }
    275276
  • trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java

    r17275 r17658  
    44import java.io.File;
    55import java.io.IOException;
     6import java.io.InputStream;
     7import java.nio.charset.StandardCharsets;
     8import java.nio.file.Files;
     9import java.nio.file.Path;
     10import java.nio.file.Paths;
    611import java.util.Arrays;
    712import java.util.Collections;
     
    914import java.util.List;
    1015import java.util.Map;
     16import java.util.zip.ZipFile;
    1117
    1218import org.junit.jupiter.api.BeforeEach;
    1319import org.junit.jupiter.api.Test;
    1420import org.junit.jupiter.api.extension.RegisterExtension;
     21import org.openstreetmap.josm.TestUtils;
    1522import org.openstreetmap.josm.data.coor.LatLon;
    1623import org.openstreetmap.josm.data.gpx.GpxData;
     
    3542import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    3643
     44import static org.junit.jupiter.api.Assertions.assertEquals;
     45
    3746/**
    3847 * Unit tests for Session writing.
     
    99108    }
    100109
    101     private void testWrite(List<Layer> layers, final boolean zip) throws IOException {
     110    private byte[] testWrite(List<Layer> layers, final boolean zip) throws IOException {
    102111        Map<Layer, SessionLayerExporter> exporters = new HashMap<>();
    103112        if (zip) {
     
    115124        try {
    116125            sw.write(file);
     126            if (!zip) {
     127                return null;
     128            }
     129            try (ZipFile zipFile = new ZipFile(file);
     130                 InputStream input = zipFile.getInputStream(zipFile.getEntry("session.jos"))) {
     131                return Utils.readBytesFromStream(input);
     132            }
    117133        } finally {
    118134            if (file.exists()) {
     
    213229    void testWriteGpxAndMarkerJoz() throws IOException {
    214230        GpxLayer gpx = createGpxLayer();
    215         testWrite(Arrays.asList(gpx, createMarkerLayer(gpx)), true);
     231        byte[] bytes = testWrite(Arrays.asList(gpx, createMarkerLayer(gpx)), true);
     232        Path path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/gpx_markers.jos");
     233        String expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
     234        String actual = new String(bytes, StandardCharsets.UTF_8).replace("\r", "");
     235        assertEquals(expected, actual);
    216236    }
    217237
Note: See TracChangeset for help on using the changeset viewer.