Changeset 14797 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java
r14456 r14797 176 176 } 177 177 178 private static Double getElevation(WayPoint wp) { 179 String value = wp.getString(GpxConstants.PT_ELE); 180 if (value != null && !value.isEmpty()) { 181 try { 182 return Double.valueOf(value); 183 } catch (NumberFormatException e) { 184 Logging.warn(e); 178 static Double getElevation(WayPoint wp) { 179 if (wp != null) { 180 String value = wp.getString(GpxConstants.PT_ELE); 181 if (value != null && !value.isEmpty()) { 182 try { 183 return Double.valueOf(value); 184 } catch (NumberFormatException e) { 185 Logging.warn(e); 186 } 185 187 } 186 188 } -
trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxImageCorrelationTest.java
r14205 r14797 4 4 import static org.junit.Assert.assertEquals; 5 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertNull; 6 7 import static org.junit.Assert.assertTrue; 7 8 … … 14 15 import org.openstreetmap.josm.TestUtils; 15 16 import org.openstreetmap.josm.data.coor.CachedLatLon; 17 import org.openstreetmap.josm.data.coor.LatLon; 16 18 import org.openstreetmap.josm.io.GpxReaderTest; 17 19 import org.openstreetmap.josm.spi.preferences.Config; … … 267 269 } 268 270 } 271 272 /** 273 * Unit test of {@link GpxImageCorrelation#getElevation} 274 */ 275 @Test 276 public void testGetElevation() { 277 assertNull(GpxImageCorrelation.getElevation(null)); 278 WayPoint wp = new WayPoint(LatLon.ZERO); 279 assertNull(GpxImageCorrelation.getElevation(wp)); 280 wp.put(GpxConstants.PT_ELE, ""); 281 assertNull(GpxImageCorrelation.getElevation(wp)); 282 wp.put(GpxConstants.PT_ELE, "not a number"); 283 assertNull(GpxImageCorrelation.getElevation(wp)); 284 wp.put(GpxConstants.PT_ELE, "150.0"); 285 assertEquals(Double.valueOf(150.0d), GpxImageCorrelation.getElevation(wp)); 286 } 269 287 }
Note:
See TracChangeset
for help on using the changeset viewer.