### Question:
EthHashrate implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final Optional<Long> hashesPerSecond = miningCoordinator.hashesPerSecond(); return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), Quantity.create(hashesPerSecond.orElse(0L))); } EthHashrate(final MiningCoordinator miningCoordinator); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test public void shouldReturnValueFromMiningCoordinator() { final JsonRpcRequestContext request = requestWithParams(); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), "0xc"); when(miningCoordinator.hashesPerSecond()).thenReturn(Optional.of(12L)); final JsonRpcResponse actualResponse = method.response(request); assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse); }
@Test public void shouldReturnZeroWhenMiningCoordinatorDoesNotHaveHashes() { final JsonRpcRequestContext request = requestWithParams(); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), "0x0"); when(miningCoordinator.hashesPerSecond()).thenReturn(Optional.empty()); final JsonRpcResponse actualResponse = method.response(request); assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse); }