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 injectedUniAsserterand 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 providedUnisupplier for assertion andUniAsserter.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 Constructor Description UniAsserterInterceptor(UniAsserter asserter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <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.UniAsserterassertFalse(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.UniAsserterassertTrue(Supplier<io.smallrye.mutiny.Uni<Boolean>> uni)Assert that the value of theUniistrue.io.smallrye.mutiny.Uni<?>asUni()voidclearData()Clear the test data.UniAsserterexecute(Runnable c)Execute some arbitrary operation as part of the pipeline.<T> UniAsserterexecute(Supplier<io.smallrye.mutiny.Uni<T>> uni)Execute some arbitrary operation as part of the pipeline.UniAsserterfail()Ensure that the whole pipeline always failsObjectgetData(String key)ObjectputData(String key, Object value)Associate 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 Detail
-
UniAsserterInterceptor
public UniAsserterInterceptor(UniAsserter asserter)
-
-
Method Detail
-
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
public <T> UniAsserter assertThat(Supplier<io.smallrye.mutiny.Uni<T>> uni, Consumer<T> asserter)
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
public <T> UniAsserter execute(Supplier<io.smallrye.mutiny.Uni<T>> uni)
Description copied from interface:UniAsserterExecute some arbitrary operation as part of the pipeline.- Specified by:
executein interfaceUniAsserter
-
execute
public UniAsserter execute(Runnable c)
Description copied from interface:UniAsserterExecute some arbitrary operation as part of the pipeline.- Specified by:
executein interfaceUniAsserter
-
assertEquals
public <T> UniAsserter assertEquals(Supplier<io.smallrye.mutiny.Uni<T>> uni, T t)
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:
Object.equals(Object)
-
assertNotEquals
public <T> UniAsserter assertNotEquals(Supplier<io.smallrye.mutiny.Uni<T>> uni, T t)
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:
Object.equals(Object)
-
assertSame
public <T> UniAsserter assertSame(Supplier<io.smallrye.mutiny.Uni<T>> uni, T t)
Description copied from interface:UniAsserterAssert that the value of theUniand the expected value refer to the same object.- Specified by:
assertSamein interfaceUniAsserter
-
assertNotSame
public <T> UniAsserter assertNotSame(Supplier<io.smallrye.mutiny.Uni<T>> uni, T t)
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
public <T> UniAsserter assertNull(Supplier<io.smallrye.mutiny.Uni<T>> uni)
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
public <T> UniAsserter assertNotNull(Supplier<io.smallrye.mutiny.Uni<T>> uni)
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
public UniAsserter fail()
Description copied from interface:UniAsserterEnsure that the whole pipeline always fails- Specified by:
failin interfaceUniAsserter
-
assertTrue
public UniAsserter assertTrue(Supplier<io.smallrye.mutiny.Uni<Boolean>> uni)
Description copied from interface:UniAsserterAssert that the value of theUniistrue.- Specified by:
assertTruein interfaceUniAsserter
-
assertFalse
public UniAsserter assertFalse(Supplier<io.smallrye.mutiny.Uni<Boolean>> uni)
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
public Object getData(String key)
- Specified by:
getDatain interfaceUniAsserter- Returns:
- the test data associated with the given key, or
null - See Also:
UniAsserter.putData(String, Object)
-
putData
public Object putData(String key, Object value)
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
-
-