Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandMoveImage.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandMoveImage.java	(revision 31475)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandMoveImage.java	(revision 31476)
@@ -3,5 +3,4 @@
 import static org.openstreetmap.josm.tools.I18n.trn;
 
-import java.util.ArrayList;
 import java.util.List;
 
@@ -31,5 +30,5 @@
   public CommandMoveImage(List<MapillaryAbstractImage> images, double x,
       double y) {
-    this.images = new ArrayList<>(images);
+    this.images = images;
     this.x = x;
     this.y = y;
@@ -43,5 +42,6 @@
     }
     checkModified();
-    Main.map.repaint();
+    if (Main.main != null)
+      Main.map.repaint();
   }
 
@@ -53,5 +53,6 @@
     }
     checkModified();
-    Main.map.repaint();
+    if (Main.main != null)
+      Main.map.repaint();
   }
 
Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandTurnImage.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandTurnImage.java	(revision 31475)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandTurnImage.java	(revision 31476)
@@ -3,5 +3,4 @@
 import static org.openstreetmap.josm.tools.I18n.trn;
 
-import java.util.ArrayList;
 import java.util.List;
 
@@ -27,5 +26,5 @@
    */
   public CommandTurnImage(List<MapillaryAbstractImage> images, double ca) {
-    this.images = new ArrayList<>(images);
+    this.images = images;
     this.ca = ca;
   }
@@ -38,5 +37,6 @@
     }
     checkModified();
-    Main.map.repaint();
+    if (Main.main != null)
+      Main.map.repaint();
   }
 
@@ -48,5 +48,6 @@
     }
     checkModified();
-    Main.map.repaint();
+    if (Main.main != null)
+      Main.map.repaint();
   }
 
Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecord.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecord.java	(revision 31475)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecord.java	(revision 31476)
@@ -6,5 +6,5 @@
 
 /**
- * History record system in order to let the user undo and redo commands
+ * History record system in order to let the user undo and redo commands.
  *
  * @author nokutu
@@ -97,5 +97,5 @@
   public void undo() {
     if (this.position == -1)
-      return;
+      throw new IllegalStateException();
     this.commandList.get(this.position).undo();
     this.position--;
@@ -104,9 +104,9 @@
 
   /**
-   * Redo latest undoed action.
+   * Redoes latest undone action.
    */
   public void redo() {
     if (this.position + 1 >= this.commandList.size())
-      return;
+      throw new IllegalStateException();
     this.position++;
     this.commandList.get(this.position).redo();
Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java	(revision 31475)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java	(revision 31476)
@@ -87,4 +87,3 @@
     isTokenValid = true;
   }
-
 }
Index: applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecordTest.java
===================================================================
--- applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecordTest.java	(revision 31476)
+++ applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecordTest.java	(revision 31476)
@@ -0,0 +1,147 @@
+package org.openstreetmap.josm.plugins.mapillary.commands;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openstreetmap.josm.plugins.mapillary.AbstractTest;
+import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
+import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
+
+/**
+ * Tests the command record system.
+ *
+ * @author nokutu
+ *
+ */
+public class MapillaryRecordTest extends AbstractTest {
+
+  MapillaryRecord record;
+  MapillaryImage img1;
+  MapillaryImage img2;
+  MapillaryImage img3;
+
+  /**
+   * Creates a new {@link MapillaryRecord} object and 3 {@link MapillaryImage}
+   * objects.
+   */
+  @Before
+  public void setUp() {
+    this.record = new MapillaryRecord();
+    this.img1 = new MapillaryImage("key1", 0.1, 0.1, 0.1);
+    this.img2 = new MapillaryImage("key2", 0.2, 0.2, 0.2);
+    this.img3 = new MapillaryImage("key3", 0.3, 0.3, 0.3);
+  }
+
+  /**
+   * Test commands in general.
+   */
+  @Test
+  public void commandTest() {
+    MapillaryCommand cmd1 = new CommandMoveImage(
+        Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 }),
+        0.1, 0.1);
+    MapillaryCommand cmd2 = new CommandMoveImage(
+        Arrays.asList(new MapillaryAbstractImage[] { this.img2, this.img3 }),
+        0.1, 0.1);
+    MapillaryCommand cmd3 = new CommandMoveImage(
+        Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img3 }),
+        0.1, 0.1);
+    MapillaryCommand cmd31 = new CommandMoveImage(
+        Arrays.asList(new MapillaryAbstractImage[] { this.img3, this.img1 }),
+        0.2, 0.2);
+    this.record.addCommand(cmd1);
+    this.record.addCommand(cmd2);
+
+    assertEquals(1, this.record.position);
+    assertEquals(2, this.record.commandList.size());
+
+    this.record.undo();
+
+    assertEquals(0, this.record.position);
+    assertEquals(2, this.record.commandList.size());
+
+    this.record.addCommand(cmd3);
+
+    assertEquals(1, this.record.position);
+    assertEquals(2, this.record.commandList.size());
+
+    this.record.undo();
+    this.record.redo();
+
+    assertEquals(1, this.record.position);
+    assertEquals(2, this.record.commandList.size());
+
+    this.record.addCommand(cmd31);
+
+    assertEquals(1, this.record.position);
+    assertEquals(2, this.record.commandList.size());
+  }
+
+  /**
+   * Tests CommandMoveImage class.
+   */
+  @Test
+  public void commandMoveTest() {
+    CommandMoveImage cmd1 = new CommandMoveImage(
+        Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 }),
+        0.1, 0.1);
+    CommandMoveImage cmd2 = new CommandMoveImage(
+        Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 }),
+        0.1, 0.1);
+
+    this.record.addCommand(cmd1);
+
+    assertEquals(0.1, this.img1.getLatLon().lat(), 0.01);
+
+    this.record.undo();
+
+    assertEquals(0.0, this.img1.getLatLon().lat(), 0.01);
+
+    this.record.redo();
+
+    assertEquals(0.1, this.img1.getLatLon().lat(), 0.01);
+
+    this.record.addCommand(cmd2);
+    this.record.undo();
+
+    assertEquals(-0.1, this.img1.getLatLon().lat(), 0.01);
+
+    this.record.redo();
+
+    assertEquals(0.1, this.img1.getLatLon().lat(), 0.01);
+  }
+
+  /**
+   * Tests CommandTurnImage class.
+   */
+  @Test
+  public void commandTurnTest() {
+    CommandTurnImage cmd1 = new CommandTurnImage(
+        Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 }),
+        0.2);
+    CommandTurnImage cmd2 = new CommandTurnImage(
+        Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 }),
+        0.1);
+
+    this.record.addCommand(cmd1);
+    this.record.undo();
+
+    assertEquals(-0.1, this.img1.getCa(), 0.01);
+
+    this.record.redo();
+
+    assertEquals(0.1, this.img1.getCa(), 0.01);
+
+    this.record.addCommand(cmd2);
+    this.record.undo();
+
+    assertEquals(-0.2, this.img1.getCa(), 0.01);
+
+    this.record.redo();
+
+    assertEquals(0.1, this.img1.getCa(), 0.01);
+  }
+}
