Fixes HttpEngine tests
This commit is contained in:
committed by
Hannes Janetzek
parent
2bf5313c2b
commit
d709d7f39a
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user