LoggingUpdate implements Update<M, E, F> { @Nonnull @Override public Next<M, F> update(M model, E event) { logger.beforeUpdate(model, event); Next<M, F> result = safeInvokeUpdate(model, event); logger.afterUpdate(model, event, result); return result; } LoggingUpdate(Update<M, E, F> actualUpdate, MobiusLoop.Logger<M, E, F> logger); @Nonnull @Override Next<M, F> update(M model, E event);  }
@Test public void shouldLogBeforeUpdate() throws Exception { loggingUpdate.update("mah model", 1); assertThat( logger.beforeUpdate, contains(CapturingLogger.BeforeUpdateArgs.create("mah model", 1))); }
@Test public void shouldLogAfterUpdate() throws Exception { loggingUpdate.update("mah model", 1); assertThat( logger.afterUpdate, contains( CapturingLogger.AfterUpdateArgs.create( "mah model", 1, Next.next("mah model-", effects(false))))); }
@Test public void shouldReportExceptions() throws Exception { final RuntimeException expected = new RuntimeException("expected"); loggingUpdate = new LoggingUpdate<>( new Update<String, Integer, Boolean>() { @Nonnull @Override public Next<String, Boolean> update(String model, Integer event) { throw expected; } }, logger); try { loggingUpdate.update("log this plx", 13); } catch (Exception e) { } assertThat( logger.updateErrors, contains(CapturingLogger.UpdateErrorArgs.create("log this plx", 13, expected))); }
@Test public void shouldPropagateExceptions() throws Exception { final RuntimeException expected = new RuntimeException("expected"); loggingUpdate = new LoggingUpdate<>( new Update<String, Integer, Boolean>() { @Nonnull @Override public Next<String, Boolean> update(String model, Integer event) { throw expected; } }, logger); assertThatThrownBy(() -> loggingUpdate.update("hi", 7)).isEqualTo(expected); }