Changeset 8606 in josm for trunk/test/unit


Ignore:
Timestamp:
2015-07-16T21:13:12+02:00 (9 years ago)
Author:
wiktorn
Message:

Properly report exceptions from tile download

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java

    r8604 r8606  
    1515public class JCSCachedTileLoaderJobTest {
    1616    private static class TestCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, CacheEntry> {
     17        private String url;
    1718
    18         private int responseCode;
    19 
    20         public TestCachedTileLoaderJob(int responseCode) throws IOException {
     19        public TestCachedTileLoaderJob(String url) throws IOException {
    2120            super(getCache(), 30000, 30000, null);
    22             this.responseCode = responseCode;
     21            this.url = url;
    2322        }
    2423
     
    3534        public URL getUrl() {
    3635            try {
    37                 return new URL("http://httpstat.us/" + Integer.toString(responseCode));
     36                return new URL(url);
    3837            } catch (MalformedURLException e) {
    3938                throw new RuntimeException(e);
     
    8685    }
    8786
     87    @Test
     88    public void testUnkownHost() throws Exception {
     89        TestCachedTileLoaderJob job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown");
     90        Listener listener = new Listener();
     91        job.submit(listener, true);
     92        synchronized (listener) {
     93            if (!listener.ready) {
     94                listener.wait();
     95            }
     96        }
     97        assertEquals("java.net.UnknownHostException: unkownhost.unkownhost", listener.attributes.getErrorMessage());
     98    }
     99
    88100    public void testStatusCode(int responseCode) throws Exception {
    89         TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(responseCode);
     101        TestCachedTileLoaderJob job = getStatusLoaderJob(responseCode);
    90102        Listener listener = new Listener();
    91103        job.submit(listener, true);
     
    98110
    99111    }
     112
     113    private static TestCachedTileLoaderJob getStatusLoaderJob(int responseCode) throws IOException {
     114        return new TestCachedTileLoaderJob("http://httpstat.us/" + responseCode);
     115    }
     116
    100117}
    101118
Note: See TracChangeset for help on using the changeset viewer.