- Timestamp:
- 2018-12-09T22:02:02+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java
r14538 r14539 12 12 import java.util.List; 13 13 import java.util.Map; 14 import java.util.Optional; 14 15 import java.util.TreeMap; 15 16 import java.util.concurrent.TimeUnit; … … 89 90 } 90 91 91 private byte[]checkUrl(ImageryInfo info, String url) {92 private Optional<byte[]> checkUrl(ImageryInfo info, String url) { 92 93 if (url != null && !url.isEmpty()) { 93 94 if (workingURLs.containsKey(url)) { 94 return workingURLs.get(url);95 return Optional.of(workingURLs.get(url)); 95 96 } 96 97 try { … … 110 111 workingURLs.put(url, data); 111 112 } 112 return data;113 return Optional.of(data); 113 114 } finally { 114 115 response.disconnect(); … … 118 119 } 119 120 } 120 return new byte[0];121 return Optional.empty(); 121 122 } 122 123 123 124 private void checkLinkUrl(ImageryInfo info, String url) { 124 if (url != null && checkUrl(info, url).length == 0) { 125 addError(info, url + " -> returned empty contents"); 126 } 125 checkUrl(info, url).filter(x -> x.length == 0).ifPresent(x -> addError(info, url + " -> returned empty contents")); 127 126 } 128 127 … … 133 132 try { 134 133 String url = tileSource.getTileUrl(zoom, xy.getXIndex(), xy.getYIndex()); 135 byte[] data = checkUrl(info, url); 136 try (ByteArrayInputStream bais = new ByteArrayInputStream(data)) { 137 if (ImageIO.read(bais) == null) { 138 addImageError(info, url, data, "did not return an image"); 134 checkUrl(info, url).ifPresent(data -> { 135 try (ByteArrayInputStream bais = new ByteArrayInputStream(data)) { 136 if (ImageIO.read(bais) == null) { 137 addImageError(info, url, data, "did not return an image"); 138 } 139 } catch (IOException e) { 140 addImageError(info, url, data, e.toString()); 141 Logging.trace(e); 139 142 } 140 } catch (IOException e) { 141 addImageError(info, url, data, e.toString()); 142 Logging.trace(e); 143 } 143 }); 144 144 return; 145 145 } catch (IOException e) {
Note:
See TracChangeset
for help on using the changeset viewer.