forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue2539.java
More file actions
91 lines (70 loc) · 2.01 KB
/
Copy pathIssue2539.java
File metadata and controls
91 lines (70 loc) · 2.01 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package io.jooby.i2539;
import static org.junit.jupiter.api.Assertions.assertEquals;
import io.jooby.Jooby;
import io.jooby.junit.ServerTest;
import io.jooby.junit.ServerTestRunner;
public class Issue2539 {
static class AppA extends Jooby {
{
get("/throwsGeneric", ctx -> {
throw new IllegalStateException(ctx.getRequestPath());
});
get("/throwsA", ctx -> {
throw new ExceptionA();
});
error(ExceptionA.class, (ctx, cause, code) -> {
ctx.send("exception A was thrown");
});
}
}
static class AppB extends Jooby {
{
get("/throwsB", ctx -> {
throw new ExceptionB();
});
// THIS DOES NOT WORK!!!!
error(ExceptionB.class, (ctx, cause, code) -> {
ctx.send("exception B was thrown");
});
}
}
static class ExceptionA extends RuntimeException {
}
static class ExceptionB extends RuntimeException {
}
static class ExceptionRoot extends RuntimeException {
}
@ServerTest
public void shouldErrorHandlerWorkForMountedResources(ServerTestRunner runner) {
runner.define(app -> {
app.get("/2539", ctx -> {
throw new ExceptionRoot();
});
app.mount(new AppA());
app.mount(new AppB());
app.error(ExceptionRoot.class, (ctx, cause, code) -> {
ctx.send("exception Root was thrown");
});
app.error((ctx, cause, code) -> {
ctx.send("exception was thrown");
});
}).ready(http -> {
http
.get("/2539", rsp -> {
assertEquals("exception Root was thrown", rsp.body().string());
});
http
.get("/throwsGeneric", rsp -> {
assertEquals("exception was thrown", rsp.body().string());
});
http
.get("/throwsA", rsp -> {
assertEquals("exception A was thrown", rsp.body().string());
});
http
.get("/throwsB", rsp -> {
assertEquals("exception B was thrown", rsp.body().string());
});
});
}
}