Skip to content

Commit f0cfa18

Browse files
support Problem Details handler in the MockRouter
1 parent 639a0a7 commit f0cfa18

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

modules/jooby-test/src/main/java/io/jooby/test/MockRouter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.jooby.Router;
1919
import io.jooby.SneakyThrows;
2020
import io.jooby.WebSocket;
21+
import io.jooby.problem.ProblemDetailsHandler;
2122

2223
/**
2324
* Utility class that allows us to execute routes using a {@link MockContext}.
@@ -74,6 +75,9 @@ public Object value() {
7475
* @param application Source application.
7576
*/
7677
public MockRouter(@NonNull Jooby application) {
78+
if (application.problemDetailsIsEnabled()) {
79+
application.error(ProblemDetailsHandler.from(application.getConfig()));
80+
}
7781
this.supplier = () -> application;
7882
}
7983

tests/src/test/java/io/jooby/i3787/Application.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
package io.jooby.i3787;
22

3+
import com.typesafe.config.Config;
4+
import com.typesafe.config.ConfigFactory;
35
import io.jooby.Jooby;
46
import io.jooby.problem.HttpProblem;
57

8+
import java.util.Map;
9+
610
class Application extends Jooby {
711
{
12+
Config problemDetailsConfig = ConfigFactory.parseMap(
13+
Map.of("problem.details.enabled", true)
14+
);
15+
getEnvironment().setConfig(problemDetailsConfig.withFallback(getConfig()));
16+
817
get("/throw", ctx -> {
918
throw new CustomException();
1019
});
@@ -19,5 +28,6 @@ public static void main(String[] args) {
1928
runApp(args, Application::new);
2029
}
2130

22-
static class CustomException extends RuntimeException {}
31+
static class CustomException extends RuntimeException {
32+
}
2333
}

0 commit comments

Comments
 (0)