@Test public void testGetTokenIfNeeded() { String responseKey = "randomKeyThatReturnsFromMS"; Response response = Mockito.mock(Response.class); when(response.getStatusInfo()).thenReturn(Response.Status.OK); when(response.readEntity(String.class)).thenReturn(responseKey); when(invocation.invoke()).thenReturn(response); String token = api.getCurrentToken(); Long tokenExpiry = api.getTokenExpiration(); api.getTokenIfNeeded(); assertThat(api.getCurrentToken()).isNotEqualTo(token); assertThat(api.getTokenExpiration()).isNotEqualTo(tokenExpiry); }
protected void getTokenIfNeeded() { if (System.currentTimeMillis() > tokenExpiration) { String tokenKey = getToken(); tokenExpiration = System.currentTimeMillis() + TOKEN_CACHE_EXPIRATION; token = "Bearer " + tokenKey; if (LOG.isDebugEnabled()) { LOG.debug("New token:{}", token); } } }
MicrosoftTranslatorClient { protected void getTokenIfNeeded() { if (System.currentTimeMillis() > tokenExpiration) { String tokenKey = getToken(); tokenExpiration = System.currentTimeMillis() + TOKEN_CACHE_EXPIRATION; token = "Bearer " + tokenKey; if (LOG.isDebugEnabled()) { LOG.debug("New token:{}", token); } } } }
MicrosoftTranslatorClient { protected void getTokenIfNeeded() { if (System.currentTimeMillis() > tokenExpiration) { String tokenKey = getToken(); tokenExpiration = System.currentTimeMillis() + TOKEN_CACHE_EXPIRATION; token = "Bearer " + tokenKey; if (LOG.isDebugEnabled()) { LOG.debug("New token:{}", token); } } } protected  MicrosoftTranslatorClient(String clientSubscriptionKey,
            MicrosoftRestEasyClient restClient, DTOUtil dtoUtil); }
MicrosoftTranslatorClient { protected void getTokenIfNeeded() { if (System.currentTimeMillis() > tokenExpiration) { String tokenKey = getToken(); tokenExpiration = System.currentTimeMillis() + TOKEN_CACHE_EXPIRATION; token = "Bearer " + tokenKey; if (LOG.isDebugEnabled()) { LOG.debug("New token:{}", token); } } } protected  MicrosoftTranslatorClient(String clientSubscriptionKey,
            MicrosoftRestEasyClient restClient, DTOUtil dtoUtil);  }
MicrosoftTranslatorClient { protected void getTokenIfNeeded() { if (System.currentTimeMillis() > tokenExpiration) { String tokenKey = getToken(); tokenExpiration = System.currentTimeMillis() + TOKEN_CACHE_EXPIRATION; token = "Bearer " + tokenKey; if (LOG.isDebugEnabled()) { LOG.debug("New token:{}", token); } } } protected  MicrosoftTranslatorClient(String clientSubscriptionKey,
            MicrosoftRestEasyClient restClient, DTOUtil dtoUtil);   }