Checking for exceptions with HandlingResult

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Checking for exceptions with HandlingResult

nmarquesantos
Hi guys

So I know how to properly check when an exception is thrown, on my handler unit tests.

However, what is the correct approach when I want to make sure an exception was not thrown?

This is the best I've come up with so far:

 def "No exception is thrown"() {
        given:
        def noExceptionThrown = false

        when:
        def result =  RequestFixture.handle(new TestEndpoint(), { fixture -> fixture.uri("path/a)})

        then:
        try {
            result.exception(CustomException)
        } catch(ratpack.test.handling.HandlerExceptionNotThrownException e) {
            noExceptionThrown = (e != null)
        }

        noExceptionThrown
    }
Loading...