### Question:
CliqueGetSignersAtHash implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final Optional<BlockHeader> blockHeader = determineBlockHeader(requestContext); return blockHeader .map(bh -> voteTallyCache.getVoteTallyAfterBlock(bh).getValidators()) .map(addresses -> addresses.stream().map(Objects::toString).collect(Collectors.toList())) .<JsonRpcResponse>map( addresses -> new JsonRpcSuccessResponse(requestContext.getRequest().getId(), addresses)) .orElse( new JsonRpcErrorResponse( requestContext.getRequest().getId(), JsonRpcError.INTERNAL_ERROR)); } CliqueGetSignersAtHash(
      final BlockchainQueries blockchainQueries, final VoteTallyCache voteTallyCache); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test @SuppressWarnings("unchecked") public void failsWhenNoParam() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("2.0", "clique_getSignersAtHash", new Object[] {})); final Throwable thrown = AssertionsForClassTypes.catchThrowable(() -> method.response(request)); assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) .hasMessage("Missing required json rpc parameter at index 0"); }
@Test @SuppressWarnings("unchecked") public void returnsValidatorsForBlockHash() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("2.0", "clique_getSignersAtHash", new Object[] {BLOCK_HASH})); when(blockchainQueries.blockByHash(Hash.fromHexString(BLOCK_HASH))) .thenReturn(Optional.of(blockWithMetadata)); when(blockWithMetadata.getHeader()).thenReturn(blockHeader); when(voteTallyCache.getVoteTallyAfterBlock(blockHeader)).thenReturn(voteTally); when(voteTally.getValidators()).thenReturn(validators); final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request); assertThat(response.getResult()).isEqualTo(validatorsAsStrings); }
@Test public void failsOnInvalidBlockHash() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("2.0", "clique_getSigners", new Object[] {BLOCK_HASH})); when(blockchainQueries.blockByHash(Hash.fromHexString(BLOCK_HASH))) .thenReturn(Optional.empty()); final JsonRpcErrorResponse response = (JsonRpcErrorResponse) method.response(request); assertThat(response.getError().name()).isEqualTo(JsonRpcError.INTERNAL_ERROR.name()); }