Changeset 17658 in josm for trunk/test/unit
- Timestamp:
- 2021-03-24T23:04:25+01:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java
r17275 r17658 4 4 import java.io.File; 5 5 import java.io.IOException; 6 import java.io.InputStream; 7 import java.nio.charset.StandardCharsets; 8 import java.nio.file.Files; 9 import java.nio.file.Path; 10 import java.nio.file.Paths; 6 11 import java.util.Arrays; 7 12 import java.util.Collections; … … 9 14 import java.util.List; 10 15 import java.util.Map; 16 import java.util.zip.ZipFile; 11 17 12 18 import org.junit.jupiter.api.BeforeEach; 13 19 import org.junit.jupiter.api.Test; 14 20 import org.junit.jupiter.api.extension.RegisterExtension; 21 import org.openstreetmap.josm.TestUtils; 15 22 import org.openstreetmap.josm.data.coor.LatLon; 16 23 import org.openstreetmap.josm.data.gpx.GpxData; … … 35 42 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 36 43 44 import static org.junit.jupiter.api.Assertions.assertEquals; 45 37 46 /** 38 47 * Unit tests for Session writing. … … 99 108 } 100 109 101 private voidtestWrite(List<Layer> layers, final boolean zip) throws IOException {110 private byte[] testWrite(List<Layer> layers, final boolean zip) throws IOException { 102 111 Map<Layer, SessionLayerExporter> exporters = new HashMap<>(); 103 112 if (zip) { … … 115 124 try { 116 125 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 } 117 133 } finally { 118 134 if (file.exists()) { … … 213 229 void testWriteGpxAndMarkerJoz() throws IOException { 214 230 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); 216 236 } 217 237
Note:
See TracChangeset
for help on using the changeset viewer.