Changeset 14564 in josm for trunk/test/unit
- Timestamp:
- 2018-12-15T19:24:34+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java
r14553 r14564 12 12 import java.util.Collections; 13 13 import java.util.List; 14 import java.util.Locale; 14 15 import java.util.Map; 15 16 import java.util.Optional; … … 137 138 } 138 139 139 private booleancheckTileUrl(ImageryInfo info, AbstractTileSource tileSource, ICoordinate center, int zoom)140 private String checkTileUrl(ImageryInfo info, AbstractTileSource tileSource, ICoordinate center, int zoom) 140 141 throws IOException { 141 142 TileXY xy = tileSource.latLonToTileXY(center, zoom); … … 143 144 try { 144 145 String url = tileSource.getTileUrl(zoom, xy.getXIndex(), xy.getYIndex()); 145 checkUrl(info, url).ifPresent(data -> { 146 Optional<byte[]> optional = checkUrl(info, url); 147 String error = ""; 148 if (optional.isPresent()) { 149 byte[] data = optional.get(); 146 150 try (ByteArrayInputStream bais = new ByteArrayInputStream(data)) { 147 151 if (ImageIO.read(bais) == null) { 148 addImageError(info, url, data, zoom, "did not return an image");152 error = addImageError(info, url, data, zoom, "did not return an image"); 149 153 } 150 154 } catch (IOException e) { 151 addImageError(info, url, data, zoom, e.toString());155 error = addImageError(info, url, data, zoom, e.toString()); 152 156 Logging.trace(e); 153 157 } 154 }); 155 // Determines if this is a success (no error message with current zoom marker) 156 return errors.getOrDefault(info.getCountryCode(), Collections.emptyMap()) 157 .getOrDefault(info, Collections.emptyList()) 158 .stream().noneMatch(e -> e.contains(zoomMarker(zoom))); 158 } 159 return error; 159 160 } catch (IOException e) { 160 161 // Try up to three times max to allow Bing source to initialize itself … … 171 172 } 172 173 } 173 return false;174 return ""; 174 175 } 175 176 … … 178 179 } 179 180 180 private voidaddImageError(ImageryInfo info, String url, byte[] data, int zoom, String defaultMessage) {181 private String addImageError(ImageryInfo info, String url, byte[] data, int zoom, String defaultMessage) { 181 182 // Check if we have received an error message 182 183 String error = helper.detectErrorMessage(new String(data, StandardCharsets.UTF_8)); 183 addError(info, url + zoomMarker(zoom) + (error != null ? error.split("\\n")[0] : defaultMessage)); 184 String errorMsg = url + zoomMarker(zoom) + (error != null ? error.split("\\n")[0] : defaultMessage); 185 addError(info, errorMsg); 186 return errorMsg; 184 187 } 185 188 … … 258 261 int maxZoom = info.getMaxZoom() > 0 ? Math.min(DEFAULT_ZOOM, info.getMaxZoom()) : DEFAULT_ZOOM; 259 262 for (int zoom = info.getMinZoom(); zoom < maxZoom; zoom++) { 260 if ( checkTileUrl(info, tileSource, center, zoom)) {263 if (!isZoomError(checkTileUrl(info, tileSource, center, zoom))) { 261 264 break; 262 265 } … … 273 276 checkEntry(mirror); 274 277 } 278 } 279 280 private static boolean isZoomError(String error) { 281 String[] parts = error.split(" -> "); 282 String lastPart = parts.length > 0 ? parts[parts.length - 1].toLowerCase(Locale.ENGLISH) : ""; 283 return lastPart.contains("bbox") 284 || lastPart.contains("bounding box"); 275 285 } 276 286
Note:
See TracChangeset
for help on using the changeset viewer.