Package ratpack.test

Interface CloseableApplicationUnderTest

    • Method Detail

      • test

        default void test​(Action<? super TestHttpClient> action)
                   throws java.lang.Exception
        Provides the given action with a 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())
             );
           }
         }
         
        Parameters:
        action - an action that tests this embedded application
        Throws:
        java.lang.Exception - any thrown by action
      • close

        void close()
        Shuts down the application under test.

        The exact meaning of invoking this method is implementation dependent.

        Specified by:
        close in interface java.lang.AutoCloseable