Index: trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackActionTest.java
===================================================================
--- trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackActionTest.java	(revision 9719)
+++ trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackActionTest.java	(revision 9719)
@@ -0,0 +1,65 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.gui.layer.gpx;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openstreetmap.josm.JOSMFixture;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.TestUtils;
+import org.openstreetmap.josm.data.gpx.GpxData;
+import org.openstreetmap.josm.data.imagery.ImageryInfo;
+import org.openstreetmap.josm.gui.layer.TMSLayer;
+import org.openstreetmap.josm.gui.layer.gpx.DownloadWmsAlongTrackAction.PrecacheWmsTask;
+import org.openstreetmap.josm.io.GpxReaderTest;
+
+/**
+ * Unit tests of {@link DownloadWmsAlongTrackAction} class.
+ */
+public class DownloadWmsAlongTrackActionTest {
+
+    /**
+     * Setup test.
+     */
+    @BeforeClass
+    public static void setUpBeforeClass() {
+        JOSMFixture.createUnitTestFixture().init(true);
+    }
+
+    /**
+     * Test action without layer.
+     */
+    @Test
+    public void testNoLayer() {
+        assertNull(new DownloadWmsAlongTrackAction(new GpxData()).createTask());
+    }
+
+    /**
+     * Test action with a TMS layer.
+     * @throws Exception if an error occurs
+     */
+    @Test
+    public void testTmsLayer() throws Exception {
+        // Create new TMS layer and clear cache
+        TMSLayer layer = new TMSLayer(new ImageryInfo("OSM TMS", "https://a.tile.openstreetmap.org/{zoom}/{x}/{y}.png", "tms", null, null));
+        try {
+            Main.main.addLayer(layer);
+            TMSLayer.getCache().clear();
+            assertTrue(TMSLayer.getCache().getMatching(".*").isEmpty());
+            // Perform action
+            final GpxData gpx = GpxReaderTest.parseGpxData(TestUtils.getTestDataRoot() + "minimal.gpx");
+            PrecacheWmsTask task = new DownloadWmsAlongTrackAction(gpx).createTask();
+            assertNotNull(task);
+            task.run();
+            // Ensure cache is not empty
+            assertFalse(TMSLayer.getCache().getMatching(".*").isEmpty());
+        } finally {
+            // Ensure we clean the place before leaving, even if test fails.
+            Main.main.removeLayer(layer);
+        }
+    }
+}
