Class UniAsserterInterceptor

java.lang.Object
io.quarkus.test.vertx.UniAsserterInterceptor
All Implemented Interfaces:
UniAsserter, UnwrappableUniAsserter

public abstract class UniAsserterInterceptor extends Object implements UnwrappableUniAsserter
A subclass can be used to wrap the injected UniAsserter and customize the default behavior.

Specifically, it can intercept selected methods and perform some additional logic. The transformUni(Supplier) method can be used to transform the provided Uni supplier for assertion and UniAsserter.execute(Supplier) methods.

For example, it can be used to perform all assertions within the scope of a database transaction:

 @QuarkusTest
 public class SomeTest {

     static class TransactionalUniAsserterInterceptor extends UniAsserterInterceptor {

         public TransactionUniAsserterInterceptor(UniAsserter asserter){
         super(asserter);
         }

         @Override
         protected <T> Supplier<Uni<T>> transformUni(Supplier<Uni<T>> uniSupplier) {
             // Assert/execute methods are invoked within a database transaction
             return () -> Panache.withTransaction(uniSupplier);
         }
     }

     @Test
     @RunOnVertxContext
     public void testEntity(UniAsserter asserter) {
         asserter = new TransactionalUniAsserterInterceptor(asserter);
         asserter.execute(() -> new MyEntity().persist());
         asserter.assertEquals(() -> MyEntity.count(), 1l);
         asserter.execute(() -> MyEntity.deleteAll());
     }
 }
 
Alternatively, an anonymous class can be used as well:
 @QuarkusTest
 public class SomeTest {

     @Test
     @RunOnVertxContext
     public void testEntity(UniAsserter asserter) {
         asserter = new UniAsserterInterceptor(asserter) {
             @Override
             protected <T> Supplier<Uni<T>> transformUni(Supplier<Uni<T>> uniSupplier) {
                 return () -> Panache.withTransaction(uniSupplier);
             }
         };
         asserter.execute(() -> new MyEntity().persist());
         asserter.assertEquals(() -> MyEntity.count(), 1l);
         asserter.execute(() -> MyEntity.deleteAll());
     }
 }