Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

package com.google.auth.appengine;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import com.google.auth.Credentials;
import com.google.auth.oauth2.AccessToken;
Expand All @@ -51,21 +51,18 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;

/** Unit tests for AppEngineCredentials */
@RunWith(JUnit4.class)
public class AppEngineCredentialsTest extends BaseSerializationTest {
class AppEngineCredentialsTest extends BaseSerializationTest {

private static Collection<String> SCOPES =
private static final Collection<String> SCOPES =
Collections.unmodifiableCollection(Arrays.asList("scope1", "scope2"));
private static final URI CALL_URI = URI.create("http://googleapis.com/testapi/v1/foo");
private static final String EXPECTED_ACCOUNT = "serviceAccount";

@Test
public void constructor_usesAppIdentityService() throws IOException {
void constructor_usesAppIdentityService() throws IOException {
String expectedAccessToken = "ExpectedAccessToken";

MockAppIdentityService appIdentity = new MockAppIdentityService();
Expand All @@ -83,7 +80,7 @@ public void constructor_usesAppIdentityService() throws IOException {
}

@Test
public void refreshAccessToken_sameAs() throws IOException {
void refreshAccessToken_sameAs() throws IOException {
String expectedAccessToken = "ExpectedAccessToken";

MockAppIdentityService appIdentity = new MockAppIdentityService();
Expand All @@ -100,7 +97,7 @@ public void refreshAccessToken_sameAs() throws IOException {
}

@Test
public void getAccount_sameAs() throws IOException {
void getAccount_sameAs() {
MockAppIdentityService appIdentity = new MockAppIdentityService();
appIdentity.setServiceAccountName(EXPECTED_ACCOUNT);
AppEngineCredentials credentials =
Expand All @@ -112,7 +109,7 @@ public void getAccount_sameAs() throws IOException {
}

@Test
public void sign_sameAs() throws IOException {
void sign_sameAs() {
byte[] expectedSignature = {0xD, 0xE, 0xA, 0xD};
MockAppIdentityService appIdentity = new MockAppIdentityService();
appIdentity.setSignature(expectedSignature);
Expand All @@ -125,7 +122,7 @@ public void sign_sameAs() throws IOException {
}

@Test
public void createScoped_clonesWithScopes() throws IOException {
void createScoped_clonesWithScopes() throws IOException {
String expectedAccessToken = "ExpectedAccessToken";
Collection<String> emptyScopes = Collections.emptyList();

Expand Down Expand Up @@ -155,7 +152,7 @@ public void createScoped_clonesWithScopes() throws IOException {
}

@Test
public void equals_true() throws IOException {
void equals_true() {
Collection<String> emptyScopes = Collections.emptyList();
MockAppIdentityService appIdentity = new MockAppIdentityService();

Expand All @@ -169,13 +166,12 @@ public void equals_true() throws IOException {
.setScopes(emptyScopes)
.setAppIdentityService(appIdentity)
.build();
assertTrue(credentials.equals(credentials));
assertTrue(credentials.equals(otherCredentials));
assertTrue(otherCredentials.equals(credentials));
assertEquals(credentials, otherCredentials);
assertEquals(otherCredentials, credentials);
}

@Test
public void equals_false_scopes() throws IOException {
void equals_false_scopes() {
Collection<String> emptyScopes = Collections.emptyList();
Collection<String> scopes = Collections.singleton("SomeScope");
MockAppIdentityService appIdentity = new MockAppIdentityService();
Expand All @@ -190,12 +186,12 @@ public void equals_false_scopes() throws IOException {
.setScopes(scopes)
.setAppIdentityService(appIdentity)
.build();
assertFalse(credentials.equals(otherCredentials));
assertFalse(otherCredentials.equals(credentials));
assertNotEquals(credentials, otherCredentials);
assertNotEquals(otherCredentials, credentials);
}

@Test
public void toString_containsFields() throws IOException {
void toString_containsFields() {
String expectedToString =
String.format(
"AppEngineCredentials{scopes=[%s], scopesRequired=%b, appIdentityServiceClassName=%s}",
Expand All @@ -213,7 +209,7 @@ public void toString_containsFields() throws IOException {
}

@Test
public void hashCode_equals() throws IOException {
void hashCode_equals() {
Collection<String> emptyScopes = Collections.emptyList();
MockAppIdentityService appIdentity = new MockAppIdentityService();
AppEngineCredentials credentials =
Expand All @@ -230,7 +226,7 @@ public void hashCode_equals() throws IOException {
}

@Test
public void serialize() throws IOException, ClassNotFoundException {
void serialize() throws IOException, ClassNotFoundException {
Collection<String> scopes = Collections.singleton("SomeScope");
MockAppIdentityService appIdentity = new MockAppIdentityService();
AppEngineCredentials credentials =
Expand All @@ -249,7 +245,7 @@ private static void assertContainsBearerToken(Map<String, List<String>> metadata
assertNotNull(token);
String expectedValue = "Bearer " + token;
List<String> authorizations = metadata.get("Authorization");
assertNotNull("Authorization headers not found", authorizations);
assertTrue("Bearer token not found", authorizations.contains(expectedValue));
assertNotNull(authorizations, "Authorization headers not found");
assertTrue(authorizations.contains(expectedValue), "Bearer token not found");
}
}
9 changes: 7 additions & 2 deletions appengine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Loading
Loading