### Question:
EncryptionKeyService extends EscrowAgentService { public EncryptionKey requestEncryptionKey() throws IOException, EscrowAgentErrorResponseException { if (!requestToken.isAuthorized()) throw new InvalidRequestTokenException("Your request token cannot" + " be exchanged for an encryption key"); clientCredentials.checkNotNull(); requestToken.checkNotNull(); String url = "https: + EscrowAgent.getEncryptionKeyService(); TreeMap<String, String> parameters = getParameters(); SignatureBase signatureBase = new SignatureBase(parameters, url, "POST"); String parametersQuery = signRequest(signatureBase, clientCredentials.getClientSecret() + "&" + requestToken.getTokenSecret()); String response = callEscrowAgentService(parametersQuery, url); return (EncryptionKey) ResponseParser.toObject(response, EncryptionKey.class); } EncryptionKeyService(final ClientCredentials clientCredentials,
            final EscrowAgent escrowAgent, final SecureConnection con,
            final RequestToken requestToken); @Override TreeMap<String, String> getParameters(); EncryptionKey requestEncryptionKey();  }### Answer:
@Test public void testRequestEncryptionKey() throws IOException, EscrowAgentErrorResponseException { EncryptionKeyService mockService = Mockito.spy(new EncryptionKeyService( client, escrowAgent, secure, requestToken)); Mockito.doReturn("encryption_key=key") .when((EscrowAgentService) mockService) .callEscrowAgentService(Mockito.anyString(), Mockito.anyString()); EncryptionKey key = mockService.requestEncryptionKey(); Assert.assertEquals(key.getEncryptionKey(), "key"); Mockito.verify((EscrowAgentService) mockService, Mockito.times(1)) .callEscrowAgentService(Mockito.anyString(), Mockito.anyString()); }
@Test(expected = InvalidRequestTokenException.class) public void testUnauthorizedRequestToken() throws IOException, EscrowAgentErrorResponseException { EncryptionKeyService service = new EncryptionKeyService(client, escrowAgent, secure, unauthorizedToken); service.requestEncryptionKey(); }