@Test public void testGetTokenException() throws Exception { Response response = Mockito.mock(Response.class); when(response.getStatusInfo()).thenReturn(Response.Status.BAD_REQUEST); when(invocation.invoke()).thenReturn(response); assertThatThrownBy(() -> api.getToken()) .isInstanceOf(MTException.class); }
protected String getToken() throws MTException { Response response = null; try { LOG.debug("Getting token for Microsoft Engine"); Invocation.Builder builder = restClient.getBuilder(DATA_MARKET_ACCESS_URI, ENCODING); builder.header(OCP_APIM_SUBSCRIPTION_KEY_HEADER, clientSubscriptionKey); response = builder.build("POST").invoke(); if (response.getStatusInfo() != Response.Status.OK) { throw new MTException( "Error getting token: " + response.getStatusInfo().getReasonPhrase()); } return response.readEntity(String.class); } finally { if (response != null) { response.close(); } } }
MicrosoftTranslatorClient { protected String getToken() throws MTException { Response response = null; try { LOG.debug("Getting token for Microsoft Engine"); Invocation.Builder builder = restClient.getBuilder(DATA_MARKET_ACCESS_URI, ENCODING); builder.header(OCP_APIM_SUBSCRIPTION_KEY_HEADER, clientSubscriptionKey); response = builder.build("POST").invoke(); if (response.getStatusInfo() != Response.Status.OK) { throw new MTException( "Error getting token: " + response.getStatusInfo().getReasonPhrase()); } return response.readEntity(String.class); } finally { if (response != null) { response.close(); } } } }
MicrosoftTranslatorClient { protected String getToken() throws MTException { Response response = null; try { LOG.debug("Getting token for Microsoft Engine"); Invocation.Builder builder = restClient.getBuilder(DATA_MARKET_ACCESS_URI, ENCODING); builder.header(OCP_APIM_SUBSCRIPTION_KEY_HEADER, clientSubscriptionKey); response = builder.build("POST").invoke(); if (response.getStatusInfo() != Response.Status.OK) { throw new MTException( "Error getting token: " + response.getStatusInfo().getReasonPhrase()); } return response.readEntity(String.class); } finally { if (response != null) { response.close(); } } } protected  MicrosoftTranslatorClient(String clientSubscriptionKey,
            MicrosoftRestEasyClient restClient, DTOUtil dtoUtil); }
MicrosoftTranslatorClient { protected String getToken() throws MTException { Response response = null; try { LOG.debug("Getting token for Microsoft Engine"); Invocation.Builder builder = restClient.getBuilder(DATA_MARKET_ACCESS_URI, ENCODING); builder.header(OCP_APIM_SUBSCRIPTION_KEY_HEADER, clientSubscriptionKey); response = builder.build("POST").invoke(); if (response.getStatusInfo() != Response.Status.OK) { throw new MTException( "Error getting token: " + response.getStatusInfo().getReasonPhrase()); } return response.readEntity(String.class); } finally { if (response != null) { response.close(); } } } protected  MicrosoftTranslatorClient(String clientSubscriptionKey,
            MicrosoftRestEasyClient restClient, DTOUtil dtoUtil);  }
MicrosoftTranslatorClient { protected String getToken() throws MTException { Response response = null; try { LOG.debug("Getting token for Microsoft Engine"); Invocation.Builder builder = restClient.getBuilder(DATA_MARKET_ACCESS_URI, ENCODING); builder.header(OCP_APIM_SUBSCRIPTION_KEY_HEADER, clientSubscriptionKey); response = builder.build("POST").invoke(); if (response.getStatusInfo() != Response.Status.OK) { throw new MTException( "Error getting token: " + response.getStatusInfo().getReasonPhrase()); } return response.readEntity(String.class); } finally { if (response != null) { response.close(); } } } protected  MicrosoftTranslatorClient(String clientSubscriptionKey,
            MicrosoftRestEasyClient restClient, DTOUtil dtoUtil);   }