### Question:
PrivNewFilter implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext request) { final String privacyGroupId = request.getRequiredParameter(0, String.class); final FilterParameter filter = request.getRequiredParameter(1, FilterParameter.class); final String enclavePublicKey = enclavePublicKeyProvider.getEnclaveKey(request.getUser()); checkIfPrivacyGroupMatchesAuthenticatedEnclaveKey(enclavePublicKey, privacyGroupId); if (!filter.isValid()) { return new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.INVALID_PARAMS); } final String logFilterId = filterManager.installPrivateLogFilter( privacyGroupId, enclavePublicKey, filter.getFromBlock(), filter.getToBlock(), filter.getLogsQuery()); return new JsonRpcSuccessResponse(request.getRequest().getId(), logFilterId); } PrivNewFilter(
      final FilterManager filterManager,
      final PrivacyController privacyController,
      final EnclavePublicKeyProvider enclavePublicKeyProvider); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext request);  }### Answer:
@Test public void privacyGroupIdIsRequired() { final JsonRpcRequestContext request = privNewFilterRequest(null, mock(FilterParameter.class)); assertThatThrownBy(() -> method.response(request)) .isInstanceOf(InvalidJsonRpcParameters.class) .hasMessageContaining("Missing required json rpc parameter at index 0"); }
@Test public void filterParameterIsRequired() { final JsonRpcRequestContext request = privNewFilterRequest(PRIVACY_GROUP_ID, null); assertThatThrownBy(() -> method.response(request)) .isInstanceOf(InvalidJsonRpcParameters.class) .hasMessageContaining("Missing required json rpc parameter at index 1"); }
@Test public void filterWithInvalidParameters() { final FilterParameter invalidFilter = new FilterParameter( BlockParameter.EARLIEST, BlockParameter.LATEST, Collections.emptyList(), Collections.emptyList(), Hash.ZERO); final JsonRpcRequestContext request = privNewFilterRequest(PRIVACY_GROUP_ID, invalidFilter); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, JsonRpcError.INVALID_PARAMS); final JsonRpcResponse response = method.response(request); assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse); }
@Test public void filterWithExpectedQueryIsCreated() { final List<Address> addresses = List.of(Address.ZERO); final User user = mock(User.class); final List<List<LogTopic>> logTopics = List.of(List.of(LogTopic.of(Bytes32.random()))); when(enclavePublicKeyProvider.getEnclaveKey(eq(Optional.of(user)))).thenReturn(ENCLAVE_KEY); final FilterParameter filter = new FilterParameter( BlockParameter.EARLIEST, BlockParameter.LATEST, addresses, logTopics, null); final LogsQuery expectedQuery = new LogsQuery.Builder().addresses(addresses).topics(logTopics).build(); final JsonRpcRequestContext request = privNewFilterRequestWithUser(PRIVACY_GROUP_ID, filter, user); method.response(request); verify(filterManager) .installPrivateLogFilter( eq(PRIVACY_GROUP_ID), eq(ENCLAVE_KEY), refEq(BlockParameter.EARLIEST), refEq(BlockParameter.LATEST), eq((expectedQuery))); }
@Test public void multiTenancyCheckFailure() { final User user = mock(User.class); final FilterParameter filterParameter = mock(FilterParameter.class); when(enclavePublicKeyProvider.getEnclaveKey(any())).thenReturn(ENCLAVE_KEY); doThrow(new MultiTenancyValidationException("msg")) .when(privacyController) .verifyPrivacyGroupContainsEnclavePublicKey(eq(PRIVACY_GROUP_ID), eq(ENCLAVE_KEY)); final JsonRpcRequestContext request = privNewFilterRequestWithUser(PRIVACY_GROUP_ID, filterParameter, user); assertThatThrownBy(() -> method.response(request)) .isInstanceOf(MultiTenancyValidationException.class) .hasMessageContaining("msg"); }