Index: trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java	(revision 9473)
+++ trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java	(revision 9474)
@@ -354,6 +354,5 @@
 
     /**
-     * Explains a {@link OsmApiException} with a generic error
-     * message.
+     * Explains a {@link OsmApiException} with a generic error message.
      *
      * @param e the exception
@@ -392,5 +391,4 @@
      * @param e the exception
      */
-
     public static void explainNestedUnkonwnHostException(OsmTransferException e) {
         HelpAwareOptionPane.showOptionDialog(
Index: trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java	(revision 9473)
+++ trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java	(revision 9474)
@@ -36,4 +36,8 @@
 import org.openstreetmap.josm.tools.date.DateUtils;
 
+/**
+ * Utilities for exception handling.
+ * @since 2097
+ */
 public final class ExceptionUtil {
 
@@ -43,5 +47,5 @@
 
     /**
-     * handles an exception caught during OSM API initialization
+     * Explains an exception caught during OSM API initialization.
      *
      * @param e the exception
@@ -53,7 +57,14 @@
                 "<html>Failed to initialize communication with the OSM server {0}.<br>"
                 + "Check the server URL in your preferences and your internet connection.",
-                OsmApi.getOsmApi().getServerUrl());
-    }
-
+                OsmApi.getOsmApi().getServerUrl())+"</html>";
+    }
+
+    /**
+     * Explains a {@link OsmApiException} which was thrown because accessing a protected
+     * resource was forbidden.
+     *
+     * @param e the exception
+     * @return The HTML formatted error message to display
+     */
     public static String explainMissingOAuthAccessTokenException(MissingOAuthAccessTokenException e) {
         Main.error(e);
@@ -69,8 +80,10 @@
 
     public static Pair<OsmPrimitive, Collection<OsmPrimitive>> parsePreconditionFailed(String msg) {
+        if (msg == null)
+            return null;
         final String ids = "(\\d+(?:,\\d+)*)";
         final Collection<OsmPrimitive> refs = new TreeSet<>(); // error message can contain several times the same way
         Matcher m;
-        m = Pattern.compile(".*Node (\\d+) is still used by relations " + ids + ".*").matcher(msg);
+        m = Pattern.compile(".*Node (\\d+) is still used by relations? " + ids + ".*").matcher(msg);
         if (m.matches()) {
             OsmPrimitive n = new Node(Long.parseLong(m.group(1)));
@@ -80,5 +93,5 @@
             return Pair.create(n, refs);
         }
-        m = Pattern.compile(".*Node (\\d+) is still used by ways " + ids + ".*").matcher(msg);
+        m = Pattern.compile(".*Node (\\d+) is still used by ways? " + ids + ".*").matcher(msg);
         if (m.matches()) {
             OsmPrimitive n = new Node(Long.parseLong(m.group(1)));
@@ -96,5 +109,5 @@
             return Pair.create(n, refs);
         }
-        m = Pattern.compile(".*Way (\\d+) is still used by relations " + ids + ".*").matcher(msg);
+        m = Pattern.compile(".*Way (\\d+) is still used by relations? " + ids + ".*").matcher(msg);
         if (m.matches()) {
             OsmPrimitive n = new Way(Long.parseLong(m.group(1)));
@@ -240,4 +253,11 @@
     }
 
+    /**
+     * Explains a {@link OsmApiException} which was thrown because the authentication at
+     * the OSM server failed, with basic authentication.
+     *
+     * @param e the exception
+     * @return The HTML formatted error message to display
+     */
     public static String explainFailedBasicAuthentication(OsmApiException e) {
         Main.error(e);
@@ -250,4 +270,11 @@
     }
 
+    /**
+     * Explains a {@link OsmApiException} which was thrown because the authentication at
+     * the OSM server failed, with OAuth authentication.
+     *
+     * @param e the exception
+     * @return The HTML formatted error message to display
+     */
     public static String explainFailedOAuthAuthentication(OsmApiException e) {
         Main.error(e);
@@ -260,9 +287,16 @@
     }
 
+    /**
+     * Explains a {@link OsmApiException} which was thrown because accessing a protected
+     * resource was forbidden (HTTP 403), without OAuth authentication.
+     *
+     * @param e the exception
+     * @return The HTML formatted error message to display
+     */
     public static String explainFailedAuthorisation(OsmApiException e) {
         Main.error(e);
         String header = e.getErrorHeader();
         String body = e.getErrorBody();
-        String msg = null;
+        String msg;
         if (header != null) {
             if (body != null && !header.equals(body)) {
@@ -291,4 +325,11 @@
     }
 
+    /**
+     * Explains a {@link OsmApiException} which was thrown because accessing a protected
+     * resource was forbidden (HTTP 403), with OAuth authentication.
+     *
+     * @param e the exception
+     * @return The HTML formatted error message to display
+     */
     public static String explainFailedOAuthAuthorisation(OsmApiException e) {
         Main.error(e);
@@ -356,7 +397,5 @@
         String msg = e.getErrorHeader();
         if (msg != null) {
-            String pattern = "The changeset (\\d+) was closed at (.*)";
-            Pattern p = Pattern.compile(pattern);
-            Matcher m = p.matcher(msg);
+            Matcher m = Pattern.compile("The changeset (\\d+) was closed at (.*)").matcher(msg);
             if (m.matches()) {
                 long changesetId = Long.parseLong(m.group(1));
@@ -392,5 +431,5 @@
                     "<html>The server reported that it has detected a conflict.");
         }
-        return msg;
+        return msg.endsWith("</html>") ? msg : (msg + "</html>");
     }
 
@@ -449,5 +488,5 @@
         return tr("<html>Failed to open a connection to the remote server<br>" + "''{0}''<br>"
                 + "for security reasons. This is most likely because you are running<br>"
-                + "in an applet and because you did not load your applet from ''{1}''.", apiUrl, host);
+                + "in an applet and because you did not load your applet from ''{1}''.", apiUrl, host)+"</html>";
     }
 
@@ -463,5 +502,5 @@
         Main.error(e);
         return tr("<html>Failed to open a connection to the remote server<br>" + "''{0}''.<br>"
-                + "Please check your internet connection.", e.getUrl());
+                + "Please check your internet connection.", e.getUrl())+"</html>";
     }
 
@@ -479,6 +518,6 @@
         return tr("<html>Failed to upload data to or download data from<br>" + "''{0}''<br>"
                 + "due to a problem with transferring data.<br>"
-                + "Details (untranslated): {1}</html>", e.getUrl(), ioe
-                .getMessage());
+                + "Details (untranslated): {1}</html>", e.getUrl(),
+                ioe != null ? ioe.getMessage() : "null");
     }
 
@@ -495,5 +534,5 @@
         return tr("<html>Failed to download data. "
                 + "Its format is either unsupported, ill-formed, and/or inconsistent.<br>"
-                + "<br>Details (untranslated): {0}</html>", ide.getMessage());
+                + "<br>Details (untranslated): {0}</html>", ide != null ? ide.getMessage() : "null");
     }
 
@@ -510,10 +549,10 @@
         Main.error(e);
         return tr("<html>Failed to download data.<br>"
-                + "<br>Details: {0}</html>", oae.getMessage());
+                + "<br>Details: {0}</html>", oae != null ? oae.getMessage() : "null");
     }
 
     /**
      * Explains a {@link OsmApiException} which was thrown because of an internal server
-     * error in the OSM API server..
+     * error in the OSM API server.
      *
      * @param e the exception
@@ -523,5 +562,5 @@
         Main.error(e);
         return tr("<html>The OSM server<br>" + "''{0}''<br>" + "reported an internal server error.<br>"
-                + "This is most likely a temporary problem. Please try again later.", e.getUrl());
+                + "This is most likely a temporary problem. Please try again later.", e.getUrl())+"</html>";
     }
 
@@ -613,5 +652,5 @@
         return tr("<html>Failed to open a connection to the remote server<br>" + "''{0}''.<br>"
                 + "Host name ''{1}'' could not be resolved. <br>"
-                + "Please check the API URL in your preferences and your internet connection.", apiUrl, host);
+                + "Please check the API URL in your preferences and your internet connection.", apiUrl, host)+"</html>";
     }
 
@@ -708,4 +747,3 @@
         }
     }
-
 }
Index: trunk/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java
===================================================================
--- trunk/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java	(revision 9474)
+++ trunk/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java	(revision 9474)
@@ -0,0 +1,413 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.tools;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openstreetmap.josm.JOSMFixture;
+import org.openstreetmap.josm.io.ChangesetClosedException;
+import org.openstreetmap.josm.io.IllegalDataException;
+import org.openstreetmap.josm.io.MissingOAuthAccessTokenException;
+import org.openstreetmap.josm.io.OfflineAccessException;
+import org.openstreetmap.josm.io.OsmApiException;
+import org.openstreetmap.josm.io.OsmApiInitializationException;
+import org.openstreetmap.josm.io.auth.CredentialsManager;
+import org.openstreetmap.josm.tools.date.DateUtils;
+
+/**
+ * Unit tests of {@link ExceptionUtil} class.
+ */
+public class ExceptionUtilTest {
+
+    private static String url;
+    private static String host;
+    private static String user;
+
+    /**
+     * Setup test.
+     */
+    @BeforeClass
+    public static void setUp() {
+        JOSMFixture.createUnitTestFixture().init();
+        url = new OsmApiException("").getUrl();
+        host = url.replace("http://", "").replace("/api/", "");
+        user = CredentialsManager.getInstance().getUsername();
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainBadRequest} method.
+     */
+    @Test
+    public void testExplainBadRequest() {
+        assertEquals("<html>The OSM server '"+url+"' reported a bad request.<br></html>",
+                ExceptionUtil.explainBadRequest(new OsmApiException("")));
+
+        assertEquals("<html>The OSM server '"+url+"' reported a bad request.<br><br>"+
+                "Error message(untranslated): header</html>",
+                ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "")));
+
+        assertEquals("<html>The OSM server '"+url+"' reported a bad request.<br><br>"+
+                "Error message(untranslated): header</html>",
+                ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", "invalid_url")));
+
+        assertEquals("<html>The OSM server '"+host+"' reported a bad request.<br><br>"+
+                "Error message(untranslated): header</html>",
+                ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", url)));
+
+        assertEquals("<html>The OSM server '"+url+"' reported a bad request.<br><br>"+
+                "The area you tried to download is too big or your request was too large.<br>"+
+                "Either request a smaller area or use an export file provided by the OSM community.</html>",
+                ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "The maximum bbox", "")));
+
+        assertEquals("<html>The OSM server '"+url+"' reported a bad request.<br><br>"+
+                "The area you tried to download is too big or your request was too large.<br>"+
+                "Either request a smaller area or use an export file provided by the OSM community.</html>",
+                ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "You requested too many nodes", "")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainBandwidthLimitExceeded} method.
+     */
+    @Test
+    public void testExplainBandwidthLimitExceeded() {
+        assertEquals("<html>Communication with the OSM server '"+url+"'failed. "+
+                "The server replied<br>the following error code and the following error message:<br>"+
+                "<strong>Error code:<strong> 0<br><strong>Error message (untranslated)</strong>: no error message available</html>",
+                ExceptionUtil.explainBandwidthLimitExceeded(new OsmApiException("")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainChangesetClosedException} method.
+     */
+    @Test
+    public void testExplainChangesetClosedException() {
+        assertEquals("<html>Failed to upload to changeset <strong>0</strong><br>because it has already been closed on ?.",
+                ExceptionUtil.explainChangesetClosedException(new ChangesetClosedException("")));
+
+        assertEquals("<html>Failed to upload to changeset <strong>1</strong><br>because it has already been closed on Jan 1, 2016 12:00:00 AM.",
+                ExceptionUtil.explainChangesetClosedException(new ChangesetClosedException(1, DateUtils.fromString("2016-01-01"), null)));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainClientTimeout} method.
+     */
+    @Test
+    public void testExplainClientTimeout() {
+        assertEquals("<html>Communication with the OSM server '"+url+"' timed out. Please retry later.</html>",
+                ExceptionUtil.explainClientTimeout(new OsmApiException("")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainConflict} method.
+     */
+    @Test
+    public void testExplainConflict() {
+        int code = HttpURLConnection.HTTP_CONFLICT;
+        assertEquals("<html>The server reported that it has detected a conflict.</html>",
+                ExceptionUtil.explainConflict(new OsmApiException("")));
+        assertEquals("<html>The server reported that it has detected a conflict.<br>Error message (untranslated):<br>header</html>",
+                ExceptionUtil.explainConflict(new OsmApiException(code, "header", "")));
+        assertEquals("<html>Closing of changeset <strong>1</strong> failed <br>because it has already been closed.",
+                ExceptionUtil.explainConflict(new OsmApiException(code, "The changeset 1 was closed at xxx", "")));
+        assertEquals("<html>Closing of changeset <strong>1</strong> failed<br> because it has already been closed on Jan 1, 2016 1:34:56 PM.",
+                ExceptionUtil.explainConflict(new OsmApiException(code, "The changeset 1 was closed at 2016-01-01 12:34:56 UTC", "")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainException} method.
+     */
+    @Test
+    public void testExplainException() {
+        assertEquals("ResponseCode=0",
+                ExceptionUtil.explainException(new OsmApiException("")));
+        assertEquals("java.lang.Exception: ",
+                ExceptionUtil.explainException(new Exception("")));
+        assertEquals("java.lang.Exception",
+                ExceptionUtil.explainException(new Exception(null, null)));
+        assertEquals("test",
+                ExceptionUtil.explainException(new Exception("test")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainFailedAuthorisation} method.
+     */
+    @Test
+    public void testExplainFailedAuthorisation() {
+        assertEquals("<html>Authorisation at the OSM server failed.<br></html>",
+                ExceptionUtil.explainFailedAuthorisation(new OsmApiException("")));
+        assertEquals("<html>Authorisation at the OSM server failed.<br>The server reported the following error:<br>'header'</html>",
+                ExceptionUtil.explainFailedAuthorisation(new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN, "header", null)));
+        assertEquals("<html>Authorisation at the OSM server failed.<br>The server reported the following error:<br>'header (body)'</html>",
+                ExceptionUtil.explainFailedAuthorisation(new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN, "header", "body")));
+        assertEquals("<html>Authorisation at the OSM server failed.<br>The server reported the following error:<br>'body'</html>",
+                ExceptionUtil.explainFailedAuthorisation(new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN, null, "body")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainFailedOAuthAuthorisation} method.
+     */
+    @Test
+    public void testExplainFailedOAuthAuthorisation() {
+        assertEquals("<html>Authorisation at the OSM server with the OAuth token 'null' failed.<br>"+
+                "The token is not authorised to access the protected resource<br>'unknown'.<br>"+
+                "Please launch the preferences dialog and retrieve another OAuth token.</html>",
+                ExceptionUtil.explainFailedOAuthAuthorisation(new OsmApiException("")));
+        assertEquals("<html>Authorisation at the OSM server with the OAuth token 'null' failed.<br>"+
+                "The token is not authorised to access the protected resource<br>'"+url+"'.<br>"+
+                "Please launch the preferences dialog and retrieve another OAuth token.</html>",
+                ExceptionUtil.explainFailedOAuthAuthorisation(new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN, "", "", url)));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainFailedBasicAuthentication} method.
+     */
+    @Test
+    public void testExplainFailedBasicAuthentication() {
+        assertEquals("<html>Authentication at the OSM server with the username '"+user+"' failed.<br>"+
+                "Please check the username and the password in the JOSM preferences.</html>",
+                ExceptionUtil.explainFailedBasicAuthentication(new OsmApiException("")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainFailedOAuthAuthentication} method.
+     */
+    @Test
+    public void testExplainFailedOAuthAuthentication() {
+        assertEquals("<html>Authentication at the OSM server with the OAuth token 'null' failed.<br>"+
+                "Please launch the preferences dialog and retrieve another OAuth token.</html>",
+                ExceptionUtil.explainFailedOAuthAuthentication(new OsmApiException("")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainGenericOsmApiException} method.
+     */
+    @Test
+    public void testExplainGenericOsmApiException() {
+        assertEquals("<html>Communication with the OSM server '"+url+"'failed. The server replied<br>"+
+                "the following error code and the following error message:<br><strong>Error code:<strong> 0<br>"+
+                "<strong>Error message (untranslated)</strong>: no error message available</html>",
+                ExceptionUtil.explainGenericOsmApiException(new OsmApiException("")));
+
+        assertEquals("<html>Communication with the OSM server '"+url+"'failed. The server replied<br>"+
+                "the following error code and the following error message:<br><strong>Error code:<strong> 500<br>"+
+                "<strong>Error message (untranslated)</strong>: header</html>",
+                ExceptionUtil.explainGenericOsmApiException(new OsmApiException(HttpURLConnection.HTTP_INTERNAL_ERROR, "header", null)));
+
+        assertEquals("<html>Communication with the OSM server '"+url+"'failed. The server replied<br>"+
+                "the following error code and the following error message:<br><strong>Error code:<strong> 500<br>"+
+                "<strong>Error message (untranslated)</strong>: body</html>",
+                ExceptionUtil.explainGenericOsmApiException(new OsmApiException(HttpURLConnection.HTTP_INTERNAL_ERROR, null, "body")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainGoneForUnknownPrimitive} method.
+     */
+    @Test
+    public void testExplainGoneForUnknownPrimitive() {
+        assertEquals("<html>The server reports that an object is deleted.<br>"+
+                "<strong>Uploading failed</strong> if you tried to update or delete this object.<br> "+
+                "<strong>Downloading failed</strong> if you tried to download this object.<br><br>"+
+                "The error message is:<br>ResponseCode=0</html>",
+                ExceptionUtil.explainGoneForUnknownPrimitive(new OsmApiException("")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainInternalServerError} method.
+     */
+    @Test
+    public void testExplainInternalServerError() {
+        assertEquals("<html>The OSM server<br>'"+url+"'<br>reported an internal server error.<br>"+
+                "This is most likely a temporary problem. Please try again later.</html>",
+                ExceptionUtil.explainInternalServerError(new OsmApiException("")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainMissingOAuthAccessTokenException} method.
+     */
+    @Test
+    public void testExplainMissingOAuthAccessTokenException() {
+        assertEquals("<html>Failed to authenticate at the OSM server 'http://api06.dev.openstreetmap.org/api'.<br>"+
+                "You are using OAuth to authenticate but currently there is no<br>OAuth Access Token configured.<br>"+
+                "Please open the Preferences Dialog and generate or enter an Access Token.</html>",
+                ExceptionUtil.explainMissingOAuthAccessTokenException(new MissingOAuthAccessTokenException()));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainNestedIllegalDataException} method.
+     */
+    @Test
+    public void testExplainNestedIllegalDataException() {
+        assertEquals("<html>Failed to download data. Its format is either unsupported, ill-formed, and/or inconsistent.<br><br>"+
+                "Details (untranslated): null</html>",
+                ExceptionUtil.explainNestedIllegalDataException(new OsmApiException("")));
+
+        assertEquals("<html>Failed to download data. Its format is either unsupported, ill-formed, and/or inconsistent.<br><br>"+
+                "Details (untranslated): test</html>",
+                ExceptionUtil.explainNestedIllegalDataException(new OsmApiException(new IllegalDataException("test"))));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainNestedIOException} method.
+     */
+    @Test
+    public void testExplainNestedIOException() {
+        assertEquals("<html>Failed to upload data to or download data from<br>'"+url+"'<br>"+
+                "due to a problem with transferring data.<br>Details (untranslated): null</html>",
+                ExceptionUtil.explainNestedIOException(new OsmApiException("")));
+
+        assertEquals("<html>Failed to upload data to or download data from<br>'"+url+"'<br>"+
+                "due to a problem with transferring data.<br>Details (untranslated): test</html>",
+                ExceptionUtil.explainNestedIOException(new OsmApiException(new IOException("test"))));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainNestedSocketException} method.
+     */
+    @Test
+    public void testExplainNestedSocketException() {
+        assertEquals("<html>Failed to open a connection to the remote server<br>'"+url+"'.<br>"+
+                "Please check your internet connection.</html>",
+                ExceptionUtil.explainNestedSocketException(new OsmApiException("")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainNestedUnknownHostException} method.
+     */
+    @Test
+    public void testExplainNestedUnknownHostException() {
+        assertEquals("<html>Failed to open a connection to the remote server<br>'"+url+"'.<br>"+
+                "Host name '"+host+"' could not be resolved. <br>"+
+                "Please check the API URL in your preferences and your internet connection.</html>",
+                ExceptionUtil.explainNestedUnknownHostException(new OsmApiException("")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainNotFound} method.
+     */
+    @Test
+    public void testExplainNotFound() {
+        assertEquals("<html>The OSM server '"+url+"' does not know about an object<br>"+
+                "you tried to read, update, or delete. Either the respective object<br>"+
+                "does not exist on the server or you are using an invalid URL to access<br>"+
+                "it. Please carefully check the server's address '"+url+"' for typos.</html>",
+                ExceptionUtil.explainNotFound(new OsmApiException("")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainOfflineAccessException} method.
+     */
+    @Test
+    public void testExplainOfflineAccessException() {
+        assertEquals("<html>Failed to download data.<br><br>Details: null</html>",
+                ExceptionUtil.explainOfflineAccessException(new OsmApiException("")));
+        assertEquals("<html>Failed to download data.<br><br>Details: test</html>",
+                ExceptionUtil.explainOfflineAccessException(new OsmApiException(new OfflineAccessException("test"))));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainOsmApiInitializationException} method.
+     */
+    @Test
+    public void testExplainOsmApiInitializationException() {
+        assertEquals("<html>Failed to initialize communication with the OSM server "+url.substring(0, url.length()-1)+".<br>"+
+                "Check the server URL in your preferences and your internet connection.</html>",
+                ExceptionUtil.explainOsmApiInitializationException(new OsmApiInitializationException("")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainOsmTransferException} method.
+     */
+    @Test
+    public void testExplainOsmTransferException() {
+        assertEquals("<html>Failed to open a connection to the remote server<br>'"+url+"'<br>"+
+                "for security reasons. This is most likely because you are running<br>"+
+                "in an applet and because you did not load your applet from '"+host+"'.</html>",
+                ExceptionUtil.explainOsmTransferException(new OsmApiException(new SecurityException("test"))));
+
+        assertEquals("<html>Failed to open a connection to the remote server<br>'"+url+"'.<br>"+
+                "Please check your internet connection.</html>",
+                ExceptionUtil.explainOsmTransferException(new OsmApiException(new SocketException("test"))));
+
+        assertEquals("<html>Failed to open a connection to the remote server<br>'"+url+"'.<br>"+
+                "Host name '"+host+"' could not be resolved. <br>"+
+                "Please check the API URL in your preferences and your internet connection.</html>",
+                ExceptionUtil.explainOsmTransferException(new OsmApiException(new UnknownHostException("test"))));
+
+        assertEquals("<html>Failed to upload data to or download data from<br>'"+url+"'<br>"+
+                "due to a problem with transferring data.<br>Details (untranslated): test</html>",
+                ExceptionUtil.explainOsmTransferException(new OsmApiException(new IOException("test"))));
+
+        assertEquals("<html>Failed to initialize communication with the OSM server "+url.substring(0, url.length()-1)+".<br>"+
+                "Check the server URL in your preferences and your internet connection.</html>",
+                ExceptionUtil.explainOsmTransferException(new OsmApiInitializationException("")));
+
+        assertEquals("<html>Failed to upload to changeset <strong>0</strong><br>because it has already been closed on ?.",
+                ExceptionUtil.explainOsmTransferException(new ChangesetClosedException("")));
+
+        assertEquals("<html>Uploading to the server <strong>failed</strong> because your current<br>"+
+                "dataset violates a precondition.<br>The error message is:<br>ResponseCode=412</html>",
+                ExceptionUtil.explainOsmTransferException(new OsmApiException(HttpURLConnection.HTTP_PRECON_FAILED, "", "")));
+
+        assertEquals("<html>The server reports that an object is deleted.<br>"+
+                "<strong>Uploading failed</strong> if you tried to update or delete this object.<br> "+
+                "<strong>Downloading failed</strong> if you tried to download this object.<br><br>"+
+                "The error message is:<br>ResponseCode=410</html>",
+                ExceptionUtil.explainOsmTransferException(new OsmApiException(HttpURLConnection.HTTP_GONE, "", "")));
+
+        assertEquals("<html>The OSM server<br>'"+url+"'<br>reported an internal server error.<br>"+
+                "This is most likely a temporary problem. Please try again later.</html>",
+                ExceptionUtil.explainOsmTransferException(new OsmApiException(HttpURLConnection.HTTP_INTERNAL_ERROR, "", "")));
+
+        assertEquals("<html>The OSM server '"+url+"' reported a bad request.<br><br>Error message(untranslated): </html>",
+                ExceptionUtil.explainOsmTransferException(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "", "")));
+
+        assertEquals("<html>Communication with the OSM server '"+url+"'failed. The server replied<br>"+
+                "the following error code and the following error message:<br><strong>Error code:<strong> 509<br>"+
+                "<strong>Error message (untranslated)</strong>: </html>",
+                ExceptionUtil.explainOsmTransferException(new OsmApiException(509, "", "")));
+
+        assertEquals("ResponseCode=0",
+                ExceptionUtil.explainOsmTransferException(new OsmApiException("")));
+    }
+
+    /**
+     * Test of {@link ExceptionUtil#explainPreconditionFailed} method.
+     */
+    @Test
+    public void testExplainPreconditionFailed() {
+        int code = HttpURLConnection.HTTP_PRECON_FAILED;
+        assertEquals("<html>Uploading to the server <strong>failed</strong> because your current<br>dataset violates a precondition.<br>"+
+                "The error message is:<br>ResponseCode=0</html>",
+                ExceptionUtil.explainPreconditionFailed(new OsmApiException("")));
+
+        assertEquals("<html>Uploading to the server <strong>failed</strong> because your current<br>dataset violates a precondition.<br>"+
+                "The error message is:<br>ResponseCode=412, Error Header=&lt;test&gt;</html>",
+                ExceptionUtil.explainPreconditionFailed(new OsmApiException(code, "test", "")));
+
+        assertEquals("<html><strong>Failed</strong> to delete <strong>node 1</strong>. It is still referred to by relation 1.<br>"+
+                "Please load the relation, remove the reference to the node, and upload again.</html>",
+                ExceptionUtil.explainPreconditionFailed(new OsmApiException(code, "Node 1 is still used by relation 1", "")));
+
+        assertEquals("<html><strong>Failed</strong> to delete <strong>node 1</strong>. It is still referred to by way 1.<br>"+
+                "Please load the way, remove the reference to the node, and upload again.</html>",
+                ExceptionUtil.explainPreconditionFailed(new OsmApiException(code, "Node 1 is still used by way 1", "")));
+
+        assertEquals("<html><strong>Failed</strong> to delete <strong>relation 1</strong>. It is still referred to by relation 2.<br>"+
+                "Please load the relation, remove the reference to the relation, and upload again.</html>",
+                ExceptionUtil.explainPreconditionFailed(new OsmApiException(code, "The relation 1 is used in relation 2", "")));
+
+        assertEquals("<html><strong>Failed</strong> to delete <strong>way 1</strong>. It is still referred to by relation 1.<br>"+
+                "Please load the relation, remove the reference to the way, and upload again.</html>",
+                ExceptionUtil.explainPreconditionFailed(new OsmApiException(code, "Way 1 is still used by relation 1", "")));
+
+        assertEquals("<html><strong>Failed</strong> to delete <strong>way 1</strong>. It is still referred to by nodes [1, 2].<br>"+
+                "Please load the nodes, remove the reference to the way, and upload again.</html>",
+                ExceptionUtil.explainPreconditionFailed(new OsmApiException(code, "Way 1 requires the nodes with id in 1,2", "")));
+    }
+}
