-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UniAsserter - introduce UniAsserterInterceptor
- Loading branch information
Showing
2 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
test-framework/vertx/src/main/java/io/quarkus/test/vertx/UniAsserterInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package io.quarkus.test.vertx; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
/** | ||
* Makes it possible to intercept the methods of an injected {@link UniAsserter} and perform some additional logic. | ||
* <p> | ||
* The {@link #transformUni(Supplier)} method can be used to transform the provided {@link Uni} supplier for assertion and | ||
* {@link UniAsserter#execute(Supplier)} methods. For example, it can be used to perform all assertions within the scope of a | ||
* database transaction. | ||
*/ | ||
public abstract class UniAsserterInterceptor implements UniAsserter { | ||
|
||
private final UniAsserter delegate; | ||
|
||
public UniAsserterInterceptor(UniAsserter asserter) { | ||
this.delegate = asserter; | ||
} | ||
|
||
/** | ||
* This method can be used to transform the provided {@link Uni} supplier for assertion methods and | ||
* {@link UniAsserter#execute(Supplier)}. | ||
* | ||
* @param <T> | ||
* @param uniSupplier | ||
* @return | ||
*/ | ||
protected <T> Supplier<Uni<T>> transformUni(Supplier<Uni<T>> uniSupplier) { | ||
return uniSupplier; | ||
} | ||
|
||
@Override | ||
public <T> UniAsserter assertThat(Supplier<Uni<T>> uni, Consumer<T> asserter) { | ||
delegate.assertThat(transformUni(uni), asserter); | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> UniAsserter execute(Supplier<Uni<T>> uni) { | ||
delegate.execute(transformUni(uni)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public UniAsserter execute(Runnable c) { | ||
delegate.execute(c); | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> UniAsserter assertEquals(Supplier<Uni<T>> uni, T t) { | ||
delegate.assertEquals(transformUni(uni), t); | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> UniAsserter assertNotEquals(Supplier<Uni<T>> uni, T t) { | ||
delegate.assertNotEquals(transformUni(uni), t); | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> UniAsserter assertSame(Supplier<Uni<T>> uni, T t) { | ||
delegate.assertSame(transformUni(uni), t); | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> UniAsserter assertNotSame(Supplier<Uni<T>> uni, T t) { | ||
delegate.assertNotSame(transformUni(uni), t); | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> UniAsserter assertNull(Supplier<Uni<T>> uni) { | ||
delegate.assertNull(transformUni(uni)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> UniAsserter assertNotNull(Supplier<Uni<T>> uni) { | ||
delegate.assertNotNull(transformUni(uni)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> UniAsserter surroundWith(Function<Uni<T>, Uni<T>> uni) { | ||
delegate.surroundWith(uni); | ||
return this; | ||
} | ||
|
||
@Override | ||
public UniAsserter fail() { | ||
delegate.fail(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public UniAsserter assertTrue(Supplier<Uni<Boolean>> uni) { | ||
delegate.assertTrue(transformUni(uni)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public UniAsserter assertFalse(Supplier<Uni<Boolean>> uni) { | ||
delegate.assertFalse(transformUni(uni)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> UniAsserter assertFailedWith(Supplier<Uni<T>> uni, Consumer<Throwable> c) { | ||
delegate.assertFailedWith(transformUni(uni), c); | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> UniAsserter assertFailedWith(Supplier<Uni<T>> uni, Class<? extends Throwable> c) { | ||
delegate.assertFailedWith(transformUni(uni), c); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Object getData(String key) { | ||
return delegate.getData(key); | ||
} | ||
|
||
@Override | ||
public Object putData(String key, Object value) { | ||
return delegate.putData(key, value); | ||
} | ||
|
||
@Override | ||
public void clearData() { | ||
delegate.clearData(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters