BlockTemplate extends AbstractTemplate implements BlockOperation { @Override public Subscription<BlockMetadata> subscribeBlockMetadata( final StreamObserver<BlockMetadata> observer) { return request(blockMethods.getSubscribeBlockMetadata(), Arrays.<Object>asList(observer)); } BlockTemplate(final ContextStorage<Context> contextStorage); @Override BlockMetadata getBlockMetadata(final BlockHash blockHash); @Override BlockMetadata getBlockMetadata(final long height); @Override List<BlockMetadata> listBlockMetadatas(final BlockHash blockHash, final int size); @Override List<BlockMetadata> listBlockMetadatas(final long height, final int size); @Override Block getBlock(final BlockHash blockHash); @Override Block getBlock(final long height); @Override Subscription<BlockMetadata> subscribeNewBlockMetadata(
      final StreamObserver<BlockMetadata> observer); @Override Subscription<BlockMetadata> subscribeBlockMetadata(
      final StreamObserver<BlockMetadata> observer); @Override Subscription<Block> subscribeNewBlock(final StreamObserver<Block> observer); @Override Subscription<Block> subscribeBlock(final StreamObserver<Block> observer);  }
@Test public void testSubscribeBlockMetadata() throws Exception { final BlockTemplate blockTemplate = new BlockTemplate(contextStorage); final Requester mockRequester = mock(Requester.class); final Subscription<?> expected = mock(Subscription.class); when(mockRequester.request(ArgumentMatchers.<Invocation<?>>any())).thenReturn(expected); blockTemplate.requester = mockRequester; final StreamObserver<BlockMetadata> observer = new StreamObserver<BlockMetadata>() { @Override public void onNext(BlockMetadata value) { } @Override public void onError(Throwable t) { } @Override public void onCompleted() { } }; assertEquals(expected, blockTemplate.subscribeBlockMetadata(observer)); assertEquals(expected, blockTemplate.subscribeNewBlockMetadata(observer)); }