### Question:
AdminLogsRepairCache implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final Optional<Long> blockNumber = requestContext.getOptionalParameter(0, Long.class); blockNumber.ifPresent( bn -> blockchainQueries .getBlockchain() .getBlockByNumber(bn) .orElseThrow(() -> new IllegalStateException("Block not found, " + bn))); final TransactionLogBloomCacher transactionLogBloomCacher = blockchainQueries .getTransactionLogBloomCacher() .orElseThrow( () -> new InternalError( "Error attempting to get TransactionLogBloomCacher. Please ensure that the TransactionLogBloomCacher is enabled.")); transactionLogBloomCacher.ensurePreviousSegmentsArePresent( blockNumber.orElse(blockchainQueries.headBlockNumber()), true); final Map<String, String> response = Map.of( "Status", transactionLogBloomCacher.getCachingStatus().isCaching() ? "Already running" : "Started"); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), response); } AdminLogsRepairCache(final BlockchainQueries blockchainQueries); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test public void requestStartedTest() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("2.0", "admin_logsRepairCache", new String[] {})); final Map<String, String> response = new HashMap<>(); response.put("Status", "Started"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), response); when(blockchainQueries.getTransactionLogBloomCacher()) .thenReturn(Optional.of(transactionLogBloomCacher)); when(transactionLogBloomCacher.getCachingStatus()).thenReturn(cachingStatus); when(cachingStatus.isCaching()).thenReturn(false); final JsonRpcResponse actualResponse = adminLogsRepairCache.response(request); assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse); }
@Test public void requestAlreadyRunningTest() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("2.0", "admin_logsRepairCache", new String[] {})); final Map<String, String> response = new HashMap<>(); response.put("Status", "Already running"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), response); when(blockchainQueries.getTransactionLogBloomCacher()) .thenReturn(Optional.of(transactionLogBloomCacher)); when(transactionLogBloomCacher.getCachingStatus()).thenReturn(cachingStatus); when(cachingStatus.isCaching()).thenReturn(true); final JsonRpcResponse actualResponse = adminLogsRepairCache.response(request); assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse); }
@Test(expected = IllegalStateException.class) public void requestBlockNumberNotFoundTest() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("2.0", "admin_logsRepairCache", new String[] {"123456789"})); when(blockchainQueries.getBlockchain()).thenReturn(blockchain); when(blockchain.getBlockByNumber(anyLong())).thenReturn(Optional.empty()); adminLogsRepairCache.response(request); }