@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); } }
@Nonnull @Override public First<M, F> init(M model) { logger.beforeInit(model); First<M, F> result = safeInvokeInit(model); logger.afterInit(model, result); return result; }
@Before public void setUp() throws Exception { Init<String, Integer> delegate = new Init<String, Integer>() { @Nonnull @Override public First<String, Integer> init(String model) { return First.first(model); } }; logger = new CapturingLogger<>(); loggingInit = new LoggingInit<>(delegate, logger); }
@Test public void shouldLogBeforeInit() throws Exception { loggingInit.init("tha modell"); assertThat(logger.beforeInit, contains("tha modell")); }
@Override @Nonnull public MobiusLoop<M, E, F> startFrom(M startModel) { LoggingInit<M, F> loggingInit = new LoggingInit<>(init, logger); LoggingUpdate<M, E, F> loggingUpdate = new LoggingUpdate<>(update, logger); return MobiusLoop.create( MobiusStore.create(loggingInit, loggingUpdate, checkNotNull(startModel)), effectHandler, eventSource, checkNotNull(eventRunner.get()), checkNotNull(effectRunner.get())); }
@Test public void shouldLogAfterInit() throws Exception { loggingInit.init("tha modell"); //noinspection unchecked 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) { // ignore } //noinspection unchecked assertThat( logger.initErrors, contains(CapturingLogger.InitErrorArgs.create("log this plx", expected))); }
@Override @Nonnull public MobiusLoop<M, E, F> startFrom(M startModel) { LoggingInit<M, F> loggingInit = new LoggingInit<>(init, logger); LoggingUpdate<M, E, F> loggingUpdate = new LoggingUpdate<>(update, logger); return MobiusLoop.create( MobiusStore.create(loggingInit, loggingUpdate, checkNotNull(startModel)), effectHandler, eventSource, checkNotNull(eventRunner.get()), checkNotNull(effectRunner.get())); }
@Nonnull @Override public First<M, F> init(M model) { logger.beforeInit(model); First<M, F> result = safeInvokeInit(model); logger.afterInit(model, result); return result; }