### Question:
IbftChainObserver implements BlockAddedObserver { @Override public void onBlockAdded(final BlockAddedEvent event) { switch (event.getEventType()) { case HEAD_ADVANCED: queue.add(new NewChainHead(event.getBlock().getHeader())); break; default: throw new IllegalStateException( String.format("Unexpected BlockAddedEvent received: %s", event.getEventType())); } } IbftChainObserver(final IbftEventQueue queue); @Override void onBlockAdded(final BlockAddedEvent event);  }### Answer:
@Test public void newChainHeadHeaderEventIsAddedToTheQueue() { final IbftEventQueue mockQueue = mock(IbftEventQueue.class); final BlockAddedEvent mockBlockAddedEvent = mock(BlockAddedEvent.class); final IbftChainObserver ibftChainObserver = new IbftChainObserver(mockQueue); final BlockHeader header = new BlockHeaderTestFixture() .number(1234) .coinbase(Address.ECREC) .parentHash(Hash.EMPTY_LIST_HASH) .buildHeader(); final Block block = new Block(header, new BlockBody(emptyList(), emptyList())); when(mockBlockAddedEvent.getEventType()).thenReturn(BlockAddedEvent.EventType.HEAD_ADVANCED); when(mockBlockAddedEvent.getBlock()).thenReturn(block); ibftChainObserver.onBlockAdded(mockBlockAddedEvent); final ArgumentCaptor<IbftEvent> ibftEventArgumentCaptor = ArgumentCaptor.forClass(IbftEvent.class); verify(mockQueue).add(ibftEventArgumentCaptor.capture()); assertThat(ibftEventArgumentCaptor.getValue() instanceof NewChainHead).isTrue(); assertThat(((NewChainHead) ibftEventArgumentCaptor.getValue()).getNewChainHeadHeader()) .isEqualTo(header); }
@Test(expected = IllegalStateException.class) public void exceptionIsThrownWhenEventTypeIsFork() { final IbftEventQueue mockQueue = mock(IbftEventQueue.class); final BlockAddedEvent mockBlockAddedEvent = mock(BlockAddedEvent.class); when(mockBlockAddedEvent.getEventType()).thenReturn(BlockAddedEvent.EventType.FORK); final IbftChainObserver ibftChainObserver = new IbftChainObserver(mockQueue); ibftChainObserver.onBlockAdded(mockBlockAddedEvent); }
@Test(expected = IllegalStateException.class) public void exceptionIsThrownWhenEventTypeIsChainReorg() { final IbftEventQueue mockQueue = mock(IbftEventQueue.class); final BlockAddedEvent mockBlockAddedEvent = mock(BlockAddedEvent.class); when(mockBlockAddedEvent.getEventType()).thenReturn(BlockAddedEvent.EventType.CHAIN_REORG); final IbftChainObserver ibftChainObserver = new IbftChainObserver(mockQueue); ibftChainObserver.onBlockAdded(mockBlockAddedEvent); }