Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import io.vertx.core.Handler
import io.vertx.groovy.ext.unit.Async
import io.vertx.groovy.ext.unit.TestContext
import io.vertx.groovy.ext.unit.junit.VertxUnitRunner
import org.junit.runner.RunWith
@RunWith(VertxUnitRunner.class)
abstract class GroovyTestBase {
public GroovyTestBase() {
TestContext.metaClass.asyncAssertSuccess = { Handler handler = null ->
TestContext ctx = delegate
Async async = delegate.async()
return { res ->
if (res.failed()) {
ctx.fail(res.cause())
} else {
try {
if (handler) {
handler.handle(res.result())
}
async.complete()
} catch(all) {
ctx.fail(all)
}
}
}
}
TestContext.metaClass.asyncAssertFailure = { Handler handler = null ->
TestContext ctx = delegate
Async async = delegate.async()
return { res ->
if (res.failed()) {
try {
handler.handle(res.cause())
async.complete()
} catch(all) {
ctx.fail(all)
}
} else {
ctx.fail("Was expecting a failure instead of success")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.