Skip to content

Commit

Permalink
googleapis#992 Implement comments and add some builder setters which …
Browse files Browse the repository at this point in the history
…were missing
  • Loading branch information
qcastel committed Sep 8, 2022
1 parent 7783d1a commit be45e01
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
11 changes: 11 additions & 0 deletions oauth2_http/java/com/google/auth/oauth2/UserCredentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.io.ObjectInputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -441,6 +442,16 @@ public Builder setAccessToken(AccessToken token) {
return this;
}

public Builder setExpirationMargin(Duration expirationMargin) {
super.setExpirationMargin(expirationMargin);
return this;
}

public Builder setRefreshMargin(Duration refreshMargin) {
super.setRefreshMargin(refreshMargin);
return this;
}

public Builder setQuotaProjectId(String quotaProjectId) {
this.quotaProjectId = quotaProjectId;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -831,26 +834,24 @@ public void IdTokenCredentials_NoUserEmailScope_throws() throws IOException {
}

@Test
public void toBuilder() throws IOException {
final URI tokenServer1 = URI.create("https://foo1.com/bar");
AccessToken accessToken = new AccessToken(ACCESS_TOKEN, null);
public void UserCredentials_ToBuilder_CopyEveryAttributes() {
MockHttpTransportFactory httpTransportFactory = new MockHttpTransportFactory();
UserCredentials credentials =
UserCredentials.newBuilder()
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
.setRefreshToken(REFRESH_TOKEN)
.setAccessToken(accessToken)
.setHttpTransportFactory(httpTransportFactory)
.setTokenServerUri(tokenServer1)
.build();

credentials.toBuilder().build();
UserCredentials credentials = UserCredentials.newBuilder()
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
.setRefreshToken(REFRESH_TOKEN)
.setAccessToken(new AccessToken(ACCESS_TOKEN, new Date()))
.setHttpTransportFactory(httpTransportFactory)
.setTokenServerUri(URI.create("https://foo1.com/bar"))
.setQuotaProjectId(QUOTA_PROJECT)
.setExpirationMargin(Duration.of(10, ChronoUnit.SECONDS))
.setRefreshMargin(Duration.of(12, ChronoUnit.MINUTES))
.build();

UserCredentials otherCredentials = credentials.toBuilder().build();
assertEquals(credentials, otherCredentials);
}


static GenericJson writeUserJson(
String clientId, String clientSecret, String refreshToken, String quotaProjectId) {
GenericJson json = new GenericJson();
Expand Down

0 comments on commit be45e01

Please sign in to comment.