Index: trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java	(revision 9394)
+++ trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java	(revision 9395)
@@ -12,4 +12,5 @@
 import java.awt.Stroke;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -106,5 +107,13 @@
      */
     public enum ColorMode {
-        NONE, VELOCITY, HDOP, DIRECTION, TIME
+        NONE, VELOCITY, HDOP, DIRECTION, TIME;
+
+        static ColorMode fromIndex(final int index) {
+            return values()[index];
+        }
+
+        int toIndex() {
+            return Arrays.asList(values()).indexOf(this);
+        }
     }
 
@@ -141,5 +150,5 @@
         try {
             int i = Main.pref.getInteger("draw.rawgps.colors", specName(layerName), 0);
-            return ColorMode.values()[i];
+            return ColorMode.fromIndex(i);
         } catch (Exception e) {
             Main.warn(e);
Index: trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelperTest.java
===================================================================
--- trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelperTest.java	(revision 9394)
+++ trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelperTest.java	(revision 9395)
@@ -2,8 +2,11 @@
 package org.openstreetmap.josm.gui.layer.gpx;
 
-import java.io.FileInputStream;
+import static org.junit.Assert.assertEquals;
+
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 import org.junit.BeforeClass;
@@ -12,5 +15,8 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.TestUtils;
-import org.openstreetmap.josm.io.GpxReader;
+import org.openstreetmap.josm.data.gpx.GpxData;
+import org.openstreetmap.josm.data.gpx.WayPoint;
+import org.openstreetmap.josm.io.GpxReaderTest;
+import org.openstreetmap.josm.tools.ColorHelper;
 import org.xml.sax.SAXException;
 
@@ -36,13 +42,96 @@
     @Test
     public void testTicket12312() throws FileNotFoundException, IOException, SAXException {
-        try (InputStream in = new FileInputStream((TestUtils.getRegressionDataFile(12312, "single_trackpoint.gpx")))) {
-            GpxReader reader = new GpxReader(in);
-            reader.parse(false);
-            GpxDrawHelper gdh = new GpxDrawHelper(reader.getGpxData());
-            Main.pref.put("draw.rawgps.colors.dynamic.layer 12312", true);
-            Main.pref.putInteger("draw.rawgps.colors.layer 12312", 1); // ColorMode.VELOCITY
-            gdh.readPreferences("12312");
-            gdh.calculateColors();
+        Main.pref.put("draw.rawgps.colors.dynamic.layer 12312", true);
+        Main.pref.putInteger("draw.rawgps.colors.layer 12312", GpxDrawHelper.ColorMode.VELOCITY.toIndex());
+        final List<String> colors = calculateColors(TestUtils.getRegressionDataFile(12312, "single_trackpoint.gpx"), "12312", 1);
+        assertEquals("[#FF00FF]", colors.toString());
+    }
+
+    /**
+     * Tests coloring of an example track using the default color.
+     * @throws IOException if any I/O error occurs
+     * @throws FileNotFoundException if the data file is not found
+     * @throws SAXException if any SAX error occurs
+     */
+    @Test
+    public void testNone() throws IOException, SAXException {
+        final List<String> colors = calculateColors("data_nodist/2094047.gpx", "000", 10);
+        assertEquals("[#FF00FF, #FF00FF, #FF00FF, #FF00FF, #FF00FF, #FF00FF, #FF00FF, #FF00FF, #FF00FF, #FF00FF]", colors.toString());
+    }
+
+    /**
+     * Tests coloring of an example track using its velocity.
+     * @throws IOException if any I/O error occurs
+     * @throws FileNotFoundException if the data file is not found
+     * @throws SAXException if any SAX error occurs
+     */
+    @Test
+    public void testVelocity() throws IOException, SAXException {
+        Main.pref.putInteger("draw.rawgps.colors.layer 001", GpxDrawHelper.ColorMode.VELOCITY.toIndex());
+        final List<String> colors = calculateColors("data_nodist/2094047.gpx", "001", 10);
+        assertEquals("[#FF00FF, #FFAD00, #FFA800, #FFA800, #FF9E00, #FF9400, #FF7000, #FF7000, #FF8000, #FF9400]", colors.toString());
+    }
+
+    /**
+     * Tests coloring of an example track using its velocity with a dynamic scale
+     * @throws IOException if any I/O error occurs
+     * @throws FileNotFoundException if the data file is not found
+     * @throws SAXException if any SAX error occurs
+     */
+    @Test
+    public void testVelocityDynamic() throws IOException, SAXException {
+        Main.pref.putInteger("draw.rawgps.colors.layer 002", GpxDrawHelper.ColorMode.VELOCITY.toIndex());
+        Main.pref.put("draw.rawgps.colors.dynamic.layer 002", true);
+        final List<String> colors = calculateColors("data_nodist/2094047.gpx", "002", 10);
+        assertEquals("[#FF00FF, #00FFE0, #00FFC2, #00FFC2, #00FF75, #00FF3D, #99FF00, #94FF00, #38FF00, #00FF38]", colors.toString());
+    }
+
+    /**
+     * Tests coloring of an example track using its direction.
+     * @throws IOException if any I/O error occurs
+     * @throws FileNotFoundException if the data file is not found
+     * @throws SAXException if any SAX error occurs
+     */
+    @Test
+    public void testDirection() throws IOException, SAXException {
+        Main.pref.putInteger("draw.rawgps.colors.layer 003", GpxDrawHelper.ColorMode.DIRECTION.toIndex());
+        final List<String> colors = calculateColors("data_nodist/2094047.gpx", "003", 10);
+        assertEquals("[#FF00FF, #E8EC25, #EDEA26, #EDE625, #ECD622, #ECBC1E, #E8600E, #E73C09, #E8540C, #EA9116]", colors.toString());
+    }
+
+    /**
+     * Tests coloring of an example track using its direction.
+     * @throws IOException if any I/O error occurs
+     * @throws FileNotFoundException if the data file is not found
+     * @throws SAXException if any SAX error occurs
+     */
+    @Test
+    public void testTime() throws IOException, SAXException {
+        Main.pref.putInteger("draw.rawgps.colors.layer 003", GpxDrawHelper.ColorMode.TIME.toIndex());
+        final List<String> colors = calculateColors("data_nodist/2094047.gpx", "003", 10);
+        assertEquals("[#FF00FF, #FF0000, #FF0000, #FF0500, #FF0500, #FF0A00, #FF0A00, #FF1F00, #FF2E00, #FF3300]", colors.toString());
+    }
+
+    /**
+     *
+     * @param fileName the GPX filename to parse
+     * @param layerName the layer name used to fetch the color settings, see {@link GpxDrawHelper#readPreferences(java.lang.String)}
+     * @param n the number of waypoints of the first track/segment to analyze
+     * @return the HTML color codes for the first {@code n} points
+     * @throws IOException if any I/O error occurs
+     * @throws FileNotFoundException if the data file is not found
+     * @throws SAXException if any SAX error occurs
+     */
+    static List<String> calculateColors(String fileName, String layerName, int n) throws IOException, SAXException {
+        final GpxData data = GpxReaderTest.parseGpxData(fileName);
+        final GpxDrawHelper gdh = new GpxDrawHelper(data);
+        gdh.readPreferences(layerName);
+        gdh.calculateColors();
+        final Iterator<WayPoint> wayPointIterator = data.tracks.iterator().next().getSegments().iterator().next().getWayPoints().iterator();
+        final List<String> colorCodes = new ArrayList<>(n);
+        while (colorCodes.size() < n) {
+            colorCodes.add(ColorHelper.color2html(wayPointIterator.next().customColoring));
         }
+        return colorCodes;
     }
 }
