public interface CloseableApplicationUnderTest extends ApplicationUnderTest, java.lang.AutoCloseable
ApplicationUnderTest
that is able to be shut down.
Typically, the close()
method is called by “test infrastructure”, such as in a JUnit @After
method.
Modifier and Type | Method and Description |
---|---|
void |
close()
Shuts down the application under test.
|
default void |
test(Action<? super TestHttpClient> action)
Provides the given action with a
test http client for this application, then closes this application. |
getAddress, getHttpClient
default void test(Action<? super TestHttpClient> action) throws java.lang.Exception
test http client
for this application, then closes this application.
The application will be closed regardless of whether the given action throws an exception.
import ratpack.test.embed.EmbeddedApp;
import static org.junit.Assert.assertEquals;
public class Example {
public static void main(String... args) throws Exception {
EmbeddedApp.fromHandler(ctx ->
ctx.render("ok")
).test(httpClient ->
assertEquals("ok", httpClient.get().getBody().getText())
);
}
}
action
- an action that tests this embedded applicationjava.lang.Exception
- any thrown by action
void close()
The exact meaning of invoking this method is implementation dependent.
close
in interface java.lang.AutoCloseable