forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue2452.java
More file actions
42 lines (35 loc) · 1.11 KB
/
Copy pathIssue2452.java
File metadata and controls
42 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package io.jooby.i2452;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.concurrent.CompletableFuture;
import org.jetbrains.annotations.NotNull;
import io.jooby.Context;
import io.jooby.ErrorHandler;
import io.jooby.StatusCode;
import io.jooby.WebClient;
import io.jooby.exception.StatusCodeException;
import io.jooby.junit.ServerTest;
import io.jooby.junit.ServerTestRunner;
public class Issue2452 {
@ServerTest
public void shouldHandleCompletableFutureError(ServerTestRunner runner) {
runner.define(app -> {
app.get("/2452", ctx -> CompletableFuture.supplyAsync(
() -> {
throw new StatusCodeException(StatusCode.NOT_FOUND);
}
));
app.error((ctx, cause, code) -> {
ctx.setResponseCode(code);
ctx.send(cause.getClass().getSimpleName());
});
}).ready((WebClient http) -> {
http
.get("/2452", rsp -> {
assertEquals("StatusCodeException",
rsp.body().string());
assertEquals(StatusCode.NOT_FOUND.value(),
rsp.code());
});
});
}
}