Skip to content

Commit

Permalink
Allow the use of UniAsserter in @beforeeach and @AfterEach test methods
Browse files Browse the repository at this point in the history
Fixes: #19109
  • Loading branch information
geoand committed Aug 2, 2021
1 parent 72cc2d6 commit 138eee3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import io.smallrye.mutiny.Uni;

public abstract class ReactiveTransactionalInterceptorBase {
private static final String JUNIT_TEST_CLASS = "org.junit.jupiter.api.Test";
private static final String JUNIT_TEST_ANN = "org.junit.jupiter.api.Test";
private static final String JUNIT_BEFORE_EACH_ANN = "org.junit.jupiter.api.BeforeEach";
private static final String JUNIT_AFTER_EACH_ANN = "org.junit.jupiter.api.AfterEach";
private static final String UNI_ASSERTER_CLASS = "io.quarkus.test.junit.vertx.UniAsserter";

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -57,8 +59,10 @@ public Object intercept(InvocationContext ic) throws Exception {

protected boolean isSpecialTestMethod(InvocationContext ic) {
Method method = ic.getMethod();
return hasAnnotation(JUNIT_TEST_CLASS, method)
&& hasParameter(UNI_ASSERTER_CLASS, method);
return hasParameter(UNI_ASSERTER_CLASS, method)
&& (hasAnnotation(JUNIT_TEST_ANN, method)
|| hasAnnotation(JUNIT_BEFORE_EACH_ANN, method)
|| hasAnnotation(JUNIT_AFTER_EACH_ANN, method));
}

protected Object handleSpecialTestMethod(InvocationContext ic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.quarkus.it.panache.reactive;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import io.quarkus.hibernate.reactive.panache.Panache;
import io.quarkus.test.TestReactiveTransaction;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.vertx.UniAsserter;

@QuarkusTest
public class TestReactiveTransactionTest {

@TestReactiveTransaction
@Test
public void testTestTransaction(UniAsserter asserter) {
asserter.assertNotNull(() -> Panache.currentTransaction());
}

@TestReactiveTransaction
@BeforeEach
public void beforeEach(UniAsserter asserter) {
asserter.assertNotNull(() -> Panache.currentTransaction());
}
}

0 comments on commit 138eee3

Please sign in to comment.