Changeset 31418 in osm for applications/editors/josm/plugins/mapillary/test/unit
- Timestamp:
- 2015-07-30T13:17:49+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/AbstractTest.java
r31417 r31418 2 2 3 3 import org.junit.BeforeClass; 4 import org.openstreetmap.josm.Main;5 import org.openstreetmap.josm.gui.MainApplication;6 4 import org.openstreetmap.josm.plugins.mapillary.util.TestUtil; 7 5 6 /** 7 * Abstract class for tests that require JOSM's preferences running. 8 * 9 * @author nokutu 10 * 11 */ 8 12 public abstract class AbstractTest { 9 13 10 14 private static boolean started = false; 11 15 16 /** 17 * Initiates the basic parts of JOSM. 18 */ 12 19 @BeforeClass 13 public static void setUpBeforeClass() throws Exception{20 public static void setUpBeforeClass() { 14 21 if (!started) { 15 new Thread() { 16 @Override 17 public synchronized void run() { 18 MainApplication 19 .main(new String[] { "--download=http://www.openstreetmap.org/#map=18/40.42013/-3.68923" }); 20 } 21 }.start(); 22 TestUtil.initPlugin(); 22 23 started = true; 23 while (Main.map == null || Main.map.mapView == null) {24 synchronized (Thread.currentThread()) {25 Thread.currentThread().wait(1000);26 }27 }28 24 } 29 25 } -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/AllTests.java
r31417 r31418 4 4 import org.junit.runners.Suite; 5 5 import org.junit.runners.Suite.SuiteClasses; 6 import org.openstreetmap.josm.plugins.mapillary.util.TestUtil;7 6 7 /** 8 * Runs all tests. 9 * 10 * @author nokutu 11 * 12 */ 8 13 @RunWith(Suite.class) 9 @SuiteClasses({ ImportTest.class, 10 MapillarySequenceDownloadThreadTest.class}) 14 @SuiteClasses({ ImportTest.class, MapillarySequenceDownloadThreadTest.class }) 11 15 public class AllTests { 12 16 } -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/ImportTest.java
r31417 r31418 2 2 3 3 import static org.junit.Assert.*; 4 import org.junit.Test; 4 5 5 6 import java.io.File; … … 10 11 import org.apache.commons.imaging.common.RationalNumber; 11 12 import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants; 12 import org.junit.BeforeClass;13 import org.junit.Test;14 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;15 13 import org.openstreetmap.josm.Main; 16 14 import org.openstreetmap.josm.data.coor.LatLon; 17 import org.openstreetmap.josm.gui.MainApplication;18 15 import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryImportAction; 19 16 20 public class ImportTest extends AbstractTest{ 17 /** 18 * Test the importation of images. 19 * 20 * @author nokutu 21 * 22 */ 23 public class ImportTest extends AbstractTest { 21 24 25 /** 26 * Test the importation of images in PNG format. 27 */ 22 28 @Test 23 public void importNoTagsTest() throws InterruptedException{29 public void importNoTagsTest() { 24 30 File image = new File(MapillaryPlugin.directory + "images/icon16.png"); 25 MapillaryImportedImage img = MapillaryPlugin.importAction.readNoTags(image); 31 MapillaryImportedImage img = MapillaryPlugin.importAction.readNoTags(image, 32 new LatLon(0, 0)); 26 33 assertEquals(0, img.getCa(), 0.01); 27 assert(Main.map.mapView.getRealBounds().getCenter().equalsEpsilon(img.getLatLon())); 34 assert (Main.map.mapView.getRealBounds().getCenter().equalsEpsilon(img 35 .getLatLon())); 28 36 } 29 37 30 @Test(expected=IIOException.class) 38 /** 39 * Test if provided an invalid file, the proper exception is thrown. 40 * 41 * @throws IOException 42 */ 43 @Test(expected = IIOException.class) 31 44 public void testInvalidFiles() throws IOException { 32 0,0, null);33 34 45 MapillaryImportedImage img = new MapillaryImportedImage(0, 0, 0, null); 46 assertEquals(null, img.getImage()); 47 assertEquals(null, img.getFile()); 35 48 36 37 38 49 img = new MapillaryImportedImage(0, 0, 0, new File("")); 50 assertEquals(new File(""), img.getFile()); 51 img.getImage(); 39 52 } 40 53 54 /** 55 * Test degMinSecToDouble method. 56 */ 41 57 @Test 42 58 public void degMinSecToDoubleTest() { -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/util/TestUtil.java
r31417 r31418 11 11 import org.openstreetmap.josm.tools.I18n; 12 12 13 /** 14 * 15 * Utilities for tests. 16 * 17 * @author floscher 18 */ 13 19 public class TestUtil { 14 20 private static boolean isInitialized; 15 21 16 private TestUtil() { 17 // Prevent instantiation 22 private TestUtil() { 23 // Prevent instantiation 24 } 25 26 /** 27 * Initializes the {@link Main} class of JOSM and the mapillary plugin with 28 * the preferences from test/data/preferences. 29 * 30 * That is needed e.g. to use {@link MapillaryLayer#getInstance()} 31 */ 32 public static final void initPlugin() { 33 if (!isInitialized) { 34 System.setProperty("josm.home", "test/data/preferences"); 35 Main.initApplicationPreferences(); 36 Main.pref.enableSaveOnPut(false); 37 I18n.init(); 38 Main.determinePlatformHook(); 39 Main.platform.preStartupHook(); 40 Main.pref.init(false); 41 I18n.set(Main.pref.get("language", "en")); 42 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator 43 try { 44 new MapillaryPlugin(new PluginInformation(new File( 45 "./build/libs/josm-mapillary-plugin.jar"))); 46 } catch (PluginException e) { 47 e.printStackTrace(); 48 } 49 isInitialized = true; 18 50 } 19 20 /** 21 * Initializes the {@link Main} class of JOSM and the mapillary plugin 22 * with the preferences from test/data/preferences. 23 * 24 * That is needed e.g. to use {@link MapillaryLayer#getInstance()} 25 */ 26 public static final void initPlugin() { 27 if (!isInitialized) { 28 System.setProperty("josm.home", "test/data/preferences"); 29 Main.initApplicationPreferences(); 30 Main.pref.enableSaveOnPut(false); 31 I18n.init(); 32 Main.determinePlatformHook(); 33 Main.platform.preStartupHook(); 34 Main.pref.init(false); 35 I18n.set(Main.pref.get("language", "en")); 36 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator 37 try { 38 new MapillaryPlugin(new PluginInformation(new File("/home/nokutu/.josm/plugins/Mapillary.jar"))); 39 } catch (PluginException e) { 40 // TODO Auto-generated catch block 41 e.printStackTrace(); 42 } 43 isInitialized = true; 44 } 45 } 51 } 46 52 47 53 }
Note:
See TracChangeset
for help on using the changeset viewer.