Created
September 25, 2016 11:57
-
-
Save dherges/cd7ed2179f17b4e8c334ce3b55ce8ba8 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 spark.Spark.get; | |
| public class TwitterApp implements SparkApplication { | |
| @Override | |
| public void init() { | |
| get("/", (req, res) -> "Hello again!"); | |
| } | |
| } |
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 spark.Spark.awaitInitialization; | |
| import static spark.Spark.port; | |
| import static spark.Spark.stop; | |
| public class TwitterAppTest { | |
| /** bootstraps the spark application by starting an embedded web server */ | |
| @Before | |
| public void before() { | |
| port(4444); | |
| new TwitterApp().init(); | |
| awaitInitialization(); | |
| } | |
| /** after test run, shuts down the web server */ | |
| @After | |
| public void after() { | |
| stop(); | |
| } | |
| @Test | |
| public void test() throws IOException { | |
| final OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); | |
| final Request request = new Request.Builder() | |
| .get() | |
| .url("http://localhost:4444") | |
| .build(); | |
| final Response response = okHttpClient.newCall(request).execute(); | |
| assertThat(response.body().string()).isEqualTo("Hello again!"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment