Fixes HttpEngine tests
This commit is contained in:
parent
2bf5313c2b
commit
d709d7f39a
@ -14,7 +14,6 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
@ -30,7 +29,7 @@ public class OkHttpEngineTest {
|
||||
server = new MockWebServer();
|
||||
server.enqueue(mockResponse);
|
||||
server.play();
|
||||
engine = new OkHttpEngine(server.getUrl("/tiles/vtm"));
|
||||
engine = (OkHttpEngine) new OkHttpEngine.OkHttpFactory().create();
|
||||
}
|
||||
|
||||
@After
|
||||
@ -50,7 +49,7 @@ public class OkHttpEngineTest {
|
||||
|
||||
@Test
|
||||
public void sendRequest_shouldAppendXYZToPath() throws Exception {
|
||||
engine.sendRequest(new OSciMap4TileSource("http://www.example.org/tiles/vtm"),
|
||||
engine.sendRequest(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()),
|
||||
new Tile(1, 2, new Integer(3).byteValue()));
|
||||
|
||||
RecordedRequest request = server.takeRequest();
|
||||
@ -59,7 +58,7 @@ public class OkHttpEngineTest {
|
||||
|
||||
@Test
|
||||
public void read_shouldReturnResponseStream() throws Exception {
|
||||
engine.sendRequest(new OSciMap4TileSource("http://www.example.org/tiles/vtm"),
|
||||
engine.sendRequest(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()),
|
||||
new Tile(1, 2, new Integer(3).byteValue()));
|
||||
|
||||
InputStream responseStream = engine.read();
|
||||
@ -69,7 +68,7 @@ public class OkHttpEngineTest {
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void close_shouldCloseInputStream() throws Exception {
|
||||
engine.sendRequest(new OSciMap4TileSource("http://www.example.org/tiles/vtm"),
|
||||
engine.sendRequest(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()),
|
||||
new Tile(1, 2, new Integer(3).byteValue()));
|
||||
engine.close();
|
||||
|
||||
@ -80,7 +79,7 @@ public class OkHttpEngineTest {
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void requestCompleted_shouldCloseInputStream() throws Exception {
|
||||
engine.sendRequest(new OSciMap4TileSource("http://www.example.org/tiles/vtm"),
|
||||
engine.sendRequest(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()),
|
||||
new Tile(1, 2, new Integer(3).byteValue()));
|
||||
engine.requestCompleted(true);
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.oscim.tiling.source;
|
||||
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
@ -29,7 +27,7 @@ public class UrlTileSourceTest {
|
||||
|
||||
@Test
|
||||
public void shouldUseCustomHttpEngine() throws Exception {
|
||||
tileSource.setHttpEngine(new OkHttpEngine(tileSource.getUrl()));
|
||||
tileSource.setHttpEngine(new OkHttpEngine.OkHttpFactory());
|
||||
TestTileDataSource dataSource = (TestTileDataSource) tileSource.getDataSource();
|
||||
assertThat(dataSource.getConnection()).isInstanceOf(OkHttpEngine.class);
|
||||
}
|
||||
|
@ -6,7 +6,9 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
import org.oscim.tiling.source.OkHttpEngine.OkHttpFactory;
|
||||
import org.oscim.tiling.source.HttpEngine;
|
||||
import org.oscim.tiling.source.LwHttp;
|
||||
import org.oscim.tiling.source.OkHttpEngine;
|
||||
import org.oscim.tiling.source.UrlTileDataSource;
|
||||
|
||||
public class BitmapTileSourceTest {
|
||||
@ -14,7 +16,7 @@ public class BitmapTileSourceTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
tileSource = new TestBitmapTileSource("http://tile.openstreetmap.org", 0, 18);
|
||||
tileSource = new BitmapTileSource("http://tile.openstreetmap.org", 0, 18);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -24,8 +26,8 @@ public class BitmapTileSourceTest {
|
||||
|
||||
@Test
|
||||
public void shouldUseLwHttp() throws Exception {
|
||||
LwHttpFactory lwHttp = Mockito.mock(LwHttpFactory.class);
|
||||
tileSource.setHttpEngine(lwHttp);
|
||||
LwHttp lwHttp = Mockito.mock(LwHttp.class);
|
||||
tileSource.setHttpEngine(new TestHttpFactory(lwHttp));
|
||||
ITileDataSource dataSource = tileSource.getDataSource();
|
||||
dataSource.destroy();
|
||||
Mockito.verify(lwHttp).close();
|
||||
@ -33,16 +35,26 @@ public class BitmapTileSourceTest {
|
||||
|
||||
@Test
|
||||
public void shouldUseOkHttp() throws Exception {
|
||||
OkHttpFactory okHttp = Mockito.mock(OkHttpFactory.class);
|
||||
tileSource.setHttpEngine(okHttp);
|
||||
OkHttpEngine okHttp = Mockito.mock(OkHttpEngine.class);
|
||||
tileSource.setHttpEngine(new TestHttpFactory(okHttp));
|
||||
UrlTileDataSource dataSource = (UrlTileDataSource) tileSource.getDataSource();
|
||||
dataSource.destroy();
|
||||
//Mockito.verify(dataSource.mConn).close();
|
||||
Mockito.verify(okHttp).close();
|
||||
}
|
||||
|
||||
class TestBitmapTileSource extends BitmapTileSource {
|
||||
public TestBitmapTileSource(String url, int zoomMin, int zoomMax) {
|
||||
super(url, zoomMin, zoomMax);
|
||||
/**
|
||||
* Test factory that allows the specific {@link HttpEngine} instance to be set.
|
||||
*/
|
||||
class TestHttpFactory implements HttpEngine.Factory {
|
||||
final HttpEngine engine;
|
||||
|
||||
public TestHttpFactory(HttpEngine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpEngine create() {
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
import org.oscim.tiling.source.HttpEngine;
|
||||
import org.oscim.tiling.source.LwHttp;
|
||||
import org.oscim.tiling.source.OkHttpEngine;
|
||||
|
||||
@ -25,7 +26,7 @@ public class OSciMap4TileSourceTest {
|
||||
@Test
|
||||
public void shouldUseLwHttp() throws Exception {
|
||||
LwHttp lwHttp = Mockito.mock(LwHttp.class);
|
||||
tileSource.setHttpEngine(lwHttp);
|
||||
tileSource.setHttpEngine(new TestHttpFactory(lwHttp));
|
||||
ITileDataSource dataSource = tileSource.getDataSource();
|
||||
dataSource.destroy();
|
||||
Mockito.verify(lwHttp).close();
|
||||
@ -34,9 +35,25 @@ public class OSciMap4TileSourceTest {
|
||||
@Test
|
||||
public void shouldUseOkHttp() throws Exception {
|
||||
OkHttpEngine okHttp = Mockito.mock(OkHttpEngine.class);
|
||||
tileSource.setHttpEngine(okHttp);
|
||||
tileSource.setHttpEngine(new TestHttpFactory(okHttp));
|
||||
ITileDataSource dataSource = tileSource.getDataSource();
|
||||
dataSource.destroy();
|
||||
Mockito.verify(okHttp).close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test factory that allows the specific {@link HttpEngine} instance to be set.
|
||||
*/
|
||||
class TestHttpFactory implements HttpEngine.Factory {
|
||||
final HttpEngine engine;
|
||||
|
||||
public TestHttpFactory(HttpEngine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpEngine create() {
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user