### Question:
RpcOperation { public RpcResult<T> getResult(){ RpcResult<T> result; try { T subject = execute(); result = new RpcResult<T>(false, subject); } catch (IllegalArgumentException e) { result = createRpcResultError(e, RpcResult.ErrorCode.INVALID_PARAMS); } catch (DuplicateItemException e) { result = createRpcResultError(e, RpcResult.ErrorCode.DUPLICATE_ITEM); } catch (Exception e) { result = createRpcResultError(e, RpcResult.ErrorCode.INTERNAL_ERROR); } return result; }  RpcResult<T> getResult(); abstract T execute();  }### Answer:
@Test public void execute_valid() { RpcOperation<String> valid = new RpcOperation<String>() { @Override public String execute() { return BOO; } }; RpcResult<String> result = valid.getResult(); assertThat(result.getResult(), is(equalTo(BOO))); assertThat(result.getErrorCode(), is(equalTo(RpcResult.ErrorCode.NO_ERROR))); }
@Test public void execute_invalidArgs() { RpcOperation<String> valid = new RpcOperation<String>() { @Override public String execute() { throw new IllegalArgumentException(); } }; RpcResult<String> result = valid.getResult(); assertThat(result.getResult(), is(nullValue())); assertThat(result.getErrorCode(), is(equalTo(RpcResult.ErrorCode.INVALID_PARAMS))); }
@Test public void execute_internalError() { RpcOperation<String> valid = new RpcOperation<String>() { @Override public String execute() { throw new RuntimeException("Illegal Error"); } }; RpcResult<String> result = valid.getResult(); assertThat(result.getResult(), is(nullValue())); assertThat(result.getErrorCode(), is(equalTo(RpcResult.ErrorCode.INTERNAL_ERROR))); }
@Test public void execute_duplicateItemException() { RpcOperation<String> valid = new RpcOperation<String>() { @Override public String execute() { throw new DuplicateItemException("Duplicate Item Error"); } }; RpcResult<String> result = valid.getResult(); assertThat(result.getResult(), is(nullValue())); assertThat(result.getErrorCode(), is(equalTo(RpcResult.ErrorCode.DUPLICATE_ITEM))); }