BlockTemplate extends AbstractTemplate implements BlockOperation { @Override public BlockMetadata getBlockMetadata(final BlockHash blockHash) { return request(blockMethods.getBlockMetadataByHash(), Arrays.<Object>asList(blockHash)); } 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 testGetBlockMetadataByHash() throws Exception { final BlockTemplate blockTemplate = new BlockTemplate(contextStorage); final Requester mockRequester = mock(Requester.class); final BlockMetadata expected = BlockMetadata.newBuilder().build(); when(mockRequester.request(ArgumentMatchers.<Invocation<?>>any())) .thenReturn(expected); blockTemplate.requester = mockRequester; final BlockMetadata actual = blockTemplate.getBlockMetadata(anyBlockHash); assertEquals(expected, actual); }
@Test public void testGetBlockMetadataByHeight() throws Exception { final BlockTemplate blockTemplate = new BlockTemplate(contextStorage); final Requester mockRequester = mock(Requester.class); final BlockMetadata expected = BlockMetadata.newBuilder().build(); when(mockRequester.request(ArgumentMatchers.<Invocation<?>>any())) .thenReturn(expected); blockTemplate.requester = mockRequester; final BlockMetadata actual = blockTemplate.getBlockMetadata(anyHeight); assertEquals(expected, actual); }