forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue2107.java
More file actions
70 lines (57 loc) · 2.42 KB
/
Copy pathIssue2107.java
File metadata and controls
70 lines (57 loc) · 2.42 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
package io.jooby;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import io.jooby.exception.StartupException;
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class Issue2107 {
@Test
public void appInitExceptionLogging() {
Logger log = (Logger) LoggerFactory.getLogger(Jooby.class);
ListAppender<ILoggingEvent> appender = new ListAppender<>();
appender.start();
log.addAppender(appender);
Throwable t = assertThrows(StartupException.class, () -> Jooby.runApp(new String[0], AppWithRuntimeException::new));
assertEquals("Application initialization resulted in exception", t.getMessage());
assertNotNull(t.getCause());
assertTrue(t.getCause() instanceof RuntimeException);
assertEquals("meh", t.getCause().getMessage());
assertEquals(1, appender.list.size());
final ILoggingEvent ev = appender.list.get(0);
assertEquals(Level.ERROR, ev.getLevel());
assertEquals("Application initialization resulted in exception", ev.getMessage());
assertEquals("meh", ev.getThrowableProxy().getMessage());
}
@Test
public void noMatryoshkaExceptionsPlease() {
Logger log = (Logger) LoggerFactory.getLogger(Jooby.class);
ListAppender<ILoggingEvent> appender = new ListAppender<>();
appender.start();
log.addAppender(appender);
Throwable t = assertThrows(StartupException.class, () -> Jooby.runApp(new String[0], AppWithStartupException::new));
assertEquals("meh", t.getMessage());
assertNull(t.getCause());
assertEquals(1, appender.list.size());
final ILoggingEvent ev = appender.list.get(0);
assertEquals(Level.ERROR, ev.getLevel());
assertEquals("Application initialization resulted in exception", ev.getMessage());
assertEquals("meh", ev.getThrowableProxy().getMessage());
}
static class AppWithRuntimeException extends Jooby {
{
if (true) throw new RuntimeException("meh");
}
}
static class AppWithStartupException extends Jooby {
{
if (true) throw new StartupException("meh");
}
}
}