Skip to content

Commit 5ddc8e5

Browse files
committed
[#36582] Fix bug: TransactionalUniAsserter never fails
TransactionalUniAsserterTestMethodInvoker is a subclass of RunOnVertxContextTestMethodInvoker. The problem is that there were two separate pointers keeping track of the asserter in the superclass and in the subclass. This lead to only one pointer being initialized and, if the wrong pointer was null-checked, the asserter was ignored causing the test to never fail. This commit fixes the issue by keeping only one reference to the asserter in the superclass.
1 parent 0ffedc5 commit 5ddc8e5

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

test-framework/hibernate-reactive-panache/src/main/java/io/quarkus/test/hibernate/reactive/panache/TransactionalUniAsserterTestMethodInvoker.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,14 @@
88

99
public class TransactionalUniAsserterTestMethodInvoker extends RunOnVertxContextTestMethodInvoker {
1010

11-
private UniAsserter uniAsserter;
12-
1311
@Override
1412
public boolean handlesMethodParamType(String paramClassName) {
1513
return TransactionalUniAsserter.class.getName().equals(paramClassName);
1614
}
1715

1816
@Override
19-
public Object methodParamInstance(String paramClassName) {
20-
if (!handlesMethodParamType(paramClassName)) {
21-
throw new IllegalStateException(
22-
"TransactionalUniAsserterTestMethodInvoker does not handle '" + paramClassName + "' method param types");
23-
}
24-
uniAsserter = new TransactionalUniAsserter(new DefaultUniAsserter());
25-
return uniAsserter;
17+
protected UniAsserter createUniAsserter() {
18+
return new TransactionalUniAsserter(new DefaultUniAsserter());
2619
}
2720

2821
@Override

test-framework/vertx/src/main/java/io/quarkus/test/vertx/DefaultUniAsserter.java

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public DefaultUniAsserter() {
2222
this.data = new ConcurrentHashMap<>();
2323
}
2424

25+
@Override
26+
public Uni<?> asUni() {
27+
return execution;
28+
}
29+
2530
@SuppressWarnings("unchecked")
2631
@Override
2732
public <T> UniAsserter assertThat(Supplier<Uni<T>> uni, Consumer<T> asserter) {

test-framework/vertx/src/main/java/io/quarkus/test/vertx/RunOnVertxContextTestMethodInvoker.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
public class RunOnVertxContextTestMethodInvoker implements TestMethodInvoker {
2323

24-
private DefaultUniAsserter uniAsserter;
24+
private UniAsserter uniAsserter;
2525

2626
@Override
2727
public boolean handlesMethodParamType(String paramClassName) {
@@ -32,12 +32,16 @@ public boolean handlesMethodParamType(String paramClassName) {
3232
public Object methodParamInstance(String paramClassName) {
3333
if (!handlesMethodParamType(paramClassName)) {
3434
throw new IllegalStateException(
35-
"RunOnVertxContextTestMethodInvoker does not handle '" + paramClassName + "' method param types");
35+
this.getClass().getName() + " does not handle '" + paramClassName + "' method param types");
3636
}
37-
uniAsserter = new DefaultUniAsserter();
37+
uniAsserter = createUniAsserter();
3838
return uniAsserter;
3939
}
4040

41+
protected UniAsserter createUniAsserter() {
42+
return new DefaultUniAsserter();
43+
}
44+
4145
@Override
4246
public boolean supportsMethod(Class<?> originalTestClass, Method originalTestMethod) {
4347
return hasSupportedAnnotation(originalTestClass, originalTestMethod)
@@ -152,11 +156,11 @@ public void run() {
152156
private final Object testInstance;
153157
private final Method targetMethod;
154158
private final List<Object> methodArgs;
155-
private final DefaultUniAsserter uniAsserter;
159+
private final UniAsserter uniAsserter;
156160
private final CompletableFuture<Object> future;
157161

158162
public RunTestMethodOnVertxEventLoopContextHandler(Object testInstance, Method targetMethod, List<Object> methodArgs,
159-
DefaultUniAsserter uniAsserter, CompletableFuture<Object> future) {
163+
UniAsserter uniAsserter, CompletableFuture<Object> future) {
160164
this.testInstance = testInstance;
161165
this.future = future;
162166
this.targetMethod = targetMethod;
@@ -184,7 +188,7 @@ private void doRun(Runnable onTerminate) {
184188
try {
185189
Object testMethodResult = targetMethod.invoke(testInstance, methodArgs.toArray(new Object[0]));
186190
if (uniAsserter != null) {
187-
uniAsserter.execution.subscribe().with(new Consumer<Object>() {
191+
uniAsserter.asUni().subscribe().with(new Consumer<Object>() {
188192
@Override
189193
public void accept(Object o) {
190194
onTerminate.run();
@@ -209,19 +213,16 @@ public void accept(Throwable t) {
209213
}
210214

211215
public static class RunTestMethodOnVertxBlockingContextHandler implements Handler<Promise<Object>> {
212-
private static final Runnable DO_NOTHING = new Runnable() {
213-
@Override
214-
public void run() {
215-
}
216+
private static final Runnable DO_NOTHING = () -> {
216217
};
217218

218219
private final Object testInstance;
219220
private final Method targetMethod;
220221
private final List<Object> methodArgs;
221-
private final DefaultUniAsserter uniAsserter;
222+
private final UniAsserter uniAsserter;
222223

223224
public RunTestMethodOnVertxBlockingContextHandler(Object testInstance, Method targetMethod, List<Object> methodArgs,
224-
DefaultUniAsserter uniAsserter) {
225+
UniAsserter uniAsserter) {
225226
this.testInstance = testInstance;
226227
this.targetMethod = targetMethod;
227228
this.methodArgs = methodArgs;
@@ -248,7 +249,7 @@ private void doRun(Promise<Object> promise, Runnable onTerminate) {
248249
try {
249250
Object testMethodResult = targetMethod.invoke(testInstance, methodArgs.toArray(new Object[0]));
250251
if (uniAsserter != null) {
251-
uniAsserter.execution.subscribe().with(new Consumer<Object>() {
252+
uniAsserter.asUni().subscribe().with(new Consumer<Object>() {
252253
@Override
253254
public void accept(Object o) {
254255
onTerminate.run();

test-framework/vertx/src/main/java/io/quarkus/test/vertx/UniAsserter.java

+5
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,9 @@ public interface UniAsserter {
144144
* Clear the test data.
145145
*/
146146
void clearData();
147+
148+
/**
149+
* @return a {@link Uni} representing the operations pipeline up to this point
150+
*/
151+
Uni<?> asUni();
147152
}

test-framework/vertx/src/main/java/io/quarkus/test/vertx/UniAsserterInterceptor.java

+4
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,8 @@ public void clearData() {
190190
delegate.clearData();
191191
}
192192

193+
@Override
194+
public Uni<?> asUni() {
195+
return delegate.asUni();
196+
}
193197
}

0 commit comments

Comments
 (0)