This is an automated email from the ASF dual-hosted git repository.
vaughn pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-hugegraph-commons.git
The following commit(s) were added to refs/heads/master by this push:
new 589ee2c support assert-throws return future (#102)
589ee2c is described below
commit 589ee2ca10d97f36f3f3ccd1e00b538268489a55
Author: Jermy Li <[email protected]>
AuthorDate: Fri May 27 14:19:10 2022 +0800
support assert-throws return future (#102)
Change-Id: I8fe115a7518dd84e22c9e28f777515e74e48d5d2
---
.../java/com/baidu/hugegraph/testutil/Assert.java | 27 ++++++++++++++++------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git
a/hugegraph-common/src/main/java/com/baidu/hugegraph/testutil/Assert.java
b/hugegraph-common/src/main/java/com/baidu/hugegraph/testutil/Assert.java
index 537e9d6..333002d 100644
--- a/hugegraph-common/src/main/java/com/baidu/hugegraph/testutil/Assert.java
+++ b/hugegraph-common/src/main/java/com/baidu/hugegraph/testutil/Assert.java
@@ -19,6 +19,7 @@
package com.baidu.hugegraph.testutil;
+import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -40,7 +41,8 @@ public class Assert extends org.junit.Assert {
public static void assertThrows(Class<? extends Throwable> throwable,
ThrowableRunnable runnable) {
- assertThrows(throwable, runnable, e -> {
+ CompletableFuture<?> future = assertThrowsFuture(throwable, runnable);
+ future.thenAccept(e -> {
System.err.println(e);
});
}
@@ -48,23 +50,34 @@ public class Assert extends org.junit.Assert {
public static void assertThrows(Class<? extends Throwable> throwable,
ThrowableRunnable runnable,
Consumer<Throwable> exceptionConsumer) {
+ CompletableFuture<Throwable> future = assertThrowsFuture(throwable,
+ runnable);
+ future.thenAccept(exceptionConsumer);
+ }
+
+ public static CompletableFuture<Throwable> assertThrowsFuture(
+ Class<? extends Throwable>
clazz,
+ ThrowableRunnable runnable) {
+ CompletableFuture<Throwable> future = new CompletableFuture<>();
boolean fail = false;
try {
runnable.run();
fail = true;
} catch (Throwable e) {
- if (!throwable.isInstance(e)) {
+ if (!clazz.isInstance(e)) {
Assert.fail(String.format(
"Bad exception type %s(expected %s)",
- e.getClass().getName(), throwable.getName()));
+ e.getClass().getName(), clazz.getName()));
}
- exceptionConsumer.accept(e);
+ future.complete(e);
}
if (fail) {
- Assert.fail(String.format(
- "No exception was thrown(expected %s)",
- throwable.getName()));
+ String msg = String.format("No exception was thrown(expected %s)",
+ clazz.getName());
+ future.completeExceptionally(new AssertionError(msg));
+ Assert.fail(msg);
}
+ return future;
}
public static void assertEquals(byte expected, Object actual) {