Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-f-n committed Jun 23, 2022
1 parent 775ebb0 commit be67ac7
Showing 1 changed file with 13 additions and 10 deletions.
Expand Up @@ -71,7 +71,6 @@
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -585,7 +584,8 @@ void refreshAccessToken_GMT_dateParsedCorrectly() throws IOException, IllegalSta
mockTransportFactory);

assertEquals(ACCESS_TOKEN, targetCredentials.refreshAccessToken().getTokenValue());
assertEquals(c.getTime().toInstant().truncatedTo(ChronoUnit.SECONDS).toEpochMilli(),
assertEquals(
c.getTime().toInstant().truncatedTo(ChronoUnit.SECONDS).toEpochMilli(),
targetCredentials.refreshAccessToken().getExpirationTimeMillis());
assertEquals(DEFAULT_IMPERSONATION_URL, mockTransportFactory.transport.getRequest().getUrl());
}
Expand All @@ -598,7 +598,8 @@ void refreshAccessToken_PDT_dateParsedCorrectly() throws IOException, IllegalSta

mockTransportFactory.transport.setTargetPrincipal(IMPERSONATED_CLIENT_EMAIL);
mockTransportFactory.transport.setAccessToken(ACCESS_TOKEN);
mockTransportFactory.transport.setExpireTime(getFormattedTime(c.getTime(), TimeZone.getTimeZone("PDT")));
mockTransportFactory.transport.setExpireTime(
getFormattedTime(c.getTime(), TimeZone.getTimeZone("PDT")));
ImpersonatedCredentials targetCredentials =
ImpersonatedCredentials.create(
sourceCredentials,
Expand All @@ -609,7 +610,8 @@ void refreshAccessToken_PDT_dateParsedCorrectly() throws IOException, IllegalSta
mockTransportFactory);

assertEquals(ACCESS_TOKEN, targetCredentials.refreshAccessToken().getTokenValue());
assertEquals(c.getTime().toInstant().truncatedTo(ChronoUnit.SECONDS).toEpochMilli(),
assertEquals(
c.getTime().toInstant().truncatedTo(ChronoUnit.SECONDS).toEpochMilli(),
targetCredentials.refreshAccessToken().getExpirationTimeMillis());
assertEquals(DEFAULT_IMPERSONATION_URL, mockTransportFactory.transport.getRequest().getUrl());
}
Expand Down Expand Up @@ -982,18 +984,19 @@ public static String getDefaultExpireTime() {
}

/**
Given a {@link Date}, it will return a string of the date
formatted like <b>yyyy-MM-dd'T'HH:mm:ss'Z'</b>
* Given a {@link Date}, it will return a string of the date formatted like
* <b>yyyy-MM-dd'T'HH:mm:ss'Z'</b>
*/
private static String getFormattedTime(final Date date) {
//Set timezone to GMT since that's the TZ used in the response from the service impersonation token exchange
// Set timezone to GMT since that's the TZ used in the response from the service impersonation
// token exchange
return getFormattedTime(date, TimeZone.getTimeZone("GMT"));
}

/**
Given a {@link Date} and a desired {@link TimeZone}, it will return a string of the date
formatted like <b>yyyy-MM-dd'T'HH:mm:ssX'</b> where X represents a timezone
code following RFC3339 standard
* Given a {@link Date} and a desired {@link TimeZone}, it will return a string of the date
* formatted like <b>yyyy-MM-dd'T'HH:mm:ssX'</b> where X represents a timezone code following
* RFC3339 standard
*/
private static String getFormattedTime(final Date date, final TimeZone timeZone) {
final DateFormat formatter = new SimpleDateFormat(RFC3339);
Expand Down

0 comments on commit be67ac7

Please sign in to comment.