Package ratpack.test
Interface CloseableApplicationUnderTest
-
- All Superinterfaces:
ApplicationUnderTest
,AutoCloseable
- All Known Subinterfaces:
EmbeddedApp
,GroovyEmbeddedApp
- All Known Implementing Classes:
GroovyRatpackMainApplicationUnderTest
,MainClassApplicationUnderTest
,MockApi
,ServerBackedApplicationUnderTest
public interface CloseableApplicationUnderTest extends ApplicationUnderTest, AutoCloseable
AnApplicationUnderTest
that is able to be shut down.Typically, the
close()
method is called by “test infrastructure”, such as in a JUnit@After
method.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
close()
Shuts down the application under test.default void
test(Action<? super TestHttpClient> action)
Provides the given action with atest http client
for this application, then closes this application.-
Methods inherited from interface ratpack.test.ApplicationUnderTest
getAddress, getHttpClient
-
-
-
-
Method Detail
-
test
default void test(Action<? super TestHttpClient> action) throws Exception
Provides the given action with atest 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.jupiter.api.Assertions.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()) ); } }
- Parameters:
action
- an action that tests this embedded application- Throws:
Exception
- any thrown byaction
-
close
void close()
Shuts down the application under test.The exact meaning of invoking this method is implementation dependent.
- Specified by:
close
in interfaceAutoCloseable
-
-