Good to use with unit/integration tests of Spark Java app.
Spark Java is pretty much dead
App
is your main Spark class that registeres all the routes in it's main
method.
Typical integration test case would look like this:
final class AppTest {
final HttpClient client = HttpClient.newHttpClient();
URI baseUrl;
@BeforeEach
void setUp() {
SparkServerStarter.start();
baseUrl = URI.create("http://localhost:" + Spark.port());
}
@Test
void testRunning() throws IOException, InterruptedException {
var request = HttpRequest.newBuilder()
.uri(baseUrl.resolve("/hello"))
.build();
assertEquals(200, client.send(request, HttpResponse.BodyHandlers.ofString()).statusCode());
}
}