Changeset 14539 in josm for trunk/test/unit


Ignore:
Timestamp:
2018-12-09T22:02:02+01:00 (5 years ago)
Author:
Don-vip
Message:

see #16073 - check response contents correctly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java

    r14538 r14539  
    1212import java.util.List;
    1313import java.util.Map;
     14import java.util.Optional;
    1415import java.util.TreeMap;
    1516import java.util.concurrent.TimeUnit;
     
    8990    }
    9091
    91     private byte[] checkUrl(ImageryInfo info, String url) {
     92    private Optional<byte[]> checkUrl(ImageryInfo info, String url) {
    9293        if (url != null && !url.isEmpty()) {
    9394            if (workingURLs.containsKey(url)) {
    94                 return workingURLs.get(url);
     95                return Optional.of(workingURLs.get(url));
    9596            }
    9697            try {
     
    110111                        workingURLs.put(url, data);
    111112                    }
    112                     return data;
     113                    return Optional.of(data);
    113114                } finally {
    114115                    response.disconnect();
     
    118119            }
    119120        }
    120         return new byte[0];
     121        return Optional.empty();
    121122    }
    122123
    123124    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"));
    127126    }
    128127
     
    133132            try {
    134133                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);
    139142                    }
    140                 } catch (IOException e) {
    141                     addImageError(info, url, data, e.toString());
    142                     Logging.trace(e);
    143                 }
     143                });
    144144                return;
    145145            } catch (IOException e) {
Note: See TracChangeset for help on using the changeset viewer.