### Question:
PrivFindPrivacyGroup implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { LOG.trace("Executing {}", RpcMethod.PRIV_FIND_PRIVACY_GROUP.getMethodName()); final String[] addresses = requestContext.getRequiredParameter(0, String[].class); LOG.trace("Finding a privacy group with members {}", Arrays.toString(addresses)); final List<PrivacyGroup> response; try { response = Arrays.asList( privacyController.findPrivacyGroup( Arrays.asList(addresses), enclavePublicKeyProvider.getEnclaveKey(requestContext.getUser()))); } catch (final MultiTenancyValidationException e) { LOG.error("Unauthorized privacy multi-tenancy rpc request. {}", e.getMessage()); return new JsonRpcErrorResponse( requestContext.getRequest().getId(), FIND_PRIVACY_GROUP_ERROR); } catch (final Exception e) { LOG.error("Failed to fetch privacy group", e); return new JsonRpcErrorResponse( requestContext.getRequest().getId(), FIND_PRIVACY_GROUP_ERROR); } return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), response); } PrivFindPrivacyGroup(
      final PrivacyController privacyController,
      final EnclavePublicKeyProvider enclavePublicKeyProvider); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@SuppressWarnings("unchecked") @Test public void findsPrivacyGroupWithValidAddresses() { when(privacyController.findPrivacyGroup(ADDRESSES, ENCLAVE_PUBLIC_KEY)) .thenReturn(new PrivacyGroup[] {privacyGroup}); final PrivFindPrivacyGroup privFindPrivacyGroup = new PrivFindPrivacyGroup(privacyController, enclavePublicKeyProvider); final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) privFindPrivacyGroup.response(request); final List<PrivacyGroup> result = (List<PrivacyGroup>) response.getResult(); assertThat(result).hasSize(1); assertThat(result.get(0)).isEqualToComparingFieldByField(privacyGroup); verify(privacyController).findPrivacyGroup(ADDRESSES, ENCLAVE_PUBLIC_KEY); }
@Test public void failsWithFindPrivacyGroupErrorIfEnclaveFails() { when(privacyController.findPrivacyGroup(ADDRESSES, ENCLAVE_PUBLIC_KEY)) .thenThrow(new EnclaveClientException(500, "some failure")); final PrivFindPrivacyGroup privFindPrivacyGroup = new PrivFindPrivacyGroup(privacyController, enclavePublicKeyProvider); final JsonRpcErrorResponse response = (JsonRpcErrorResponse) privFindPrivacyGroup.response(request); assertThat(response.getError()).isEqualTo(JsonRpcError.FIND_PRIVACY_GROUP_ERROR); verify(privacyController).findPrivacyGroup(ADDRESSES, ENCLAVE_PUBLIC_KEY); }
@Test public void failsWithUnauthorizedErrorIfMultiTenancyValidationFails() { when(privacyController.findPrivacyGroup(ADDRESSES, ENCLAVE_PUBLIC_KEY)) .thenThrow(new MultiTenancyValidationException("validation failed")); final PrivFindPrivacyGroup privFindPrivacyGroup = new PrivFindPrivacyGroup(privacyController, enclavePublicKeyProvider); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse( request.getRequest().getId(), JsonRpcError.FIND_PRIVACY_GROUP_ERROR); final JsonRpcResponse response = privFindPrivacyGroup.response(request); assertThat(response).isEqualTo(expectedResponse); verify(privacyController).findPrivacyGroup(ADDRESSES, ENCLAVE_PUBLIC_KEY); }