/** * Set a callback executed before each test and after the suite <code>before</code> callback. * @param callback the callback * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.unit.TestSuite beforeEach(Handler<io.vertx.rxjava.ext.unit.TestContext> callback) { delegate.beforeEach(new Handler<io.vertx.ext.unit.TestContext>() { public void handle(io.vertx.ext.unit.TestContext event) { callback.handle(io.vertx.rxjava.ext.unit.TestContext.newInstance(event)); } }); return this; }
/** * Set a callback executed before each test and after the suite <code>before</code> callback. * @param callback the callback * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.unit.TestSuite beforeEach(Handler<io.vertx.rxjava.ext.unit.TestContext> callback) { delegate.beforeEach(new Handler<io.vertx.ext.unit.TestContext>() { public void handle(io.vertx.ext.unit.TestContext event) { callback.handle(io.vertx.rxjava.ext.unit.TestContext.newInstance(event)); } }); return this; }
@Test public void testRepeatBeforeAfterEach() throws Exception { List<String> events = Collections.synchronizedList(new ArrayList<String>()); TestSuite suite = TestSuite.create("my_suite").beforeEach(ctx -> { events.add("before"); }).test("my_test", 3, ctx -> { events.add("test"); }).afterEach(ctx -> { events.add("after"); }); TestReporter reporter = new TestReporter(); run(suite, reporter); reporter.await(); assertEquals(1, reporter.results.size()); assertEquals(0, reporter.exceptions.size()); assertEquals(1, reporter.results.size()); assertEquals(Arrays.asList("before", "test", "after", "before", "test", "after", "before", "test", "after"), events); assertEquals("my_test", reporter.results.get(0).name()); assertFalse(reporter.results.get(0).failed()); }
}); } else { suite = suite.beforeEach(context -> { count.compareAndSet(0, 1); queue.add(context.async());
} else { AtomicBoolean failed = new AtomicBoolean(); suite.beforeEach(context -> { if (failed.compareAndSet(false, true)) { throw new RuntimeException();
suite = suite.beforeEach(context -> { count.incrementAndGet(); });
}).beforeEach(context -> { Integer value = context.get("value"); beforeEach.add(value);