Skip to content

Instantly share code, notes, and snippets.

@aesteve
Last active December 1, 2015 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aesteve/4042bf1d9960e883bd92 to your computer and use it in GitHub Desktop.
Save aesteve/4042bf1d9960e883bd92 to your computer and use it in GitHub Desktop.
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