Index: trunk/src/org/openstreetmap/josm/actions/AbstractMergeAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/AbstractMergeAction.java	(revision 10063)
+++ trunk/src/org/openstreetmap/josm/actions/AbstractMergeAction.java	(revision 10074)
@@ -5,4 +5,5 @@
 
 import java.awt.Component;
+import java.awt.GraphicsEnvironment;
 import java.awt.GridBagLayout;
 import java.util.List;
@@ -57,23 +58,42 @@
     }
 
-    protected Layer askTargetLayer(List<Layer> targetLayers) {
-        JosmComboBox<Layer> layerList = new JosmComboBox<>(targetLayers.toArray(new Layer[0]));
+    protected static Layer askTargetLayer(List<Layer> targetLayers) {
+        return askTargetLayer(targetLayers.toArray(new Layer[0]),
+                tr("Please select the target layer."),
+                tr("Select target layer"),
+                tr("Merge"), "dialogs/mergedown");
+    }
+
+    /**
+     * Asks a target layer.
+     * @param <T> type of layer
+     * @param targetLayers array of proposed target layers
+     * @param label label displayed in dialog
+     * @param title title of dialog
+     * @param buttonText text of button used to select target layer
+     * @param buttonIcon icon name of button used to select target layer
+     * @return choosen target layer
+     */
+    @SuppressWarnings("unchecked")
+    public static <T extends Layer> T askTargetLayer(T[] targetLayers, String label, String title, String buttonText, String buttonIcon) {
+        JosmComboBox<T> layerList = new JosmComboBox<>(targetLayers);
         layerList.setRenderer(new LayerListCellRenderer());
         layerList.setSelectedIndex(0);
 
         JPanel pnl = new JPanel(new GridBagLayout());
-        pnl.add(new JLabel(tr("Please select the target layer.")), GBC.eol());
+        pnl.add(new JLabel(label), GBC.eol());
         pnl.add(layerList, GBC.eol());
-
-        ExtendedDialog ed = new ExtendedDialog(Main.parent,
-                tr("Select target layer"),
-                new String[] {tr("Merge"), tr("Cancel")});
-        ed.setButtonIcons(new String[] {"dialogs/mergedown", "cancel"});
+        if (GraphicsEnvironment.isHeadless()) {
+            // return first layer in headless mode, for unit tests
+            return targetLayers[0];
+        }
+        ExtendedDialog ed = new ExtendedDialog(Main.parent, title, new String[] {buttonText, tr("Cancel")});
+        ed.setButtonIcons(new String[] {buttonIcon, "cancel"});
         ed.setContent(pnl);
         ed.showDialog();
-        if (ed.getValue() != 1)
+        if (ed.getValue() != 1) {
             return null;
-
-        return (Layer) layerList.getSelectedItem();
+        }
+        return (T) layerList.getSelectedItem();
     }
 
Index: trunk/src/org/openstreetmap/josm/actions/DownloadAlongAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/DownloadAlongAction.java	(revision 10063)
+++ trunk/src/org/openstreetmap/josm/actions/DownloadAlongAction.java	(revision 10074)
@@ -117,16 +117,5 @@
         final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download data"));
         final Future<?> future = new DownloadTaskList().download(false, toDownload, osmDownload, gpxDownload, monitor);
-        Main.worker.submit(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    future.get();
-                } catch (Exception e) {
-                    Main.error(e);
-                    return;
-                }
-                monitor.close();
-            }
-        });
+        waitFuture(future, monitor);
     }
 }
Index: trunk/src/org/openstreetmap/josm/actions/JosmAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/JosmAction.java	(revision 10063)
+++ trunk/src/org/openstreetmap/josm/actions/JosmAction.java	(revision 10074)
@@ -6,4 +6,5 @@
 import java.awt.event.KeyEvent;
 import java.util.Collection;
+import java.util.concurrent.Future;
 
 import javax.swing.AbstractAction;
@@ -17,4 +18,5 @@
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
 import org.openstreetmap.josm.gui.util.GuiHelper;
 import org.openstreetmap.josm.tools.Destroyable;
@@ -230,4 +232,21 @@
     }
 
+    protected static void waitFuture(final Future<?> future, final PleaseWaitProgressMonitor monitor) {
+        Main.worker.submit(
+                new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            future.get();
+                        } catch (Exception e) {
+                            Main.error(e);
+                            return;
+                        }
+                        monitor.close();
+                    }
+                }
+        );
+    }
+
     /**
      * Override in subclasses to init the enabled state of an action when it is
Index: trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java	(revision 10063)
+++ trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java	(revision 10074)
@@ -367,10 +367,9 @@
      * @return List of ways to split
      */
-    private static List<Way> getApplicableWays(List<Way> selectedWays, List<Node> selectedNodes) {
+    static List<Way> getApplicableWays(List<Way> selectedWays, List<Node> selectedNodes) {
         if (selectedNodes.isEmpty())
             return null;
 
-        // Special case - one of the selected ways touches (not cross) way that we
-        // want to split
+        // Special case - one of the selected ways touches (not cross) way that we want to split
         if (selectedNodes.size() == 1) {
             Node n = selectedNodes.get(0);
@@ -395,34 +394,5 @@
 
         // List of ways shared by all nodes
-        List<Way> result =
-            new ArrayList<>(OsmPrimitive.getFilteredList(selectedNodes.get(0).getReferrers(),
-                                                         Way.class));
-        for (int i = 1; i < selectedNodes.size(); i++) {
-            List<OsmPrimitive> ref = selectedNodes.get(i).getReferrers();
-            for (Iterator<Way> it = result.iterator(); it.hasNext();) {
-                if (!ref.contains(it.next())) {
-                    it.remove();
-                }
-            }
-        }
-
-        // Remove broken ways
-        for (Iterator<Way> it = result.iterator(); it.hasNext();) {
-            if (it.next().getNodesCount() <= 2) {
-                it.remove();
-            }
-        }
-
-        if (selectedWays.isEmpty())
-            return result;
-        else {
-            // Return only selected ways
-            for (Iterator<Way> it = result.iterator(); it.hasNext();) {
-                if (!selectedWays.contains(it.next())) {
-                    it.remove();
-                }
-            }
-            return result;
-        }
+        return UnJoinNodeWayAction.getApplicableWays(selectedWays, selectedNodes);
     }
 
Index: trunk/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java	(revision 10063)
+++ trunk/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java	(revision 10074)
@@ -149,5 +149,5 @@
      * @return List of relevant ways
      */
-    private static List<Way> getApplicableWays(List<Way> selectedWays, List<Node> selectedNodes) {
+    static List<Way> getApplicableWays(List<Way> selectedWays, List<Node> selectedNodes) {
         if (selectedNodes.isEmpty())
             return null;
Index: trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java	(revision 10063)
+++ trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java	(revision 10074)
@@ -89,18 +89,5 @@
             final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download data"));
             final Future<?> future = new DownloadTaskList().download(false /* no new layer */, areasToDownload, true, false, monitor);
-            Main.worker.submit(
-                    new Runnable() {
-                        @Override
-                        public void run() {
-                            try {
-                                future.get();
-                            } catch (Exception e) {
-                                Main.error(e);
-                                return;
-                            }
-                            monitor.close();
-                        }
-                    }
-            );
+            waitFuture(future, monitor);
         }
     }
