source: josm/trunk/test/unit/org/openstreetmap/josm/io/OsmReaderTest.java@ 12087

Last change on this file since 12087 was 12087, checked in by Don-vip, 7 years ago

fix #14754 - avoid silent failure with invalid lat/lon coordinates in .osm file

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNull;
6import static org.junit.Assert.assertTrue;
7import static org.junit.Assert.fail;
8
9import java.io.InputStream;
10
11import org.junit.Test;
12import org.openstreetmap.josm.TestUtils;
13import org.openstreetmap.josm.data.osm.Way;
14import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
15
16/**
17 * Unit tests of {@link OsmReader} class.
18 */
19public class OsmReaderTest {
20
21 /**
22 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/14199">Bug #14199</a>.
23 * @throws Exception if any error occurs
24 */
25 @Test
26 public void testTicket14199() throws Exception {
27 try (InputStream in = TestUtils.getRegressionDataStream(14199, "emptytag.osm")) {
28 Way w = OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE).getWays().iterator().next();
29 assertEquals(1, w.getKeys().size());
30 assertNull(w.get(" "));
31 assertTrue(w.isModified());
32 }
33 }
34
35 /**
36 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/14754">Bug #14754</a>.
37 * @throws Exception if any error occurs
38 */
39 @Test
40 public void testTicket14754() throws Exception {
41 try (InputStream in = TestUtils.getRegressionDataStream(14754, "malformed_for_14754.osm")) {
42 OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE);
43 fail("should throw exception");
44 } catch (IllegalDataException e) {
45 assertEquals("Illegal value for attributes 'lat', 'lon' on node with ID 1425146006." +
46 " Got '550.3311950157', '10.49428298298'." +
47 " (at line 5, column 179). 578 bytes have been read", e.getMessage());
48 }
49 }
50}
Note: See TracBrowser for help on using the repository browser.