Index: /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java	(revision 32591)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java	(revision 32592)
@@ -77,54 +77,54 @@
       this.mouseIsDragging = false;
       MapillaryImageDisplay.this.selectedRect = null;
-      if (image == null)
-        return;
-      // Calculate the mouse cursor position in image coordinates, so that
-      // we can center the zoom
-      // on that mouse position.
-      // To avoid issues when the user tries to zoom in on the image
-      // borders, this point is not calculated
-      // again if there was less than 1.5seconds since the last event.
-      if (e.getWhen() - this.lastTimeForMousePoint > 1500 || this.mousePointInImg == null) {
-        this.lastTimeForMousePoint = e.getWhen();
-        this.mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY());
-      }
-      // Set the zoom to the visible rectangle in image coordinates
-      if (e.getWheelRotation() > 0) {
-        visibleRect.width = visibleRect.width * 3 / 2;
-        visibleRect.height = visibleRect.height * 3 / 2;
-      } else {
-        visibleRect.width = visibleRect.width * 2 / 3;
-        visibleRect.height = visibleRect.height * 2 / 3;
-      }
-      // Check that the zoom doesn't exceed 2:1
-      if (visibleRect.width < getSize().width / 2) {
-        visibleRect.width = getSize().width / 2;
-      }
-      if (visibleRect.height < getSize().height / 2) {
-        visibleRect.height = getSize().height / 2;
-      }
-      // Set the same ratio for the visible rectangle and the display area
-      int hFact = visibleRect.height * getSize().width;
-      int wFact = visibleRect.width * getSize().height;
-      if (hFact > wFact) {
-        visibleRect.width = hFact / getSize().height;
-      } else {
-        visibleRect.height = wFact / getSize().width;
-      }
-      // The size of the visible rectangle is limited by the image size.
-      checkVisibleRectSize(image, visibleRect);
-      // Set the position of the visible rectangle, so that the mouse
-      // cursor doesn't move on the image.
-      Rectangle drawRect = calculateDrawImageRectangle(visibleRect);
-      visibleRect.x = this.mousePointInImg.x
-          + ((drawRect.x - e.getX()) * visibleRect.width) / drawRect.width;
-      visibleRect.y = this.mousePointInImg.y
-          + ((drawRect.y - e.getY()) * visibleRect.height) / drawRect.height;
-      // The position is also limited by the image size
-      checkVisibleRectPos(image, visibleRect);
-      synchronized (MapillaryImageDisplay.this) {
-        MapillaryImageDisplay.this.visibleRect = visibleRect;
-      }
-      MapillaryImageDisplay.this.repaint();
+      if (image != null && Math.min(getSize().getWidth(), getSize().getHeight()) > 0) {
+        // Calculate the mouse cursor position in image coordinates, so that
+        // we can center the zoom
+        // on that mouse position.
+        // To avoid issues when the user tries to zoom in on the image
+        // borders, this point is not calculated
+        // again if there was less than 1.5seconds since the last event.
+        if (e.getWhen() - this.lastTimeForMousePoint > 1500 || this.mousePointInImg == null) {
+          this.lastTimeForMousePoint = e.getWhen();
+          this.mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY());
+        }
+        // Set the zoom to the visible rectangle in image coordinates
+        if (e.getWheelRotation() > 0) {
+          visibleRect.width = visibleRect.width * 3 / 2;
+          visibleRect.height = visibleRect.height * 3 / 2;
+        } else {
+          visibleRect.width = visibleRect.width * 2 / 3;
+          visibleRect.height = visibleRect.height * 2 / 3;
+        }
+        // Check that the zoom doesn't exceed 2:1
+        if (visibleRect.width < getSize().width / 2) {
+          visibleRect.width = getSize().width / 2;
+        }
+        if (visibleRect.height < getSize().height / 2) {
+          visibleRect.height = getSize().height / 2;
+        }
+        // Set the same ratio for the visible rectangle and the display area
+        int hFact = visibleRect.height * getSize().width;
+        int wFact = visibleRect.width * getSize().height;
+        if (hFact > wFact) {
+          visibleRect.width = hFact / getSize().height;
+        } else {
+          visibleRect.height = wFact / getSize().width;
+        }
+        // The size of the visible rectangle is limited by the image size.
+        checkVisibleRectSize(image, visibleRect);
+        // Set the position of the visible rectangle, so that the mouse
+        // cursor doesn't move on the image.
+        Rectangle drawRect = calculateDrawImageRectangle(visibleRect);
+        visibleRect.x = this.mousePointInImg.x
+            + ((drawRect.x - e.getX()) * visibleRect.width) / drawRect.width;
+        visibleRect.y = this.mousePointInImg.y
+            + ((drawRect.y - e.getY()) * visibleRect.height) / drawRect.height;
+        // The position is also limited by the image size
+        checkVisibleRectPos(image, visibleRect);
+        synchronized (MapillaryImageDisplay.this) {
+          MapillaryImageDisplay.this.visibleRect = visibleRect;
+        }
+        MapillaryImageDisplay.this.repaint();
+      }
     }
 
@@ -139,37 +139,36 @@
         visibleRect = MapillaryImageDisplay.this.visibleRect;
       }
-      if (image == null) {
-        return;
-      }
-      if (e.getButton() == OPTION_BUTTON) {
-        if (!MapillaryImageDisplay.this.visibleRect.equals(new Rectangle(0, 0, image.getWidth(null), image.getHeight(null)))) {
-          // Zooms to 1:1
-          MapillaryImageDisplay.this.visibleRect = new Rectangle(0, 0,
-              image.getWidth(null), image.getHeight(null));
-        } else {
-          // Zooms to best fit.
-          MapillaryImageDisplay.this.visibleRect = new Rectangle(
-              0,
-              (image.getHeight(null) - (image.getWidth(null) * getHeight()) / getWidth()) / 2,
-              image.getWidth(null),
-              (image.getWidth(null) * getHeight()) / getWidth()
-          );
+      if (image != null && Math.min(getSize().getWidth(), getSize().getHeight()) > 0) {
+        if (e.getButton() == OPTION_BUTTON) {
+          if (!MapillaryImageDisplay.this.visibleRect.equals(new Rectangle(0, 0, image.getWidth(null), image.getHeight(null)))) {
+            // Zooms to 1:1
+            MapillaryImageDisplay.this.visibleRect = new Rectangle(0, 0,
+                image.getWidth(null), image.getHeight(null));
+          } else {
+            // Zooms to best fit.
+            MapillaryImageDisplay.this.visibleRect = new Rectangle(
+                0,
+                (image.getHeight(null) - (image.getWidth(null) * getHeight()) / getWidth()) / 2,
+                image.getWidth(null),
+                (image.getWidth(null) * getHeight()) / getWidth()
+            );
+          }
+          MapillaryImageDisplay.this.repaint();
+          return;
+        } else if (e.getButton() != DRAG_BUTTON) {
+          return;
+        }
+        // Calculate the translation to set the clicked point the center of
+        // the view.
+        Point click = comp2imgCoord(visibleRect, e.getX(), e.getY());
+        Point center = getCenterImgCoord(visibleRect);
+        visibleRect.x += click.x - center.x;
+        visibleRect.y += click.y - center.y;
+        checkVisibleRectPos(image, visibleRect);
+        synchronized (MapillaryImageDisplay.this) {
+          MapillaryImageDisplay.this.visibleRect = visibleRect;
         }
         MapillaryImageDisplay.this.repaint();
-        return;
-      } else if (e.getButton() != DRAG_BUTTON) {
-        return;
-      }
-      // Calculate the translation to set the clicked point the center of
-      // the view.
-      Point click = comp2imgCoord(visibleRect, e.getX(), e.getY());
-      Point center = getCenterImgCoord(visibleRect);
-      visibleRect.x += click.x - center.x;
-      visibleRect.y += click.y - center.y;
-      checkVisibleRectPos(image, visibleRect);
-      synchronized (MapillaryImageDisplay.this) {
-        MapillaryImageDisplay.this.visibleRect = visibleRect;
-      }
-      MapillaryImageDisplay.this.repaint();
+      }
     }
 
Index: /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/gui/ImageDisplayTest.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/gui/ImageDisplayTest.java	(revision 32592)
+++ /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/gui/ImageDisplayTest.java	(revision 32592)
@@ -0,0 +1,89 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.mapillary.gui;
+
+import java.awt.GraphicsEnvironment;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseWheelEvent;
+import java.awt.image.BufferedImage;
+
+import javax.swing.JFrame;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openstreetmap.josm.plugins.mapillary.utils.TestUtil;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests {@link MapillaryImageDisplay}
+ */
+public class ImageDisplayTest {
+
+  private static final BufferedImage DUMMY_IMAGE = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
+
+  @BeforeClass
+  public static void setUp() {
+    TestUtil.initPlugin();
+  }
+
+  @Test
+  public void testImagePersistence() {
+    MapillaryImageDisplay display = new MapillaryImageDisplay();
+    display.setImage(DUMMY_IMAGE);
+    assertEquals(DUMMY_IMAGE, display.getImage());
+  }
+
+  /**
+   * This test does not check if the scroll events result in the correct changes in the {@link MapillaryImageDisplay},
+   * it only checks if the tested method runs through.
+   */
+  @Test
+  public void testMouseWheelMoved() {
+    if (GraphicsEnvironment.isHeadless()) {
+      return;
+    }
+    MapillaryImageDisplay display = new MapillaryImageDisplay();
+    final MouseWheelEvent dummyScroll = new MouseWheelEvent(display, 42, System.currentTimeMillis(), 0, 0, 0, 0, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, 3);
+    display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll);
+
+    display.setImage(DUMMY_IMAGE);
+
+    display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll);
+
+    // This is necessary to make the size of the component > 0. If you know a more elegant solution, feel free to change it.
+    JFrame frame = new JFrame();
+    frame.setSize(42, 42);
+    frame.getContentPane().add(display);
+    frame.pack();
+
+    display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll);
+  }
+
+  /**
+   * This test does not check if the scroll events result in the correct changes in the {@link MapillaryImageDisplay},
+   * it only checks if the tested method runs through.
+   */
+  @Test
+  public void testMouseClicked() {
+    if (GraphicsEnvironment.isHeadless()) {
+      return;
+    }
+    for (int button = 1; button <= 3; button++) {
+      MapillaryImageDisplay display = new MapillaryImageDisplay();
+      final MouseEvent dummyClick = new MouseEvent(display, 42, System.currentTimeMillis(), 0, 0, 0, 1, false, button);
+      display.getMouseListeners()[0].mouseClicked(dummyClick);
+
+      display.setImage(DUMMY_IMAGE);
+
+      display.getMouseListeners()[0].mouseClicked(dummyClick);
+
+      // This is necessary to make the size of the component > 0. If you know a more elegant solution, feel free to change it.
+      JFrame frame = new JFrame();
+      frame.setSize(42, 42);
+      frame.getContentPane().add(display);
+      frame.pack();
+
+      display.getMouseListeners()[0].mouseClicked(dummyClick);
+    }
+  }
+}
