fix: HttpEngine tests

This commit is contained in:
Hannes Janetzek
2014-04-02 07:07:30 +02:00
parent 3f9847f617
commit 5c277f4d54
5 changed files with 33 additions and 31 deletions

View File

@@ -1,8 +1,11 @@
package org.oscim.tiling.source;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import com.squareup.okhttp.mockwebserver.RecordedRequest;
import static org.fest.assertions.api.Assertions.assertThat;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.junit.After;
import org.junit.Before;
@@ -10,12 +13,9 @@ import org.junit.Test;
import org.oscim.core.Tile;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import static org.fest.assertions.api.Assertions.assertThat;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import com.squareup.okhttp.mockwebserver.RecordedRequest;
public class OkHttpEngineTest {
private OkHttpEngine engine;
@@ -29,7 +29,8 @@ public class OkHttpEngineTest {
server = new MockWebServer();
server.enqueue(mockResponse);
server.play();
engine = (OkHttpEngine) new OkHttpEngine.OkHttpFactory().create();
engine = (OkHttpEngine) new OkHttpEngine.OkHttpFactory()
.create(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()));
}
@After
@@ -44,13 +45,12 @@ public class OkHttpEngineTest {
@Test(expected = IllegalArgumentException.class)
public void sendRequest_shouldRejectNullTile() throws Exception {
engine.sendRequest(null, null);
engine.sendRequest(null);
}
@Test
public void sendRequest_shouldAppendXYZToPath() throws Exception {
engine.sendRequest(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()),
new Tile(1, 2, new Integer(3).byteValue()));
engine.sendRequest(new Tile(1, 2, new Integer(3).byteValue()));
RecordedRequest request = server.takeRequest();
assertThat(request.getPath()).isEqualTo("/tiles/vtm/3/1/2.vtm");
@@ -58,8 +58,7 @@ public class OkHttpEngineTest {
@Test
public void read_shouldReturnResponseStream() throws Exception {
engine.sendRequest(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()),
new Tile(1, 2, new Integer(3).byteValue()));
engine.sendRequest(new Tile(1, 2, new Integer(3).byteValue()));
InputStream responseStream = engine.read();
String response = new BufferedReader(new InputStreamReader(responseStream)).readLine();
@@ -68,8 +67,7 @@ public class OkHttpEngineTest {
@Test(expected = IOException.class)
public void close_shouldCloseInputStream() throws Exception {
engine.sendRequest(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()),
new Tile(1, 2, new Integer(3).byteValue()));
engine.sendRequest(new Tile(1, 2, new Integer(3).byteValue()));
engine.close();
// Calling read after the stream is closed should throw an exception.
@@ -79,8 +77,7 @@ public class OkHttpEngineTest {
@Test(expected = IOException.class)
public void requestCompleted_shouldCloseInputStream() throws Exception {
engine.sendRequest(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()),
new Tile(1, 2, new Integer(3).byteValue()));
engine.sendRequest(new Tile(1, 2, new Integer(3).byteValue()));
engine.requestCompleted(true);
// Calling read after the stream is closed should throw an exception.