Index: trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java
===================================================================
--- trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java	(revision 14533)
+++ trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java	(revision 14535)
@@ -4,6 +4,8 @@
 import static org.junit.Assert.assertTrue;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -15,4 +17,7 @@
 import java.util.concurrent.TimeUnit;
 
+import javax.imageio.ImageIO;
+
+import org.apache.commons.jcs.access.CacheAccess;
 import org.junit.Before;
 import org.junit.Rule;
@@ -34,5 +39,7 @@
 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
 import org.openstreetmap.josm.data.imagery.Shape;
+import org.openstreetmap.josm.data.imagery.TMSCachedTileLoaderJob;
 import org.openstreetmap.josm.data.imagery.TemplatedWMSTileSource;
+import org.openstreetmap.josm.data.imagery.TileJobOptions;
 import org.openstreetmap.josm.data.imagery.WMSEndpointTileSource;
 import org.openstreetmap.josm.data.imagery.WMTSTileSource;
@@ -64,4 +71,5 @@
     private final Set<String> workingURLs = Collections.synchronizedSet(new HashSet<>());
 
+    private TMSCachedTileLoaderJob helper;
     private List<String> ignoredErrors;
 
@@ -72,4 +80,5 @@
     @Before
     public void before() throws IOException {
+        helper = new TMSCachedTileLoaderJob(null, null, new CacheAccess<>(null), new TileJobOptions(0, 0, null, 0), null);
         ignoredErrors = TestUtils.getIgnoredErrorMessages(ImageryPreferenceTestIT.class);
     }
@@ -82,5 +91,5 @@
     }
 
-    private void checkUrl(ImageryInfo info, String url) {
+    private byte[] checkUrl(ImageryInfo info, String url) {
         if (url != null && !url.isEmpty() && !workingURLs.contains(url)) {
             try {
@@ -97,8 +106,19 @@
                     workingURLs.add(url);
                 }
-                response.disconnect();
+                try {
+                    return Utils.readBytesFromStream(response.getContent());
+                } finally {
+                    response.disconnect();
+                }
             } catch (IOException e) {
                 addError(info, url + " -> " + e);
             }
+        }
+        return new byte[0];
+    }
+
+    private void checkLinkUrl(ImageryInfo info, String url) {
+        if (url != null && checkUrl(info, url).length == 0) {
+            addError(info, url + " -> returned empty contents");
         }
     }
@@ -109,5 +129,14 @@
         for (int i = 0; i < 3; i++) {
             try {
-                checkUrl(info, tileSource.getTileUrl(zoom, xy.getXIndex(), xy.getYIndex()));
+                String url = tileSource.getTileUrl(zoom, xy.getXIndex(), xy.getYIndex());
+                byte[] data = checkUrl(info, url);
+                try (ByteArrayInputStream bais = new ByteArrayInputStream(data)) {
+                    if (ImageIO.read(bais) == null) {
+                        addImageError(info, url, data, "did not return an image");
+                    }
+                } catch (IOException e) {
+                    addImageError(info, url, data, e.toString());
+                    Logging.trace(e);
+                }
                 return;
             } catch (IOException e) {
@@ -125,4 +154,10 @@
             }
         }
+    }
+
+    private void addImageError(ImageryInfo info, String url, byte[] data, String defaultMessage) {
+        // Check if we have received an error message
+        String error = helper.detectErrorMessage(new String(data, StandardCharsets.UTF_8));
+        addError(info, url + " -> " + (error != null ? error : defaultMessage));
     }
 
@@ -184,12 +219,12 @@
         }
 
-        checkUrl(info, info.getAttributionImageURL());
-        checkUrl(info, info.getAttributionLinkURL());
+        checkLinkUrl(info, info.getAttributionImageURL());
+        checkLinkUrl(info, info.getAttributionLinkURL());
         String eula = info.getEulaAcceptanceRequired();
         if (eula != null) {
-            checkUrl(info, eula.replaceAll("\\{lang\\}", ""));
-        }
-        checkUrl(info, info.getPermissionReferenceURL());
-        checkUrl(info, info.getTermsOfUseURL());
+            checkLinkUrl(info, eula.replaceAll("\\{lang\\}", ""));
+        }
+        checkLinkUrl(info, info.getPermissionReferenceURL());
+        checkLinkUrl(info, info.getTermsOfUseURL());
 
         try {
