Index: /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java	(revision 31417)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java	(revision 31418)
@@ -68,86 +68,87 @@
    */
   public synchronized void add(List<MapillaryAbstractImage> images) {
+    add(images, true);
+  }
+
+  /**
+   * Adds an MapillaryImage to the object, and then repaints mapView.
+   *
+   * @param image
+   *          The image to be added.
+   */
+  public synchronized void add(MapillaryAbstractImage image) {
+    add(image, true);
+  }
+
+  /**
+   * Adds a new listener.
+   *
+   * @param lis
+   *          Listener to be added.
+   */
+  public void addListener(MapillaryDataListener lis) {
+    listeners.add(lis);
+  }
+
+  /**
+   * Removes a listener.
+   *
+   * @param lis
+   *          Listener to be removed.
+   */
+  public void removeListener(MapillaryDataListener lis) {
+    listeners.remove(lis);
+  }
+
+  /**
+   * Adds a set of MapillaryImages to the object, but doesn't repaint mapView.
+   * This is needed for concurrency.
+   *
+   * @param images
+   *          The set of images to be added.
+   * @param update
+   *          Whether the map must be updated or no.
+   */
+  public synchronized void add(List<MapillaryAbstractImage> images,
+      boolean update) {
     for (MapillaryAbstractImage image : images) {
-      add(image);
-    }
-  }
-
-  /**
-   * Adds an MapillaryImage to the object, and then repaints mapView.
+      add(image, update);
+    }
+  }
+
+  /**
+   * Highlights the image under the cursor.
+   *
+   * @param image
+   *          The image under the cursor.
+   */
+  public void setHighlightedImage(MapillaryAbstractImage image) {
+    highlightedImage = image;
+  }
+
+  /**
+   * Returns the image under the mouse cursor.
+   *
+   * @return The image under the mouse cursor.
+   */
+  public MapillaryAbstractImage getHighlighted() {
+    return highlightedImage;
+  }
+
+  /**
+   * Adds a MapillaryImage to the object, but doesn't repaint mapView. This is
+   * needed for concurrency.
    *
    * @param image
    *          The image to be added.
-   */
-  public synchronized void add(MapillaryAbstractImage image) {
+   * @param update
+   *          Whether the map must be updated or not.
+   */
+  public synchronized void add(MapillaryAbstractImage image, boolean update) {
     if (!images.contains(image)) {
       this.images.add(image);
     }
-    dataUpdated();
-    fireImagesAdded();
-  }
-
-  /**
-   * Adds a new listener.
-   *
-   * @param lis
-   *          Listener to be added.
-   */
-  public void addListener(MapillaryDataListener lis) {
-    listeners.add(lis);
-  }
-
-  /**
-   * Removes a listener.
-   *
-   * @param lis
-   *          Listener to be removed.
-   */
-  public void removeListener(MapillaryDataListener lis) {
-    listeners.remove(lis);
-  }
-
-  /**
-   * Adds a set of MapillaryImages to the object, but doesn't repaint mapView.
-   * This is needed for concurrency.
-   *
-   * @param images
-   *          The set of images to be added.
-   */
-  public synchronized void addWithoutUpdate(List<MapillaryAbstractImage> images) {
-    for (MapillaryAbstractImage image : images) {
-      addWithoutUpdate(image);
-    }
-  }
-
-  /**
-   * Highlights the image under the cursor.
-   *
-   * @param image
-   *          The image under the cursor.
-   */
-  public void setHighlightedImage(MapillaryAbstractImage image) {
-    highlightedImage = image;
-  }
-
-  /**
-   * Returns the image under the mouse cursor.
-   *
-   * @return The image under the mouse cursor.
-   */
-  public MapillaryAbstractImage getHighlighted() {
-    return highlightedImage;
-  }
-
-  /**
-   * Adds a MapillaryImage to the object, but doesn't repaint mapView. This is
-   * needed for concurrency.
-   *
-   * @param image
-   *          The image to be added.
-   */
-  public synchronized void addWithoutUpdate(MapillaryAbstractImage image) {
-    if (!images.contains(image)) {
-      this.images.add(image);
-    }
+    if (update)
+      dataUpdated();
     fireImagesAdded();
   }
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 31417)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java	(revision 31418)
@@ -52,4 +52,5 @@
   private final MapillaryDownloadAction downloadAction;
   private final MapillaryExportAction exportAction;
+  /** Import action */
   public static MapillaryImportAction importAction;
   private final MapillaryZoomAction zoomAction;
Index: /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java	(revision 31417)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java	(revision 31418)
@@ -50,7 +50,8 @@
    */
   public MapillaryImportAction() {
-    super(tr("Import pictures"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"),
-        tr("Import local pictures"), Shortcut.registerShortcut(
-            "Import Mapillary", tr("Import pictures into Mapillary layer"),
+    super(tr("Import pictures"), new ImageProvider(MapillaryPlugin.directory
+        + "images/icon24.png"), tr("Import local pictures"), Shortcut
+        .registerShortcut("Import Mapillary",
+            tr("Import pictures into Mapillary layer"),
             KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, "mapillaryImport",
         false);
@@ -174,4 +175,21 @@
    */
   public MapillaryImportedImage readNoTags(File file) {
+    return readNoTags(
+        file,
+        Main.map.mapView.getProjection().eastNorth2latlon(
+            Main.map.mapView.getCenter()));
+  }
+
+  /**
+   * Reads a image file that doesn't contain the needed GPS information. And
+   * creates a new icon in the middle of the map.
+   *
+   * @param file
+   * @param pos
+   *          A {@link LatLon} object indicating the position in the map where
+   *          the image must be set.
+   * @return The imported image.
+   */
+  public MapillaryImportedImage readNoTags(File file, LatLon pos) {
     double HORIZONTAL_DISTANCE = 0.0001;
     double horDev;
@@ -180,6 +198,4 @@
     else
       horDev = -HORIZONTAL_DISTANCE * ((noTagsPics + 1) / 2);
-    LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon(
-        Main.map.mapView.getCenter());
     noTagsPics++;
     return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file);
@@ -246,11 +262,4 @@
     result += degMinSec[2].doubleValue() / 3600; // seconds
 
-    while (result >= 180) {
-      result -= 180;
-    }
-    while (result <= -180) {
-      result += 180;
-    }
-
     if (GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH.equals(ref)
         || GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST.equals(ref)) {
@@ -258,4 +267,5 @@
     }
 
+    result = 360*((result+180)/360 - Math.floor((result+180)/360)) - 180;
     return result;
   }
Index: /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java	(revision 31417)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java	(revision 31418)
@@ -33,5 +33,5 @@
   public final static String BASE_URL = "https://a.mapillary.com/v2/";
   /** Client ID for the app */
-  public final static String CLIENT_ID = "NzNRM2otQkR2SHJzaXJmNmdQWVQ0dzo1YTA2NmNlODhlNWMwOTBm";
+  public final static String CLIENT_ID = "T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz";
   /** Executor that will run the petitions. */
   private static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(3, 5,
Index: /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java	(revision 31417)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java	(revision 31418)
@@ -118,6 +118,6 @@
         }
 
-        layer.getMapillaryData().addWithoutUpdate(
-            new ArrayList<MapillaryAbstractImage>(finalImages));
+        layer.getMapillaryData().add(
+            new ArrayList<MapillaryAbstractImage>(finalImages), false);
       }
     } catch (IOException e) {
@@ -125,4 +125,5 @@
           + " might be a Mapillary problem.");
     }
+    layer.getMapillaryData().dataUpdated();
   }
 
Index: /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java	(revision 31417)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java	(revision 31418)
@@ -84,5 +84,5 @@
       oauth.setText("Login");
     else
-      oauth.setText("Already loged in, click to relogin.");
+      oauth.setText("Logged as: " + Main.pref.get("mapillary.username") + ". Click to relogin.");
     panel.add(oauth);
     gui.getDisplayPreference().addSubTab(this, "Mapillary", panel);
@@ -130,5 +130,5 @@
       portListener.start();
 
-      String url = "http://www.mapillary.io/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id=MkJKbDA0bnZuZlcxeTJHTmFqN3g1dzplZTlkZjQyYjYyZTczOTdi&response_type=token&scope=user:email";
+      String url = "http://www.mapillary.com/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&response_type=token&scope=user:read%20public:upload%20public:write";
       Desktop desktop = Desktop.getDesktop();
       if (desktop.isSupported(Desktop.Action.BROWSE)) {
Index: /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java	(revision 31417)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java	(revision 31418)
@@ -8,4 +8,5 @@
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.net.URL;
 import java.util.Scanner;
 
@@ -25,6 +26,8 @@
       ServerSocket serverSocket = new ServerSocket(8763);
       Socket clientSocket = serverSocket.accept();
-      PrintWriter out = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream(), "UTF-8"), true);
-      Scanner in = new Scanner(new InputStreamReader(clientSocket.getInputStream(), "UTF-8"));
+      PrintWriter out = new PrintWriter(new OutputStreamWriter(
+          clientSocket.getOutputStream(), "UTF-8"), true);
+      Scanner in = new Scanner(new InputStreamReader(
+          clientSocket.getInputStream(), "UTF-8"));
       String s;
       String accessToken = null;
@@ -41,16 +44,30 @@
           }
           break;
-        }
+        } else if (s.contains("keep-alive"))
+          break;
       }
 
       writeContent(out);
 
-      Main.info("Successful login with Mapillary, the access token is: "
-          + accessToken);
-      Main.pref.put("mapillary.access-token", accessToken);
-
       out.close();
       in.close();
       serverSocket.close();
+
+      Main.info("Successful login with Mapillary, the access token is: "
+          + accessToken);
+      // Saves the access token in preferences.
+      Main.pref.put("mapillary.access-token", accessToken);
+      // Sets the logged username in preferences.
+      Main.pref
+          .put(
+              "mapillary.username",
+              OAuthUtils
+                  .getWithHeader(
+                      new URL(
+                          "https://a.mapillary.com/v2/me?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz"))
+                  .getString("username"));
+
+      Main.info("The username is: " + Main.pref.get("mapillary.username"));
+
     } catch (BindException e) {
       return;
Index: /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java	(revision 31418)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java	(revision 31418)
@@ -0,0 +1,43 @@
+package org.openstreetmap.josm.plugins.mapillary.oauth;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import javax.json.Json;
+import javax.json.JsonObject;
+
+import org.openstreetmap.josm.Main;
+
+/**
+ * A set of utilities related to OAuth.
+ *
+ * @author nokutu
+ *
+ */
+public class OAuthUtils {
+
+  /** URL where to upload the images. */
+  public static final String MAPILLARY_UPLOAD_URL = "https://s3-eu-west-1.amazonaws.com/mapillary.uploads.manual.images";
+
+  /**
+   * Returns a JsonObject containing the result of making a GET request with the
+   * authorization header.
+   *
+   * @param url
+   * @return A JsonObject containing the result of the GET request.
+   * @throws IOException
+   */
+  public static JsonObject getWithHeader(URL url) throws IOException {
+    HttpURLConnection con = (HttpURLConnection) url.openConnection();
+    con.setRequestMethod("GET");
+    con.setRequestProperty("Authorization",
+        "Bearer " + Main.pref.get("mapillary.access-token"));
+
+    BufferedReader in = new BufferedReader(new InputStreamReader(
+        con.getInputStream()));
+    return Json.createReader(in).readObject();
+  }
+}
Index: /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/AbstractTest.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/AbstractTest.java	(revision 31417)
+++ /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/AbstractTest.java	(revision 31418)
@@ -2,28 +2,24 @@
 
 import org.junit.BeforeClass;
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.plugins.mapillary.util.TestUtil;
 
+/**
+ * Abstract class for tests that require JOSM's preferences running.
+ *
+ * @author nokutu
+ *
+ */
 public abstract class AbstractTest {
 
   private static boolean started = false;
 
+  /**
+   * Initiates the basic parts of JOSM.
+   */
   @BeforeClass
-  public static void setUpBeforeClass() throws Exception {
+  public static void setUpBeforeClass() {
     if (!started) {
-      new Thread() {
-        @Override
-        public synchronized void run() {
-          MainApplication
-              .main(new String[] { "--download=http://www.openstreetmap.org/#map=18/40.42013/-3.68923" });
-        }
-      }.start();
+      TestUtil.initPlugin();
       started = true;
-      while (Main.map == null || Main.map.mapView == null) {
-        synchronized (Thread.currentThread()) {
-          Thread.currentThread().wait(1000);
-        }
-      }
     }
   }
Index: /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/AllTests.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/AllTests.java	(revision 31417)
+++ /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/AllTests.java	(revision 31418)
@@ -4,9 +4,13 @@
 import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
-import org.openstreetmap.josm.plugins.mapillary.util.TestUtil;
 
+/**
+ * Runs all tests.
+ *
+ * @author nokutu
+ *
+ */
 @RunWith(Suite.class)
-@SuiteClasses({ ImportTest.class,
-    MapillarySequenceDownloadThreadTest.class})
+@SuiteClasses({ ImportTest.class, MapillarySequenceDownloadThreadTest.class })
 public class AllTests {
 }
Index: /applications/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 31417)
+++ /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/ImportTest.java	(revision 31418)
@@ -2,4 +2,5 @@
 
 import static org.junit.Assert.*;
+import org.junit.Test;
 
 import java.io.File;
@@ -10,33 +11,48 @@
 import org.apache.commons.imaging.common.RationalNumber;
 import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryImportAction;
 
-public class ImportTest extends AbstractTest{
+/**
+ * Test the importation of images.
+ *
+ * @author nokutu
+ *
+ */
+public class ImportTest extends AbstractTest {
 
+  /**
+   * Test the importation of images in PNG format.
+   */
   @Test
-  public void importNoTagsTest() throws InterruptedException {
+  public void importNoTagsTest() {
     File image = new File(MapillaryPlugin.directory + "images/icon16.png");
-    MapillaryImportedImage img = MapillaryPlugin.importAction.readNoTags(image);
+    MapillaryImportedImage img = MapillaryPlugin.importAction.readNoTags(image,
+        new LatLon(0, 0));
     assertEquals(0, img.getCa(), 0.01);
-    assert(Main.map.mapView.getRealBounds().getCenter().equalsEpsilon(img.getLatLon()));
+    assert (Main.map.mapView.getRealBounds().getCenter().equalsEpsilon(img
+        .getLatLon()));
   }
 
-  @Test(expected=IIOException.class)
+  /**
+   * Test if provided an invalid file, the proper exception is thrown.
+   *
+   * @throws IOException
+   */
+  @Test(expected = IIOException.class)
   public void testInvalidFiles() throws IOException {
-      MapillaryImportedImage img = new MapillaryImportedImage(0,0,0, null);
-      assertEquals(null, img.getImage());
-      assertEquals(null, img.getFile());
+    MapillaryImportedImage img = new MapillaryImportedImage(0, 0, 0, null);
+    assertEquals(null, img.getImage());
+    assertEquals(null, img.getFile());
 
-      img = new MapillaryImportedImage(0, 0, 0, new File(""));
-      assertEquals(new File(""), img.getFile());
-      img.getImage();
+    img = new MapillaryImportedImage(0, 0, 0, new File(""));
+    assertEquals(new File(""), img.getFile());
+    img.getImage();
   }
 
+  /**
+   * Test degMinSecToDouble method.
+   */
   @Test
   public void degMinSecToDoubleTest() {
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 31417)
+++ /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/util/TestUtil.java	(revision 31418)
@@ -11,37 +11,43 @@
 import org.openstreetmap.josm.tools.I18n;
 
+/**
+ *
+ * Utilities for tests.
+ *
+ * @author floscher
+ */
 public class TestUtil {
-    private static boolean isInitialized;
+  private static boolean isInitialized;
 
-    private TestUtil() {
-        // Prevent instantiation
+  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
+      try {
+        new MapillaryPlugin(new PluginInformation(new File(
+            "./build/libs/josm-mapillary-plugin.jar")));
+      } catch (PluginException e) {
+        e.printStackTrace();
+      }
+      isInitialized = true;
     }
-
-    /**
-     * 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
-            try {
-              new MapillaryPlugin(new PluginInformation(new File("/home/nokutu/.josm/plugins/Mapillary.jar")));
-            } catch (PluginException e) {
-              // TODO Auto-generated catch block
-              e.printStackTrace();
-            }
-            isInitialized = true;
-        }
-    }
+  }
 
 }
