Index: /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java	(revision 31346)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java	(revision 31347)
@@ -109,7 +109,10 @@
                 Main.map.mapView.getEditLayer().data.addDataSetListener(this);
         }
-        MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, true);
-        if (!MapillaryMainDialog.getInstance().isShowing())
-            MapillaryMainDialog.getInstance().getButton().doClick();
+        if (MapillaryPlugin.EXPORT_MENU != null) { // Does not execute when in headless mode
+            MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, true);
+            if (!MapillaryMainDialog.getInstance().isShowing())
+                MapillaryMainDialog.getInstance().getButton().doClick();
+        }
+
         createHatchTexture();
         data.dataUpdated();
Index: /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java	(revision 31346)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java	(revision 31347)
@@ -69,14 +69,16 @@
         downloadViewAction = new MapillaryDownloadViewAction();
 
-        DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu,
-                downloadAction, false);
-        EXPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, exportAction,
-                false, 14);
-        IMPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, importAction,
-                false, 14);
-        ZOOM_MENU = MainMenu
-                .add(Main.main.menu.viewMenu, zoomAction, false, 15);
-        DOWNLOAD_VIEW_MENU = MainMenu.add(Main.main.menu.fileMenu,
-                downloadViewAction, false, 14);
+        if (Main.main != null) { // important for headless mode
+            DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu,
+                    downloadAction, false);
+            EXPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, exportAction,
+                    false, 14);
+            IMPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, importAction,
+                    false, 14);
+            ZOOM_MENU = MainMenu
+                    .add(Main.main.menu.viewMenu, zoomAction, false, 15);
+            DOWNLOAD_VIEW_MENU = MainMenu.add(Main.main.menu.fileMenu,
+                    downloadViewAction, false, 14);
+        }
 
         EXPORT_MENU.setEnabled(false);
Index: /applications/editors/josm/plugins/mapillary/test/data/preferences/preferences.xml
===================================================================
--- /applications/editors/josm/plugins/mapillary/test/data/preferences/preferences.xml	(revision 31347)
+++ /applications/editors/josm/plugins/mapillary/test/data/preferences/preferences.xml	(revision 31347)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<preferences xmlns="http://josm.openstreetmap.de/preferences-1.0">
+  <tag key='expert' value='true'/>
+  <tag key='language' value='en'/>
+</preferences>
Index: plications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/ImportTest.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/ImportTest.java	(revision 31346)
+++ 	(revision )
@@ -1,25 +1,0 @@
-package org.openstreetmap.josm.plugins.mapillary;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-
-import org.junit.Before;
-import org.junit.Test;
-
-public class ImportTest {
-
-	@Before
-	public void setUp() {
-		MapillaryData.TEST_MODE = true;
-
-	}
-	
-
-    @Test(expected=IllegalArgumentException.class)
-    public void test() throws IOException {
-        MapillaryImportedImage img = new MapillaryImportedImage(0,0,0, null);
-        img.getImage();
-    }
-
-}
Index: /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/ImportedImageTest.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/ImportedImageTest.java	(revision 31347)
+++ /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/ImportedImageTest.java	(revision 31347)
@@ -0,0 +1,22 @@
+package org.openstreetmap.josm.plugins.mapillary;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class ImportedImageTest {
+
+	@Before
+	public void setUp() {
+		MapillaryData.TEST_MODE = true;
+
+	}
+	
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testNullFile() throws IOException {
+        MapillaryImportedImage img = new MapillaryImportedImage(0,0,0, null);
+        img.getImage();
+    }
+}
Index: /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/MapillarySequenceDownloadThreadTest.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/MapillarySequenceDownloadThreadTest.java	(revision 31347)
+++ /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/MapillarySequenceDownloadThreadTest.java	(revision 31347)
@@ -0,0 +1,75 @@
+/**
+ *
+ */
+package org.openstreetmap.josm.plugins.mapillary;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Locale;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openstreetmap.josm.data.Bounds;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
+import org.openstreetmap.josm.plugins.mapillary.downloads.MapillarySequenceDownloadThread;
+import org.openstreetmap.josm.plugins.mapillary.util.TestUtil;
+
+/**
+ *
+ */
+public class MapillarySequenceDownloadThreadTest {
+
+    /**
+     * @throws java.lang.Exception
+     */
+    @Before
+    public void setUp() {
+        MapillaryData.TEST_MODE = true;
+        TestUtil.initPlugin();
+    }
+
+    /**
+     * Test method for {@link org.openstreetmap.josm.plugins.mapillary.downloads.MapillarySequenceDownloadThread#run()}.
+     *
+     * This downloads a small area of mapillary-sequences where we know that images already exist.
+     * When the download-thread finishes, we check if the Mapillary-layer now contains one or more images.
+     *
+     * @throws InterruptedException
+     */
+    @Test
+    public void testRun() throws InterruptedException {
+	System.out.println("[JUnit] MapillarySequenceDownloadThreadTest.testRun()");
+        //Area around image UjEbeXZYIoyAKOsE-remlg (59.32125452° N 18.06166856° E)
+        LatLon minLatLon = new LatLon(59.3212545, 18.0616685);
+        LatLon maxLatLon = new LatLon(59.3212546, 18.0616686);
+
+        ExecutorService ex = Executors.newSingleThreadExecutor();
+        String url = String.format(
+            Locale.UK,
+            "%ssearch/s?max_lat=%.8f&max_lon=%.8f&min_lat=%.8f&min_lon=%.8f&limit=10&client_id=%s",
+            MapillaryDownloader.BASE_URL,
+            maxLatLon.lat(),
+            maxLatLon.lon(),
+            minLatLon.lat(),
+            minLatLon.lon(),
+            MapillaryDownloader.CLIENT_ID
+        );
+        MapillaryLayer.getInstance().bounds.add(new Bounds(minLatLon, maxLatLon));
+
+        int page = 1;
+        while (!ex.isShutdown() && MapillaryLayer.getInstance().getMapillaryData().getImages().size() <= 0 && page < 50) {
+            System.out.println("Sending sequence-request "+page+" to Mapillary-servers…");
+            Thread downloadThread = new MapillarySequenceDownloadThread(ex, url+"&page="+page, MapillaryLayer.getInstance(), null);
+            downloadThread.start();
+            downloadThread.join();
+            page++;
+            Thread.sleep(500);
+        }
+        assertTrue(MapillaryLayer.getInstance().getMapillaryData().getImages().size() >= 1);
+        System.out.println("One or more images were added to the MapillaryLayer within the given bounds.");
+    }
+
+}
Index: /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/util/TestUtil.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/util/TestUtil.java	(revision 31347)
+++ /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/util/TestUtil.java	(revision 31347)
@@ -0,0 +1,37 @@
+package org.openstreetmap.josm.plugins.mapillary.util;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.projection.Projections;
+import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
+import org.openstreetmap.josm.tools.I18n;
+
+public class TestUtil {
+    private static boolean isInitialized;
+
+    private TestUtil() {
+        // Prevent instantiation
+    }
+
+    /**
+     * Initializes the {@link Main} class of JOSM and the mapillary plugin
+     * with the preferences from test/data/preferences.
+     *
+     * That is needed e.g. to use {@link MapillaryLayer#getInstance()}
+     */
+    public static final void initPlugin() {
+        if (!isInitialized) {
+            System.setProperty("josm.home", "test/data/preferences");
+            Main.initApplicationPreferences();
+            Main.pref.enableSaveOnPut(false);
+            I18n.init();
+            Main.determinePlatformHook();
+            Main.platform.preStartupHook();
+            Main.pref.init(false);
+            I18n.set(Main.pref.get("language", "en"));
+            Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
+
+            isInitialized = true;
+        }
+    }
+
+}
