### Question:
AdminLogsRemoveCache implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final Optional<BlockParameter> startBlockParameter = requestContext.getOptionalParameter(0, BlockParameter.class); final Optional<BlockParameter> stopBlockParameter = requestContext.getOptionalParameter(1, BlockParameter.class); final long startBlock; if (startBlockParameter.isEmpty() || startBlockParameter.get().isEarliest()) { startBlock = BlockHeader.GENESIS_BLOCK_NUMBER; } else if (startBlockParameter.get().getNumber().isPresent()) { startBlock = startBlockParameter.get().getNumber().get(); blockchainQueries .getBlockchain() .getBlockByNumber(startBlock) .orElseThrow(() -> new IllegalStateException("Block not found, " + startBlock)); } else { startBlock = blockchainQueries.headBlockNumber(); } final long stopBlock; if (stopBlockParameter.isEmpty()) { if (startBlockParameter.isEmpty()) { stopBlock = blockchainQueries.headBlockNumber(); } else { stopBlock = startBlock; } } else if (stopBlockParameter.get().isEarliest()) { stopBlock = BlockHeader.GENESIS_BLOCK_NUMBER; } else if (stopBlockParameter.get().getNumber().isPresent()) { stopBlock = stopBlockParameter.get().getNumber().get(); blockchainQueries .getBlockchain() .getBlockByNumber(stopBlock) .orElseThrow(() -> new IllegalStateException("Block not found, " + stopBlock)); } else { stopBlock = blockchainQueries.headBlockNumber(); } if (stopBlock < startBlock) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS); } final TransactionLogBloomCacher transactionLogBloomCacher = blockchainQueries .getTransactionLogBloomCacher() .orElseThrow( () -> new InternalError( "Error attempting to get TransactionLogBloomCacher. Please ensure that the TransactionLogBloomCacher is enabled.")); transactionLogBloomCacher.removeSegments(startBlock, stopBlock); return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), Map.of("Status", "Cache Removed")); } AdminLogsRemoveCache(final BlockchainQueries blockchainQueries); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test public void requestCacheRemovedTest() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("2.0", "admin_logsRemoveCache", new String[] {})); final Map<String, String> response = new HashMap<>(); response.put("Status", "Cache Removed"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), response); when(blockchainQueries.getTransactionLogBloomCacher()) .thenReturn(Optional.of(transactionLogBloomCacher)); when(blockchainQueries.headBlockNumber()).thenReturn(1000L); final JsonRpcResponse actualResponse = adminLogsRemoveCache.response(request); assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse); }
@Test(expected = IllegalStateException.class) public void requestBlockNumberNotFoundTest() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("2.0", "admin_logsRemoveCache", new String[] {"123456789"})); when(blockchainQueries.getBlockchain()).thenReturn(blockchain); when(blockchain.getBlockByNumber(anyLong())).thenReturn(Optional.empty()); adminLogsRemoveCache.response(request); }
@Test public void requestBlockRangeInvalidTest() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("2.0", "admin_logsRemoveCache", new String[] {"0x20", "0x1"})); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.INVALID_PARAMS); when(blockchainQueries.getBlockchain()).thenReturn(blockchain); when(blockchain.getBlockByNumber(anyLong())).thenReturn(Optional.of(block)); final JsonRpcResponse actualResponse = adminLogsRemoveCache.response(request); assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse); }