### Question:
MinerSetCoinbase implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { try { final Address coinbase = requestContext.getRequiredParameter(0, Address.class); miningCoordinator.setCoinbase(coinbase); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); } catch (final UnsupportedOperationException ex) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), JsonRpcError.INVALID_REQUEST); } } MinerSetCoinbase(final MiningCoordinator miningCoordinator); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test public void shouldFailWhenMissingAddress() { final JsonRpcRequestContext request = minerSetCoinbaseRequest(null); final Throwable thrown = catchThrowable(() -> method.response(request)); assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) .hasMessage("Missing required json rpc parameter at index 0"); }
@Test public void shouldFailWhenAddressIsInvalid() { final JsonRpcRequestContext request = minerSetCoinbaseRequest("foo"); final Throwable thrown = catchThrowable(() -> method.response(request)); assertThat(thrown).isInstanceOf(InvalidJsonRpcParameters.class); }
@Test public void shouldSetCoinbaseWhenRequestHasAddress() { final JsonRpcRequestContext request = minerSetCoinbaseRequest("0x0"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, true); final JsonRpcResponse response = method.response(request); verify(miningCoordinator).setCoinbase(eq(Address.fromHexString("0x0"))); assertThat(response).isEqualToComparingFieldByField(expectedResponse); }
@Test public void shouldReturnAnInvalidRequestIfUnderlyingOperationThrowsUnsupportedOperation() { final JsonRpcRequestContext request = minerSetCoinbaseRequest("0x0"); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.INVALID_REQUEST); doAnswer( invocation -> { throw new UnsupportedOperationException(); }) .when(miningCoordinator) .setCoinbase(any()); final JsonRpcResponse response = method.response(request); assertThat(response).isEqualToComparingFieldByField(expectedResponse); }