Last active
September 25, 2016 12:23
-
-
Save dherges/a17287ea6bdb0ffab7fe7d3b8f803b2d to your computer and use it in GitHub Desktop.
ok-testing-reloaded-medium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.assertj.core.api.Assertions.fail; | |
public class OkHttpResponseAssert | |
extends AbstractAssert<OkHttpResponseAssert, Response> | |
implements Assert<OkHttpResponseAssert, Response> { | |
/* ... */ | |
public <T> OkHttpResponseAssert jsonPath(String jsonPath, Class<T> type, T expected) { | |
T object = JsonPath.parse(consumeResponseBody()).read(jsonPath, type); | |
objects.assertNotNull(info, object); | |
objects.assertEqual(info, object, expected); | |
return this; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.assertj.core.api.Assertions.assertThat; | |
import static ext.assertj.MyAssertions.assertThat; | |
@RunWith(SparkRunner.class) | |
@SparkApplicationTest(value = TwitterApp.class, port = 4444) | |
public class TwitterAppTest { | |
private final OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); | |
@Test | |
public void testAgain() throws IOException { | |
final Request request = new Request.Builder() | |
.get() | |
.url("http://localhost:4444/statuses/retweets/200") | |
.build(); | |
final Response response = okHttpClient.newCall(request).execute(); | |
assertThat(response) | |
.isOk() | |
.hasContentType("application/json") | |
.jsonPath("$.length()", Integer.class, 100) | |
.jsonPath("$[0].id", Integer.class, 200); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment