Skip to content

Instantly share code, notes, and snippets.

@dherges
Last active September 25, 2016 10:48
Show Gist options
  • Save dherges/aee5f3ab230b56674964567821ce1417 to your computer and use it in GitHub Desktop.
Save dherges/aee5f3ab230b56674964567821ce1417 to your computer and use it in GitHub Desktop.
ok-testing-reloaded-medium
public class TwitterApiTest {
@Rule
public MockWebServerPlus server = new MockWebServerPlus();
private final OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
@Test
public void homeTimeline() throws IOException, InterruptedException {
// replay scripted http response from yaml file
server.enqueue("twitter/statuses/home_timeline");
// execute request
final Request request = new Request.Builder()
.get()
.url(server.url("statuses/home_timeline.json"))
.build();
final Response response = okHttpClient.newCall(request).execute();
// assert response
assertThat(response.code()).isEqualTo(200);
assertThat(response.body().string()).startsWith("[\n {\n \"coordinates\"");
// verify request
final RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/statuses/home_timeline.json");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment