Class UniAsserterInterceptor
- All Implemented Interfaces:
UniAsserter,UnwrappableUniAsserter
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());
}
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> UniAsserterassertEquals(Supplier<io.smallrye.mutiny.Uni<T>> uni, T t) Assert that the value of theUniis equal to the expected value.<T> UniAsserterassertFailedWith(Supplier<io.smallrye.mutiny.Uni<T>> uni, Class<? extends Throwable> c) Used to determine whether theUnicontains the expected failure type.<T> UniAsserterassertFailedWith(Supplier<io.smallrye.mutiny.Uni<T>> uni, Consumer<Throwable> c) Used to determine whether theUnicontains the expected failure.assertFalse(Supplier<io.smallrye.mutiny.Uni<Boolean>> uni) Assert that the value of theUniisfalse.<T> UniAsserterassertNotEquals(Supplier<io.smallrye.mutiny.Uni<T>> uni, T t) Assert that the value of theUniis not equal to the expected value.<T> UniAsserterassertNotNull(Supplier<io.smallrye.mutiny.Uni<T>> uni) Assert that the value of theUniis notnull.<T> UniAsserterassertNotSame(Supplier<io.smallrye.mutiny.Uni<T>> uni, T t) Assert that the value of theUniand the expected value do not refer to the same object.<T> UniAsserterassertNull(Supplier<io.smallrye.mutiny.Uni<T>> uni) Assert that the value of theUniisnull.<T> UniAsserterassertSame(Supplier<io.smallrye.mutiny.Uni<T>> uni, T t) Assert that the value of theUniand the expected value refer to the same object.<T> UniAsserterassertThat(Supplier<io.smallrye.mutiny.Uni<T>> uni, Consumer<T> asserter) Perform a custom assertion on the value of theUniin cases where no exception was thrown.assertTrue(Supplier<io.smallrye.mutiny.Uni<Boolean>> uni) Assert that the value of theUniistrue.io.smallrye.mutiny.Uni<?>asUni()voidClear the test data.Execute some arbitrary operation as part of the pipeline.<T> UniAsserterExecute some arbitrary operation as part of the pipeline.fail()Ensure that the whole pipeline always failsAssociate the value with the given key.<T> UniAssertersurroundWith(Function<io.smallrye.mutiny.Uni<T>, io.smallrye.mutiny.Uni<T>> uni) protected <T> Supplier<io.smallrye.mutiny.Uni<T>>transformUni(Supplier<io.smallrye.mutiny.Uni<T>> uniSupplier) This method can be used to transform the providedUnisupplier for assertion methods andUniAsserter.execute(Supplier).
-
Constructor Details
-
UniAsserterInterceptor
-
-
Method Details
-
transformUni
protected <T> Supplier<io.smallrye.mutiny.Uni<T>> transformUni(Supplier<io.smallrye.mutiny.Uni<T>> uniSupplier) This method can be used to transform the providedUnisupplier for assertion methods andUniAsserter.execute(Supplier).- Type Parameters:
T-- Parameters:
uniSupplier-- Returns:
-
assertThat
Description copied from interface:UniAsserterPerform a custom assertion on the value of theUniin cases where no exception was thrown.If an exception is expected, then one of
UniAsserter.assertFailedWith(java.util.function.Supplier<io.smallrye.mutiny.Uni<T>>, java.util.function.Consumer<java.lang.Throwable>)methods should be used.- Specified by:
assertThatin interfaceUniAsserter
-
execute
Description copied from interface:UniAsserterExecute some arbitrary operation as part of the pipeline.- Specified by:
executein interfaceUniAsserter
-
execute
Description copied from interface:UniAsserterExecute some arbitrary operation as part of the pipeline.- Specified by:
executein interfaceUniAsserter
-
assertEquals
Description copied from interface:UniAsserterAssert that the value of theUniis equal to the expected value. If both arenull, they are considered equal.- Specified by:
assertEqualsin interfaceUniAsserter- See Also:
-
assertNotEquals
Description copied from interface:UniAsserterAssert that the value of theUniis not equal to the expected value. Fails if both arenull.- Specified by:
assertNotEqualsin interfaceUniAsserter- See Also:
-
assertSame
Description copied from interface:UniAsserterAssert that the value of theUniand the expected value refer to the same object.- Specified by:
assertSamein interfaceUniAsserter
-
assertNotSame
Description copied from interface:UniAsserterAssert that the value of theUniand the expected value do not refer to the same object.- Specified by:
assertNotSamein interfaceUniAsserter
-
assertNull
Description copied from interface:UniAsserterAssert that the value of theUniisnull.If an exception is expected, then one of
UniAsserter.assertFailedWith(java.util.function.Supplier<io.smallrye.mutiny.Uni<T>>, java.util.function.Consumer<java.lang.Throwable>)methods should be used.- Specified by:
assertNullin interfaceUniAsserter
-
assertNotNull
Description copied from interface:UniAsserterAssert that the value of theUniis notnull.If an exception is expected, then one of
UniAsserter.assertFailedWith(java.util.function.Supplier<io.smallrye.mutiny.Uni<T>>, java.util.function.Consumer<java.lang.Throwable>)methods should be used.- Specified by:
assertNotNullin interfaceUniAsserter
-
surroundWith
public <T> UniAsserter surroundWith(Function<io.smallrye.mutiny.Uni<T>, io.smallrye.mutiny.Uni<T>> uni) - Specified by:
surroundWithin interfaceUniAsserter
-
fail
Description copied from interface:UniAsserterEnsure that the whole pipeline always fails- Specified by:
failin interfaceUniAsserter
-
assertTrue
Description copied from interface:UniAsserterAssert that the value of theUniistrue.- Specified by:
assertTruein interfaceUniAsserter
-
assertFalse
Description copied from interface:UniAsserterAssert that the value of theUniisfalse.- Specified by:
assertFalsein interfaceUniAsserter
-
assertFailedWith
public <T> UniAsserter assertFailedWith(Supplier<io.smallrye.mutiny.Uni<T>> uni, Consumer<Throwable> c) Description copied from interface:UniAsserterUsed to determine whether theUnicontains the expected failure. The assertions fail if theUnidoes not fail.- Specified by:
assertFailedWithin interfaceUniAsserterc- Consumer that performs custom assertions on whether the failure matches expectations. This allows asserting on anything present in theThrowablelike, the cause or the message
-
assertFailedWith
public <T> UniAsserter assertFailedWith(Supplier<io.smallrye.mutiny.Uni<T>> uni, Class<? extends Throwable> c) Description copied from interface:UniAsserterUsed to determine whether theUnicontains the expected failure type. The assertions fail if theUnidoes not fail.- Specified by:
assertFailedWithin interfaceUniAsserter
-
getData
- Specified by:
getDatain interfaceUniAsserter- Returns:
- the test data associated with the given key, or
null - See Also:
-
putData
Description copied from interface:UniAsserterAssociate the value with the given key.- Specified by:
putDatain interfaceUniAsserter- Returns:
- the previous value, or
nullif there was no data for the given key
-
clearData
public void clearData()Description copied from interface:UniAsserterClear the test data.- Specified by:
clearDatain interfaceUniAsserter
-
asUni
public io.smallrye.mutiny.Uni<?> asUni()- Specified by:
asUniin interfaceUnwrappableUniAsserter- Returns:
- a
Unirepresenting the operations pipeline up to this point
-