Ignore:
Timestamp:
2015-07-30T13:17:49+02:00 (10 years ago)
Author:
nokutu
Message:

Improved tests and code quality. Login is already working. Tests now do not requiere the JOSM window to be opened.

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  
    22
    33import org.junit.BeforeClass;
    4 import org.openstreetmap.josm.Main;
    5 import org.openstreetmap.josm.gui.MainApplication;
    64import org.openstreetmap.josm.plugins.mapillary.util.TestUtil;
    75
     6/**
     7 * Abstract class for tests that require JOSM's preferences running.
     8 *
     9 * @author nokutu
     10 *
     11 */
    812public abstract class AbstractTest {
    913
    1014  private static boolean started = false;
    1115
     16  /**
     17   * Initiates the basic parts of JOSM.
     18   */
    1219  @BeforeClass
    13   public static void setUpBeforeClass() throws Exception {
     20  public static void setUpBeforeClass() {
    1421    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();
    2223      started = true;
    23       while (Main.map == null || Main.map.mapView == null) {
    24         synchronized (Thread.currentThread()) {
    25           Thread.currentThread().wait(1000);
    26         }
    27       }
    2824    }
    2925  }
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/AllTests.java

    r31417 r31418  
    44import org.junit.runners.Suite;
    55import org.junit.runners.Suite.SuiteClasses;
    6 import org.openstreetmap.josm.plugins.mapillary.util.TestUtil;
    76
     7/**
     8 * Runs all tests.
     9 *
     10 * @author nokutu
     11 *
     12 */
    813@RunWith(Suite.class)
    9 @SuiteClasses({ ImportTest.class,
    10     MapillarySequenceDownloadThreadTest.class})
     14@SuiteClasses({ ImportTest.class, MapillarySequenceDownloadThreadTest.class })
    1115public class AllTests {
    1216}
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/ImportTest.java

    r31417 r31418  
    22
    33import static org.junit.Assert.*;
     4import org.junit.Test;
    45
    56import java.io.File;
     
    1011import org.apache.commons.imaging.common.RationalNumber;
    1112import 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;
    1513import org.openstreetmap.josm.Main;
    1614import org.openstreetmap.josm.data.coor.LatLon;
    17 import org.openstreetmap.josm.gui.MainApplication;
    1815import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryImportAction;
    1916
    20 public class ImportTest extends AbstractTest{
     17/**
     18 * Test the importation of images.
     19 *
     20 * @author nokutu
     21 *
     22 */
     23public class ImportTest extends AbstractTest {
    2124
     25  /**
     26   * Test the importation of images in PNG format.
     27   */
    2228  @Test
    23   public void importNoTagsTest() throws InterruptedException {
     29  public void importNoTagsTest() {
    2430    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));
    2633    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()));
    2836  }
    2937
    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)
    3144  public void testInvalidFiles() throws IOException {
    32       MapillaryImportedImage img = new MapillaryImportedImage(0,0,0, null);
    33       assertEquals(null, img.getImage());
    34       assertEquals(null, img.getFile());
     45    MapillaryImportedImage img = new MapillaryImportedImage(0, 0, 0, null);
     46    assertEquals(null, img.getImage());
     47    assertEquals(null, img.getFile());
    3548
    36       img = new MapillaryImportedImage(0, 0, 0, new File(""));
    37       assertEquals(new File(""), img.getFile());
    38       img.getImage();
     49    img = new MapillaryImportedImage(0, 0, 0, new File(""));
     50    assertEquals(new File(""), img.getFile());
     51    img.getImage();
    3952  }
    4053
     54  /**
     55   * Test degMinSecToDouble method.
     56   */
    4157  @Test
    4258  public void degMinSecToDoubleTest() {
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/util/TestUtil.java

    r31417 r31418  
    1111import org.openstreetmap.josm.tools.I18n;
    1212
     13/**
     14 *
     15 * Utilities for tests.
     16 *
     17 * @author floscher
     18 */
    1319public class TestUtil {
    14     private static boolean isInitialized;
     20  private static boolean isInitialized;
    1521
    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;
    1850    }
    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  }
    4652
    4753}
Note: See TracChangeset for help on using the changeset viewer.