Skip to content

Commit dd74f8e

Browse files
committed
build: reduce log
1 parent 29f9ce7 commit dd74f8e

File tree

7 files changed

+45
-21
lines changed

7 files changed

+45
-21
lines changed

modules/jooby-apt/src/test/java/io/jooby/apt/ProcessorRunner.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,17 @@ public ProcessorRunner(Object instance) throws IOException {
9999
this(instance, Map.of());
100100
}
101101

102+
public ProcessorRunner(Object instance, Consumer<String> stdout) throws IOException {
103+
this(instance, stdout, Map.of());
104+
}
105+
102106
public ProcessorRunner(Object instance, Map<String, Object> options) throws IOException {
103-
this.processor = new HookJoobyProcessor(System.out::println);
107+
this(instance, System.out::println, options);
108+
}
109+
110+
public ProcessorRunner(Object instance, Consumer<String> stdout, Map<String, Object> options)
111+
throws IOException {
112+
this.processor = new HookJoobyProcessor(stdout::accept);
104113
var optionsArray =
105114
options.entrySet().stream().map(e -> "-A" + e.getKey() + "=" + e.getValue()).toList();
106115
Truth.assert_()

modules/jooby-apt/src/test/java/tests/verifyarg/VerifyArgTypeTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ class VerifyArgTypeTest {
2121
@ParameterizedTest
2222
@MethodSource("provideControllers")
2323
public void compileController_illegalArgumentType_shouldThrowException(Object controller) {
24-
RuntimeException ex =
25-
assertThrows(RuntimeException.class, () -> new ProcessorRunner(controller));
24+
var ex =
25+
assertThrows(
26+
RuntimeException.class,
27+
() ->
28+
new ProcessorRunner(
29+
controller,
30+
error -> {
31+
// NOOP
32+
}));
2633

2734
assertTrue(ex.getMessage().contains("Illegal argument type at"));
2835
}

modules/jooby-test/src/test/java/io/jooby/test/TestApp.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
*/
66
package io.jooby.test;
77

8+
import java.util.List;
9+
810
import io.jooby.Jooby;
911
import io.jooby.RouterOption;
12+
import io.jooby.StartupSummary;
1013

1114
public class TestApp extends Jooby {
1215
{
16+
setStartupSummary(List.of(StartupSummary.NONE));
1317
setRouterOptions(RouterOption.IGNORE_CASE, RouterOption.IGNORE_TRAILING_SLASH);
1418
setContextPath("/test");
1519
get("/", ctx -> "OK");

modules/jooby-test/src/test/java/io/jooby/test/TestArgApp.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
*/
66
package io.jooby.test;
77

8+
import java.util.List;
9+
810
import io.jooby.Jooby;
11+
import io.jooby.StartupSummary;
912

1013
public class TestArgApp extends Jooby {
1114
public TestArgApp(String name) {
15+
setStartupSummary(List.of(StartupSummary.NONE));
1216
get("/", ctx -> name);
1317
}
1418
}

tests/src/test/java/io/jooby/junit/ServerTestRunner.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,9 @@ public void ready(SneakyThrows.Consumer2<WebClient, WebClient> onReady) {
100100
if (mavenBuild) {
101101
applogger = app.getClass().getName();
102102
app.setStartupSummary(List.of(StartupSummary.NONE));
103-
if (app.getErrorHandler() == null) {
104-
app.error(
105-
new DefaultErrorHandler() {
106-
@Override
107-
protected void log(Context ctx, Throwable cause, StatusCode code) {
108-
app.getLog()
109-
.info(ErrorHandler.errorMessage(ctx, code) + ": " + cause.getMessage());
110-
}
111-
});
112-
}
103+
app.error(
104+
Optional.ofNullable(app.getErrorHandler())
105+
.orElseGet(ServerTestRunner::buildErrorHandler));
113106
}
114107

115108
ServerOptions serverOptions = app.getServerOptions();
@@ -154,6 +147,18 @@ protected void log(Context ctx, Throwable cause, StatusCode code) {
154147
}
155148
}
156149

150+
private static DefaultErrorHandler buildErrorHandler() {
151+
return new DefaultErrorHandler() {
152+
@Override
153+
protected void log(Context ctx, Throwable cause, StatusCode code) {
154+
ctx.getRouter()
155+
.getLog()
156+
.info(ErrorHandler.errorMessage(ctx, code) + ": " + cause.getMessage());
157+
ctx.getRouter().getLog().debug(ErrorHandler.errorMessage(ctx, code), cause.getMessage());
158+
}
159+
};
160+
}
161+
157162
private boolean disabled() {
158163
var osname = System.getProperty("os.name").toLowerCase();
159164
var osarch = System.getProperty("os.arch").toLowerCase();

tests/src/test/java/io/jooby/problem/data/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public class App extends Jooby {
120120
get(
121121
"/throw-illegal-state-exception",
122122
ctx -> {
123-
throw new IllegalStateException();
123+
throw new IllegalStateException("expected error");
124124
});
125125

126126
get(

tests/src/test/java/io/jooby/test/Issue1349.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.jooby.test;
77

88
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.junit.jupiter.api.Assertions.assertTrue;
910

1011
import io.jooby.Jooby;
1112
import io.jooby.StatusCode;
@@ -17,12 +18,6 @@ public class Issue1349 {
1718

1819
public static class App1349 extends Jooby {
1920
{
20-
error(
21-
IllegalAccessException.class,
22-
((ctx, cause, statusCode) -> {
23-
ctx.setResponseCode(statusCode);
24-
ctx.send(cause.getMessage());
25-
}));
2621
get("/1349", ctx -> something());
2722
get("/1349/iae", ctx -> throwsIAE());
2823
}
@@ -51,7 +46,7 @@ public void issue1349(ServerTestRunner runner) {
5146
"/1349/iae",
5247
rsp -> {
5348
assertEquals(500, rsp.code());
54-
assertEquals("no-access", rsp.body().string());
49+
assertTrue(rsp.body().string().contains("message: no-access"));
5550
});
5651
});
5752
}

0 commit comments

Comments
 (0)