### Question:
PrivGetTransactionCount implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { if (requestContext.getRequest().getParamLength() != 2) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS); } final Address address = requestContext.getRequiredParameter(0, Address.class); final String privacyGroupId = requestContext.getRequiredParameter(1, String.class); try { final long nonce = privacyController.determineBesuNonce( address, privacyGroupId, enclavePublicKeyProvider.getEnclaveKey(requestContext.getUser())); return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), Quantity.create(nonce)); } catch (final MultiTenancyValidationException e) { LOG.error("Unauthorized privacy multi-tenancy rpc request. {}", e.getMessage()); return new JsonRpcErrorResponse( requestContext.getRequest().getId(), GET_PRIVATE_TRANSACTION_NONCE_ERROR); } catch (final Exception e) { LOG.error(e.getMessage(), e); return new JsonRpcErrorResponse( requestContext.getRequest().getId(), GET_PRIVATE_TRANSACTION_NONCE_ERROR); } } PrivGetTransactionCount(
      final PrivacyController privacyController,
      final EnclavePublicKeyProvider enclavePublicKeyProvider); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test public void verifyTransactionCount() { final PrivGetTransactionCount privGetTransactionCount = new PrivGetTransactionCount(privacyController, enclavePublicKeyProvider); final Object[] params = new Object[] {senderAddress, PRIVACY_GROUP_ID}; final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("1", "priv_getTransactionCount", params), user); final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) privGetTransactionCount.response(request); assertThat(response.getResult()).isEqualTo(String.format("0x%X", NONCE)); verify(privacyController) .determineBesuNonce(senderAddress, PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY); }
@Test public void failsWithNonceErrorIfExceptionIsThrown() { final PrivGetTransactionCount privGetTransactionCount = new PrivGetTransactionCount(privacyController, enclavePublicKeyProvider); when(privacyController.determineBesuNonce(senderAddress, PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY)) .thenThrow(EnclaveClientException.class); final Object[] params = new Object[] {senderAddress, PRIVACY_GROUP_ID}; final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("1", "priv_getTransactionCount", params), user); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse( request.getRequest().getId(), JsonRpcError.GET_PRIVATE_TRANSACTION_NONCE_ERROR); final JsonRpcResponse response = privGetTransactionCount.response(request); assertThat(response).isEqualTo(expectedResponse); }
@Test public void failsWithUnauthorizedErrorIfMultiTenancyValidationFails() { final PrivGetTransactionCount privGetTransactionCount = new PrivGetTransactionCount(privacyController, enclavePublicKeyProvider); when(privacyController.determineBesuNonce(senderAddress, PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY)) .thenThrow(new MultiTenancyValidationException("validation failed")); final Object[] params = new Object[] {senderAddress, PRIVACY_GROUP_ID}; final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest("1", "priv_getTransactionCount", params), user); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse( request.getRequest().getId(), JsonRpcError.GET_PRIVATE_TRANSACTION_NONCE_ERROR); final JsonRpcResponse response = privGetTransactionCount.response(request); assertThat(response).isEqualTo(expectedResponse); }