### Question:
ValidatingEth1EventsPublisher extends DelegatingEth1EventsChannel { @Override public synchronized void onDepositsFromBlock(final DepositsFromBlockEvent event) { LOG.trace( "Process deposits {} - {}", event.getFirstDepositIndex(), event.getLastDepositIndex()); assertDepositEventIsValid(event); lastPublishedDeposit = Optional.of(event.getLastDepositIndex()); delegate.onDepositsFromBlock(event); } ValidatingEth1EventsPublisher(final Eth1EventsChannel delegate); synchronized void setLatestPublishedDeposit(final UInt64 latestPublishedDeposit); @Override synchronized void onDepositsFromBlock(final DepositsFromBlockEvent event);  }### Answer:
@Test public void onDepositsFromBlock_inOrder() { final DepositsFromBlockEvent event1 = dataStructureUtil.randomDepositsFromBlockEvent(1, 0, 10); final DepositsFromBlockEvent event2 = dataStructureUtil.randomDepositsFromBlockEvent(2, 10, 11); final DepositsFromBlockEvent event3 = dataStructureUtil.randomDepositsFromBlockEvent(3, 11, 15); publisher.onDepositsFromBlock(event1); verify(delegate).onDepositsFromBlock(event1); publisher.onDepositsFromBlock(event2); verify(delegate).onDepositsFromBlock(event2); publisher.onDepositsFromBlock(event3); verify(delegate).onDepositsFromBlock(event3); }
@Test public void onDepositsFromBlock_missingDeposit() { final DepositsFromBlockEvent event1 = dataStructureUtil.randomDepositsFromBlockEvent(1, 0, 10); final DepositsFromBlockEvent event3 = dataStructureUtil.randomDepositsFromBlockEvent(3, 11, 15); publisher.onDepositsFromBlock(event1); assertThatThrownBy(() -> publisher.onDepositsFromBlock(event3)) .isInstanceOf(InvalidDepositEventsException.class) .hasMessageContaining("Expected next deposit at index 10, but got 11"); }
@Test public void onDepositsFromBlock_noLatestIndexSet_depositsFromZero() { final DepositsFromBlockEvent event1 = dataStructureUtil.randomDepositsFromBlockEvent(1, 0, 10); final DepositsFromBlockEvent event2 = dataStructureUtil.randomDepositsFromBlockEvent(2, 10, 11); publisher.onDepositsFromBlock(event1); verify(delegate).onDepositsFromBlock(event1); publisher.onDepositsFromBlock(event2); verify(delegate).onDepositsFromBlock(event2); }
@Test public void onDepositsFromBlock_noLatestIndexSet_depositsAfterZero() { final DepositsFromBlockEvent event2 = dataStructureUtil.randomDepositsFromBlockEvent(2, 10, 11); assertThatThrownBy(() -> publisher.onDepositsFromBlock(event2)) .isInstanceOf(InvalidDepositEventsException.class) .hasMessageContaining("Expected next deposit at index 0, but got 10"); }