Skip to content

Commit

Permalink
Merge pull request #36841 from mkouba/tx-uni-asserter-test-improvement
Browse files Browse the repository at this point in the history
TransactionalUniAsserterTest: test that injected argument is used
  • Loading branch information
mkouba authored Nov 6, 2023
2 parents 19cc4ee + 73e6e45 commit 404e820
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.concurrent.atomic.AtomicBoolean;

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

import io.quarkus.hibernate.reactive.panache.Panache;
Expand All @@ -14,11 +18,14 @@
@QuarkusTest
public class TransactionalUniAsserterTest {

private static final AtomicBoolean ASSERTER_USED = new AtomicBoolean();

@RunOnVertxContext
@Test
public void testTransactionalUniAsserter(TransactionalUniAsserter asserter) {
assertNotNull(asserter);
asserter.assertThat(Panache::currentTransaction, transaction -> {
ASSERTER_USED.set(true);
assertNotNull(transaction);
assertFalse(transaction.isMarkedForRollback());
asserter.putData("tx", transaction);
Expand All @@ -30,4 +37,9 @@ public void testTransactionalUniAsserter(TransactionalUniAsserter asserter) {
});
}

@AfterAll
static void afterAll() {
assertTrue(ASSERTER_USED.get());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.function.Supplier;

import org.junit.jupiter.api.Test;
import org.opentest4j.AssertionFailedError;

import io.smallrye.mutiny.Uni;

Expand Down Expand Up @@ -94,6 +95,11 @@ public void testAssertThat() {
testAsserterFailure(ua -> ua.assertThat(() -> Uni.createFrom().item("foo"), foo -> assertEquals("bar", foo)));
}

@Test
public void testFail() {
testAsserterFailure(ua -> ua.fail(), t -> AssertionFailedError.class.isInstance(t));
}

@Test
public void testExecute() throws InterruptedException, ExecutionException {
CompletableFuture<Object> cf = new CompletableFuture<>();
Expand Down Expand Up @@ -238,7 +244,7 @@ private void testAsserterFailure(Consumer<UniAsserter> assertion, Predicate<Thro
fail("No failure");
} catch (ExecutionException e) {
if (expected != null) {
assertTrue(expected.test(e.getCause()));
assertTrue(expected.test(e.getCause()), "Unexpected exception thrown: " + e.getCause());
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit 404e820

Please sign in to comment.