LoggingInit implements Init<M, F> { @Nonnull @Override public First<M, F> init(M model) { logger.beforeInit(model); First<M, F> result = safeInvokeInit(model); logger.afterInit(model, result); return result; } LoggingInit(Init<M, F> actualInit, MobiusLoop.Logger<M, ?, F> logger); @Nonnull @Override First<M, F> init(M model);  }
@Test public void shouldLogBeforeInit() throws Exception { loggingInit.init("tha modell"); assertThat(logger.beforeInit, contains("tha modell")); }
@Test public void shouldLogAfterInit() throws Exception { loggingInit.init("tha modell"); assertThat( logger.afterInit, contains( CapturingLogger.AfterInitArgs.create( "tha modell", First.<String, Integer>first("tha modell")))); }
@Test public void shouldReportExceptions() throws Exception { final RuntimeException expected = new RuntimeException("expected"); loggingInit = new LoggingInit<>( new Init<String, Integer>() { @Nonnull @Override public First<String, Integer> init(String model) { throw expected; } }, logger); try { loggingInit.init("log this plx"); } catch (Exception e) { } assertThat( logger.initErrors, contains(CapturingLogger.InitErrorArgs.create("log this plx", expected))); }
@Test public void shouldPropagateExceptions() throws Exception { final RuntimeException expected = new RuntimeException("expected"); loggingInit = new LoggingInit<>( new Init<String, Integer>() { @Nonnull @Override public First<String, Integer> init(String model) { throw expected; } }, logger); assertThatThrownBy(() -> loggingInit.init("hi")).isEqualTo(expected); }