### Question:
PrivDeletePrivacyGroup implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { LOG.trace("Executing {}", RpcMethod.PRIV_DELETE_PRIVACY_GROUP.getMethodName()); final String privacyGroupId = requestContext.getRequiredParameter(0, String.class); final String response; try { response = privacyController.deletePrivacyGroup( privacyGroupId, enclavePublicKeyProvider.getEnclaveKey(requestContext.getUser())); } catch (final MultiTenancyValidationException e) { LOG.error("Unauthorized privacy multi-tenancy rpc request. {}", e.getMessage()); return new JsonRpcErrorResponse( requestContext.getRequest().getId(), DELETE_PRIVACY_GROUP_ERROR); } catch (Exception e) { LOG.error("Failed to delete privacy group", e); return new JsonRpcErrorResponse( requestContext.getRequest().getId(), DELETE_PRIVACY_GROUP_ERROR); } return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), response); } PrivDeletePrivacyGroup(
      final PrivacyController privacyController,
      final EnclavePublicKeyProvider enclavePublicKeyProvider); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test public void deletesPrivacyGroupWithValidGroupId() { when(privacyController.deletePrivacyGroup(PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY)) .thenReturn(PRIVACY_GROUP_ID); final PrivDeletePrivacyGroup privDeletePrivacyGroup = new PrivDeletePrivacyGroup(privacyController, enclavePublicKeyProvider); final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) privDeletePrivacyGroup.response(request); final String result = (String) response.getResult(); assertThat(result).isEqualTo(PRIVACY_GROUP_ID); verify(privacyController).deletePrivacyGroup(PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY); }
@Test public void failsWithDeletePrivacyGroupErrorIfEnclaveFails() { when(privacyController.deletePrivacyGroup(PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY)) .thenThrow(new EnclaveClientException(500, "some failure")); final PrivDeletePrivacyGroup privDeletePrivacyGroup = new PrivDeletePrivacyGroup(privacyController, enclavePublicKeyProvider); final JsonRpcErrorResponse response = (JsonRpcErrorResponse) privDeletePrivacyGroup.response(request); assertThat(response.getError()).isEqualTo(JsonRpcError.DELETE_PRIVACY_GROUP_ERROR); verify(privacyController).deletePrivacyGroup(PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY); }
@Test public void failsWithUnauthorizedErrorIfMultiTenancyValidationFails() { when(privacyController.deletePrivacyGroup(PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY)) .thenThrow(new MultiTenancyValidationException("validation failed")); final PrivDeletePrivacyGroup privDeletePrivacyGroup = new PrivDeletePrivacyGroup(privacyController, enclavePublicKeyProvider); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse( request.getRequest().getId(), JsonRpcError.DELETE_PRIVACY_GROUP_ERROR); final JsonRpcResponse response = privDeletePrivacyGroup.response(request); assertThat(response).isInstanceOf(JsonRpcErrorResponse.class); final JsonRpcErrorResponse errorResponse = (JsonRpcErrorResponse) response; assertThat(errorResponse).isEqualTo(expectedResponse); }