Package ratpack.test
Interface CloseableApplicationUnderTest
-
- All Superinterfaces:
ApplicationUnderTest,java.lang.AutoCloseable
- All Known Subinterfaces:
EmbeddedApp,GroovyEmbeddedApp
- All Known Implementing Classes:
GroovyRatpackMainApplicationUnderTest,MainClassApplicationUnderTest,MockApi,ServerBackedApplicationUnderTest
public interface CloseableApplicationUnderTest extends ApplicationUnderTest, java.lang.AutoCloseable
AnApplicationUnderTestthat is able to be shut down.Typically, the
close()method is called by “test infrastructure”, such as in a JUnit@Aftermethod.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidclose()Shuts down the application under test.default voidtest(Action<? super TestHttpClient> action)Provides the given action with atest http clientfor 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 java.lang.Exception
Provides the given action with atest http clientfor 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()) ); } }- Parameters:
action- an action that tests this embedded application- Throws:
java.lang.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:
closein interfacejava.lang.AutoCloseable
-
-