### Question:
AzureApiCaller { public String getAccessToken() throws AzureApiException { try { final URL url = new URL(externalOAuthClientDetails.getAccessTokenUri()); ImmutableMap<String, String> params = ImmutableMap.<String, String>builder() .put("client_id", externalOAuthClientDetails.getClientId()) .put("client_secret", externalOAuthClientDetails.getClientSecret()) .put("scope", "https: .put("grant_type", "client_credentials") .build(); String urlFormattedParams = formatQueryParams(params); byte[] postData = urlFormattedParams.getBytes(StandardCharsets.UTF_8); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setInstanceFollowRedirects(false); connection.setRequestMethod("POST"); connection.setRequestProperty("Accept", "application/json"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("charset", "utf-8"); connection.setRequestProperty("Content-Length", Integer.toString(postData.length)); connection.setUseCaches(false); try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) { wr.write(postData); } BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder builder = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { builder.append(line); } AccessTokenResponse accessTokenResponse = getAccessTokenResponse(builder.toString()); return accessTokenResponse.getAccess_token(); } catch (IOException e) { throw new AzureApiException(e.getMessage()); } } @Autowired  AzureApiCaller(ExternalOAuthClientDetails externalOAuthClientDetails); String getAccessToken();  }### Answer:
@Test(expected = AzureApiException.class) public void getAccessToken_shouldFailForInvalidData() throws AzureApiException { externalOAuthClientDetails.setClientSecret("notSoSecret"); AzureApiCaller caller = new AzureApiCaller(externalOAuthClientDetails); String accessToken = caller.getAccessToken(); }