source: josm/trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java@ 9660

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

GeoImageLayer: add unit test, fix sonar issues, add javadoc

File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.geoimage;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.io.File;
8import java.io.InputStream;
9import java.util.Collections;
10import java.util.List;
11
12import org.junit.BeforeClass;
13import org.junit.Test;
14import org.openstreetmap.josm.JOSMFixture;
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.TestUtils;
17import org.openstreetmap.josm.gui.layer.GpxLayer;
18import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer.Loader;
19import org.openstreetmap.josm.io.GpxReader;
20
21/**
22 * Unit tests of {@link GeoImageLayer} class.
23 */
24public class GeoImageLayerTest {
25
26 /**
27 * Setup test.
28 */
29 @BeforeClass
30 public static void setUpBeforeClass() {
31 JOSMFixture.createUnitTestFixture().init(true);
32 }
33
34 /**
35 * Unit test of {@link Loader} class.
36 * @throws Exception if any error occurs
37 */
38 @Test
39 public void testLoader() throws Exception {
40 try (InputStream in = TestUtils.getRegressionDataStream(12255, "bobrava2.gpx")) {
41 GpxReader reader = new GpxReader(in);
42 assertTrue(reader.parse(true));
43 GpxLayer gpxLayer = new GpxLayer(reader.getGpxData());
44 Main.main.addLayer(gpxLayer);
45 assertEquals(1, Main.map.mapView.getNumLayers());
46 new Loader(
47 Collections.singleton(new File(TestUtils.getRegressionDataFile(12255, "G0016941.JPG"))),
48 gpxLayer).run();
49 assertEquals(2, Main.map.mapView.getNumLayers());
50 GeoImageLayer layer = Main.map.mapView.getLayersOfType(GeoImageLayer.class).iterator().next();
51 assertEquals(gpxLayer, layer.getGpxLayer());
52 List<ImageEntry> images = layer.getImages();
53 assertEquals(1, images.size());
54 assertEquals("<html>1 image loaded. 0 were found to be GPS tagged.</html>", layer.getInfoComponent());
55 assertEquals("<html>1 image loaded. 0 were found to be GPS tagged.</html>", layer.getToolTipText());
56 }
57 }
58}
Note: See TracBrowser for help on using the repository browser.