### Question:
Discard implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final Address address = requestContext.getRequiredParameter(0, Address.class); proposer.discard(address); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); } Discard(final VoteProposer proposer); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test public void discardEmpty() { final VoteProposer proposer = new VoteProposer(); final Discard discard = new Discard(proposer); final Address a0 = Address.fromHexString("0"); final JsonRpcResponse response = discard.response(requestWithParams(a0)); assertThat(proposer.get(a0)).isEqualTo(Optional.empty()); assertThat(response.getType()).isEqualTo(JsonRpcResponseType.SUCCESS); final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; assertThat(successResponse.getResult()).isEqualTo(true); }
@Test public void discardAuth() { final VoteProposer proposer = new VoteProposer(); final Discard discard = new Discard(proposer); final Address a0 = Address.fromHexString("0"); proposer.auth(a0); final JsonRpcResponse response = discard.response(requestWithParams(a0)); assertThat(proposer.get(a0)).isEqualTo(Optional.empty()); assertThat(response.getType()).isEqualTo(JsonRpcResponseType.SUCCESS); final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; assertThat(successResponse.getResult()).isEqualTo(true); }
@Test public void discardDrop() { final VoteProposer proposer = new VoteProposer(); final Discard discard = new Discard(proposer); final Address a0 = Address.fromHexString("0"); proposer.drop(a0); final JsonRpcResponse response = discard.response(requestWithParams(a0)); assertThat(proposer.get(a0)).isEqualTo(Optional.empty()); assertThat(response.getType()).isEqualTo(JsonRpcResponseType.SUCCESS); final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; assertThat(successResponse.getResult()).isEqualTo(true); }
@Test public void discardIsolation() { final VoteProposer proposer = new VoteProposer(); final Discard discard = new Discard(proposer); final Address a0 = Address.fromHexString("0"); final Address a1 = Address.fromHexString("1"); proposer.auth(a0); proposer.auth(a1); final JsonRpcResponse response = discard.response(requestWithParams(a0)); assertThat(proposer.get(a0)).isEqualTo(Optional.empty()); assertThat(proposer.get(a1)).isEqualTo(Optional.of(VoteType.ADD)); assertThat(response.getType()).isEqualTo(JsonRpcResponseType.SUCCESS); final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; assertThat(successResponse.getResult()).isEqualTo(true); }
@Test public void discardWithoutAddress() { final VoteProposer proposer = new VoteProposer(); final Discard discard = new Discard(proposer); assertThatThrownBy(() -> discard.response(requestWithParams())) .hasMessage("Missing required json rpc parameter at index 0") .isInstanceOf(InvalidJsonRpcParameters.class); }