Created
September 25, 2016 12:49
-
-
Save dherges/3ac82646ec76632a36542fa2e6be73ed 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
public class SparkRunner extends BlockJUnit4ClassRunner { | |
private Class<? extends SparkApplicationContainer> applicationContainer; | |
/* ... */ | |
private void scanAnnotation() { | |
SparkApplicationTest annotation = getTestClass().getAnnotation(SparkApplicationTest.class); | |
applicationContainer = annotation.value(); | |
/* ... */ | |
} | |
private void sparkBootstrap() throws IllegalAccessException, InstantiationException { | |
/* ... */ | |
applicationContainer.newInstance().sparkApplication().init(); | |
/* ... */ | |
} | |
/* ... */ | |
} |
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
@RunWith(SparkRunner.class) | |
@SparkApplicationTest(value = TestApplicationContainer.class, port = 4444) | |
public class TwitterAppTest { | |
@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) | |
.jsonPath("$[0].user.name", String.class, "Maria Moccachino"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment