### Question:
CliqueGetSigners 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)); } CliqueGetSigners(
      final BlockchainQueries blockchainQueries, final VoteTallyCache voteTallyCache); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test @SuppressWarnings("unchecked") public void returnsValidatorsWhenNoParam() { final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", "clique_getSigners", new Object[] {})); when(blockchainQueries.headBlockNumber()).thenReturn(3065995L); when(blockchainQueries.blockByNumber(3065995L)).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(validatorAsStrings); }
@Test @SuppressWarnings("unchecked") public void returnsValidatorsForBlockNumber() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("2.0", "clique_getSigners", new Object[] {"0x2EC88B"})); when(blockchainQueries.blockByNumber(3065995L)).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(validatorAsStrings); }
@Test public void failsOnInvalidBlockNumber() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("2.0", "clique_getSigners", new Object[] {"0x1234"})); when(blockchainQueries.blockByNumber(4660)).thenReturn(Optional.empty()); final JsonRpcErrorResponse response = (JsonRpcErrorResponse) method.response(request); assertThat(response.getError().name()).isEqualTo(JsonRpcError.INTERNAL_ERROR.name()); }