Skip to content

Commit 58b7f6e

Browse files
committed
more unit tests/test coverage
1 parent 025ab2e commit 58b7f6e

File tree

4 files changed

+89
-7
lines changed

4 files changed

+89
-7
lines changed

jooby/src/main/java/org/jooby/Jooby.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4070,13 +4070,8 @@ public void stop() {
40704070
private static void fireStop(final Injector injector, final Jooby app, final Logger log,
40714071
final List<CheckedConsumer<Registry>> onStop) {
40724072
// stop services
4073-
onStop.forEach(c -> {
4074-
try {
4075-
c.accept(app);
4076-
} catch (Throwable x) {
4077-
log.error("shutdown of {} resulted in error", c, x);
4078-
}
4079-
});
4073+
onStop.forEach(c -> Try.run(() -> c.accept(app))
4074+
.onFailure(x -> log.error("shutdown of {} resulted in error", c, x)));
40804075
}
40814076

40824077
/**

jooby/src/main/java/org/jooby/Response.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,19 @@ default Response status(final int status) {
630630
*/
631631
void end();
632632

633+
/**
634+
* Append an after handler, will be execute before sending response.
635+
*
636+
* @param handler A handler
637+
* @see Route.After
638+
*/
633639
void push(Route.After handler);
634640

641+
/**
642+
* Append complete handler, will be execute after sending response.
643+
*
644+
* @param handler A handler
645+
* @see Route.After
646+
*/
635647
void push(Route.Complete handler);
636648
}

jooby/src/test/java/org/jooby/JoobyTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,53 @@ public void onStartStopCallback() throws Exception {
687687
}, boot);
688688
}
689689

690+
@Test(expected = IllegalStateException.class)
691+
public void appDidnStart() throws Exception {
692+
new Jooby().require(Object.class);
693+
}
694+
695+
@Test
696+
public void onStopCallbackLogError() throws Exception {
697+
698+
new MockUnit(Binder.class, CheckedRunnable.class)
699+
.expect(guice)
700+
.expect(shutdown)
701+
.expect(config)
702+
.expect(env)
703+
.expect(classInfo)
704+
.expect(ssl)
705+
.expect(charset)
706+
.expect(locale)
707+
.expect(zoneId)
708+
.expect(timeZone)
709+
.expect(dateTimeFormatter)
710+
.expect(numberFormat)
711+
.expect(decimalFormat)
712+
.expect(renderers)
713+
.expect(session)
714+
.expect(routes)
715+
.expect(routeHandler)
716+
.expect(params)
717+
.expect(requestScope)
718+
.expect(webSockets)
719+
.expect(tmpdir)
720+
.expect(err)
721+
.expect(unit -> {
722+
unit.get(CheckedRunnable.class).run();
723+
unit.get(CheckedRunnable.class).run();
724+
expectLastCall().andThrow(new IllegalStateException("intentional err"));
725+
})
726+
.run(unit -> {
727+
728+
Jooby app = new Jooby()
729+
.onStart(unit.get(CheckedRunnable.class))
730+
.onStop(unit.get(CheckedRunnable.class));
731+
app.start();
732+
app.stop();
733+
734+
}, boot);
735+
}
736+
690737
@Test
691738
public void defaultsWithCallback() throws Exception {
692739

jooby/src/test/java/org/jooby/ResponseForwardingTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,32 @@ public void end() throws Exception {
345345
});
346346
}
347347

348+
@Test
349+
public void pushAfter() throws Exception {
350+
new MockUnit(Response.class, Route.After.class)
351+
.expect(unit -> {
352+
Response rsp = unit.get(Response.class);
353+
rsp.push(unit.get(Route.After.class));
354+
})
355+
.run(unit -> {
356+
Response rsp = new Response.Forwarding(unit.get(Response.class));
357+
358+
rsp.push(unit.get(Route.After.class));
359+
});
360+
}
361+
362+
@Test
363+
public void pushComplete() throws Exception {
364+
new MockUnit(Response.class, Route.Complete.class)
365+
.expect(unit -> {
366+
Response rsp = unit.get(Response.class);
367+
rsp.push(unit.get(Route.Complete.class));
368+
})
369+
.run(unit -> {
370+
Response rsp = new Response.Forwarding(unit.get(Response.class));
371+
372+
rsp.push(unit.get(Route.Complete.class));
373+
});
374+
}
375+
348376
}

0 commit comments

Comments
 (0)