());
- fail("Exception should be thrown.");
- } catch (IllegalArgumentException e) {
- assertEquals(
- "A regional_cred_verification_url representing the GetCallerIdentity action URL must be specified.",
- e.getMessage());
- }
+ void credentialSource_missingRegionalCredVerificationUrl() {
+ IllegalArgumentException exception =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> new AwsCredentialSource(new HashMap<>()),
+ "Exception should be thrown.");
+ assertEquals(
+ "A regional_cred_verification_url representing the GetCallerIdentity action URL must be specified.",
+ exception.getMessage());
}
@Test
diff --git a/oauth2_http/javatests/com/google/auth/oauth2/AwsRequestSignerTest.java b/oauth2_http/javatests/com/google/auth/oauth2/AwsRequestSignerTest.java
index ebb14091e..f7bdfb084 100644
--- a/oauth2_http/javatests/com/google/auth/oauth2/AwsRequestSignerTest.java
+++ b/oauth2_http/javatests/com/google/auth/oauth2/AwsRequestSignerTest.java
@@ -31,7 +31,7 @@
package com.google.auth.oauth2;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonFactory;
@@ -42,8 +42,8 @@
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link AwsRequestSigner}.
@@ -51,7 +51,7 @@
* Examples of sigv4 signed requests:
* https://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html
*/
-public class AwsRequestSignerTest {
+class AwsRequestSignerTest {
private static final String DATE = "Mon, 09 Sep 2011 23:36:00 GMT";
private static final String X_AMZ_DATE = "20200811T065522Z";
@@ -62,15 +62,15 @@ public class AwsRequestSignerTest {
private AwsSecurityCredentials awsSecurityCredentials;
- @Before
- public void setUp() throws IOException {
+ @BeforeEach
+ void setUp() throws IOException {
awsSecurityCredentials = retrieveAwsSecurityCredentials();
}
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-vanilla.req
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-vanilla.sreq
@Test
- public void sign_getHost() {
+ void sign_getHost() {
String url = "https://host.foo.com";
Map headers = new HashMap<>();
@@ -101,7 +101,7 @@ public void sign_getHost() {
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-relative-relative.req
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-relative-relative.sreq
@Test
- public void sign_getHostRelativePath() {
+ void sign_getHostRelativePath() {
String url = "https://host.foo.com/foo/bar/../..";
Map headers = new HashMap<>();
@@ -132,7 +132,7 @@ public void sign_getHostRelativePath() {
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-slash-dot-slash.req
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-slash-dot-slash.sreq
@Test
- public void sign_getHostInvalidPath() {
+ void sign_getHostInvalidPath() {
String url = "https://host.foo.com/./";
Map headers = new HashMap<>();
@@ -163,7 +163,7 @@ public void sign_getHostInvalidPath() {
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-slash-pointless-dot.req
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-slash-pointless-dot.sreq
@Test
- public void sign_getHostDotPath() {
+ void sign_getHostDotPath() {
String url = "https://host.foo.com/./foo";
Map headers = new HashMap<>();
@@ -194,7 +194,7 @@ public void sign_getHostDotPath() {
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-utf8.req
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-utf8.sreq
@Test
- public void sign_getHostUtf8Path() {
+ void sign_getHostUtf8Path() {
String url = "https://host.foo.com/%E1%88%B4";
Map headers = new HashMap<>();
@@ -225,7 +225,7 @@ public void sign_getHostUtf8Path() {
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-vanilla-query-order-key-case.req
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-vanilla-query-order-key-case.sreq
@Test
- public void sign_getHostDuplicateQueryParam() {
+ void sign_getHostDuplicateQueryParam() {
String url = "https://host.foo.com/?foo=Zoo&foo=aha";
Map headers = new HashMap<>();
@@ -256,7 +256,7 @@ public void sign_getHostDuplicateQueryParam() {
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/post-header-key-sort.req
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/post-header-key-sort.sreq
@Test
- public void sign_postWithUpperCaseHeaderKey() {
+ void sign_postWithUpperCaseHeaderKey() {
String url = "https://host.foo.com/";
String headerKey = "ZOO";
String headerValue = "zoobar";
@@ -291,7 +291,7 @@ public void sign_postWithUpperCaseHeaderKey() {
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/post-header-value-case.req
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/post-header-value-case.sreq
@Test
- public void sign_postWithUpperCaseHeaderValue() {
+ void sign_postWithUpperCaseHeaderValue() {
String url = "https://host.foo.com/";
String headerKey = "zoo";
String headerValue = "ZOOBAR";
@@ -326,7 +326,7 @@ public void sign_postWithUpperCaseHeaderValue() {
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-header-value-trim.req
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/get-header-value-trim.sreq
@Test
- public void sign_postWithHeader() {
+ void sign_postWithHeader() {
String url = "https://host.foo.com/";
String headerKey = "p";
String headerValue = "phfft";
@@ -361,7 +361,7 @@ public void sign_postWithHeader() {
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/post-x-www-form-urlencoded.req
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/post-x-www-form-urlencoded.sreq
@Test
- public void sign_postWithBodyNoCustomHeaders() {
+ void sign_postWithBodyNoCustomHeaders() {
String url = "https://host.foo.com/";
String headerKey = "Content-Type";
String headerValue = "application/x-www-form-urlencoded";
@@ -397,7 +397,7 @@ public void sign_postWithBodyNoCustomHeaders() {
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/post-vanilla-query.req
// https://github.com/boto/botocore/blob/879f8440a4e9ace5d3cf145ce8b3d5e5ffb892ef/tests/unit/auth/aws4_testsuite/post-vanilla-query.sreq
@Test
- public void sign_postWithQueryString() {
+ void sign_postWithQueryString() {
String url = "https://host.foo.com/?foo=bar";
Map headers = new HashMap<>();
@@ -426,7 +426,7 @@ public void sign_postWithQueryString() {
}
@Test
- public void sign_getDescribeRegions() {
+ void sign_getDescribeRegions() {
String url = "https://ec2.us-east-2.amazonaws.com?Action=DescribeRegions&Version=2013-10-15";
Map additionalHeaders = new HashMap<>();
@@ -457,7 +457,7 @@ public void sign_getDescribeRegions() {
}
@Test
- public void sign_postGetCallerIdentity() {
+ void sign_postGetCallerIdentity() {
String url = "https://sts.us-east-2.amazonaws.com?Action=GetCallerIdentity&Version=2011-06-15";
Map additionalHeaders = new HashMap<>();
@@ -488,7 +488,7 @@ public void sign_postGetCallerIdentity() {
}
@Test
- public void sign_postGetCallerIdentityNoToken() {
+ void sign_postGetCallerIdentityNoToken() {
String url = "https://sts.us-east-2.amazonaws.com?Action=GetCallerIdentity&Version=2011-06-15";
AwsSecurityCredentials awsSecurityCredentialsWithoutToken =
diff --git a/oauth2_http/javatests/com/google/auth/oauth2/ClientIdTest.java b/oauth2_http/javatests/com/google/auth/oauth2/ClientIdTest.java
index d7a5ca015..1409507ea 100644
--- a/oauth2_http/javatests/com/google/auth/oauth2/ClientIdTest.java
+++ b/oauth2_http/javatests/com/google/auth/oauth2/ClientIdTest.java
@@ -31,25 +31,23 @@
package com.google.auth.oauth2;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.api.client.json.GenericJson;
import com.google.auth.TestUtils;
import java.io.IOException;
import java.io.InputStream;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Unit tests for ClientId */
-@RunWith(JUnit4.class)
-public class ClientIdTest {
+class ClientIdTest {
private static final String CLIENT_ID = "ya29.1.AADtN_UtlxN3PuGAxrN2XQnZTVRvDyVWnYq4I6dws";
private static final String CLIENT_SECRET = "jakuaL9YyieakhECKL2SwZcu";
@Test
- public void constructor() {
+ void constructor() {
ClientId clientId =
ClientId.newBuilder().setClientId(CLIENT_ID).setClientSecret(CLIENT_SECRET).build();
@@ -57,20 +55,22 @@ public void constructor() {
assertEquals(CLIENT_SECRET, clientId.getClientSecret());
}
- @Test(expected = NullPointerException.class)
- public void constructor_nullClientId_throws() {
- ClientId.newBuilder().setClientSecret(CLIENT_SECRET).build();
+ @Test
+ void constructor_nullClientId_throws() {
+ assertThrows(
+ NullPointerException.class,
+ () -> ClientId.newBuilder().setClientSecret(CLIENT_SECRET).build());
}
@Test
- public void constructor_nullClientSecret() {
+ void constructor_nullClientSecret() {
ClientId clientId = ClientId.newBuilder().setClientId(CLIENT_ID).build();
assertEquals(CLIENT_ID, clientId.getClientId());
assertNull(clientId.getClientSecret());
}
@Test
- public void fromJson_web() throws IOException {
+ void fromJson_web() throws IOException {
GenericJson json = writeClientIdJson("web", CLIENT_ID, CLIENT_SECRET);
ClientId clientId = ClientId.fromJson(json);
@@ -80,7 +80,7 @@ public void fromJson_web() throws IOException {
}
@Test
- public void fromJson_installed() throws IOException {
+ void fromJson_installed() throws IOException {
GenericJson json = writeClientIdJson("installed", CLIENT_ID, CLIENT_SECRET);
ClientId clientId = ClientId.fromJson(json);
@@ -90,7 +90,7 @@ public void fromJson_installed() throws IOException {
}
@Test
- public void fromJson_installedNoSecret() throws IOException {
+ void fromJson_installedNoSecret() throws IOException {
GenericJson json = writeClientIdJson("installed", CLIENT_ID, null);
ClientId clientId = ClientId.fromJson(json);
@@ -99,42 +99,44 @@ public void fromJson_installedNoSecret() throws IOException {
assertNull(clientId.getClientSecret());
}
- @Test(expected = IOException.class)
- public void fromJson_invalidType_throws() throws IOException {
+ @Test
+ void fromJson_invalidType_throws() {
GenericJson json = writeClientIdJson("invalid", CLIENT_ID, null);
- ClientId.fromJson(json);
+ assertThrows(IOException.class, () -> ClientId.fromJson(json));
}
- @Test(expected = IOException.class)
- public void fromJson_noClientId_throws() throws IOException {
+ @Test
+ void fromJson_noClientId_throws() {
GenericJson json = writeClientIdJson("web", null, null);
- ClientId.fromJson(json);
+ assertThrows(IOException.class, () -> ClientId.fromJson(json));
}
- @Test(expected = IOException.class)
- public void fromJson_zeroLengthClientId_throws() throws IOException {
+ @Test
+ void fromJson_zeroLengthClientId_throws() {
GenericJson json = writeClientIdJson("web", "", null);
- ClientId.fromJson(json);
+ assertThrows(IOException.class, () -> ClientId.fromJson(json));
}
@Test
- public void fromResource() throws IOException {
+ void fromResource() throws IOException {
ClientId clientId = ClientId.fromResource(ClientIdTest.class, "/client_secret.json");
assertEquals(CLIENT_ID, clientId.getClientId());
assertEquals(CLIENT_SECRET, clientId.getClientSecret());
}
- @Test(expected = NullPointerException.class)
- public void fromResource_badResource() throws IOException {
- ClientId.fromResource(ClientIdTest.class, "invalid.json");
+ @Test
+ void fromResource_badResource() {
+ assertThrows(
+ NullPointerException.class,
+ () -> ClientId.fromResource(ClientIdTest.class, "invalid.json"));
}
@Test
- public void fromStream() throws IOException {
+ void fromStream() throws IOException {
String text =
"{"
+ "\"web\": {"
@@ -155,7 +157,7 @@ public void fromStream() throws IOException {
}
@Test
- public void fromStream_invalidJson_doesNotThrow() throws IOException {
+ void fromStream_invalidJson_doesNotThrow() throws IOException {
String invalidJson =
"{"
+ "\"web\": {"
diff --git a/oauth2_http/javatests/com/google/auth/oauth2/CloudShellCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/CloudShellCredentialsTest.java
index 2dc075f17..110214508 100644
--- a/oauth2_http/javatests/com/google/auth/oauth2/CloudShellCredentialsTest.java
+++ b/oauth2_http/javatests/com/google/auth/oauth2/CloudShellCredentialsTest.java
@@ -31,10 +31,10 @@
package com.google.auth.oauth2;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.api.client.util.Clock;
import java.io.BufferedReader;
@@ -43,18 +43,14 @@
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Unit tests for CloudShellCredentials */
-@RunWith(JUnit4.class)
-public class CloudShellCredentialsTest extends BaseSerializationTest {
+class CloudShellCredentialsTest extends BaseSerializationTest {
@Test
- public void refreshAccessToken() throws IOException {
- final ServerSocket authSocket = new ServerSocket(0);
- try {
+ void refreshAccessToken() throws IOException {
+ try (ServerSocket authSocket = new ServerSocket(0)) {
Runnable serverTask =
new Runnable() {
@Override
@@ -80,13 +76,11 @@ public void run() {
GoogleCredentials creds =
CloudShellCredentials.newBuilder().setAuthPort(authSocket.getLocalPort()).build();
assertEquals("token", creds.refreshAccessToken().getTokenValue());
- } finally {
- authSocket.close();
}
}
@Test
- public void equals_true() throws IOException {
+ void equals_true() {
GoogleCredentials credentials = CloudShellCredentials.newBuilder().setAuthPort(42).build();
GoogleCredentials otherCredentials = CloudShellCredentials.newBuilder().setAuthPort(42).build();
assertTrue(credentials.equals(otherCredentials));
@@ -94,7 +88,7 @@ public void equals_true() throws IOException {
}
@Test
- public void equals_false_authPort() throws IOException {
+ void equals_false_authPort() {
GoogleCredentials credentials = CloudShellCredentials.newBuilder().setAuthPort(42).build();
GoogleCredentials otherCredentials = CloudShellCredentials.newBuilder().setAuthPort(43).build();
assertFalse(credentials.equals(otherCredentials));
@@ -102,21 +96,21 @@ public void equals_false_authPort() throws IOException {
}
@Test
- public void toString_containsFields() throws IOException {
+ void toString_containsFields() {
String expectedToString = String.format("CloudShellCredentials{authPort=%d}", 42);
GoogleCredentials credentials = CloudShellCredentials.newBuilder().setAuthPort(42).build();
assertEquals(expectedToString, credentials.toString());
}
@Test
- public void hashCode_equals() throws IOException {
+ void hashCode_equals() throws IOException {
GoogleCredentials credentials = CloudShellCredentials.newBuilder().setAuthPort(42).build();
GoogleCredentials otherCredentials = CloudShellCredentials.newBuilder().setAuthPort(42).build();
assertEquals(credentials.hashCode(), otherCredentials.hashCode());
}
@Test
- public void serialize() throws IOException, ClassNotFoundException {
+ void serialize() throws IOException, ClassNotFoundException {
GoogleCredentials credentials = CloudShellCredentials.newBuilder().setAuthPort(42).build();
GoogleCredentials deserializedCredentials = serializeAndDeserialize(credentials);
assertEquals(credentials, deserializedCredentials);
diff --git a/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java
index 41ff946b0..26b57113b 100644
--- a/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java
+++ b/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java
@@ -31,14 +31,14 @@
package com.google.auth.oauth2;
-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.assertNull;
-import static org.junit.Assert.assertSame;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.api.client.http.HttpStatusCodes;
import com.google.api.client.http.HttpTransport;
@@ -60,13 +60,10 @@
import java.util.Collections;
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;
/** Test case for {@link ComputeEngineCredentials}. */
-@RunWith(JUnit4.class)
-public class ComputeEngineCredentialsTest extends BaseSerializationTest {
+class ComputeEngineCredentialsTest extends BaseSerializationTest {
private static final URI CALL_URI = URI.create("http://googleapis.com/testapi/v1/foo");
@@ -119,7 +116,7 @@ public HttpTransport create() {
}
@Test
- public void createTokenUrlWithScopes_null_scopes() {
+ void createTokenUrlWithScopes_null_scopes() {
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setScopes(null).build();
Collection scopes = credentials.getScopes();
@@ -130,9 +127,9 @@ public void createTokenUrlWithScopes_null_scopes() {
}
@Test
- public void createTokenUrlWithScopes_empty_scopes() {
+ void createTokenUrlWithScopes_empty_scopes() {
ComputeEngineCredentials.Builder builder =
- ComputeEngineCredentials.newBuilder().setScopes(Collections.emptyList());
+ ComputeEngineCredentials.newBuilder().setScopes(Collections.emptyList());
ComputeEngineCredentials credentials = builder.build();
Collection scopes = credentials.getScopes();
String tokenUrlWithScopes = credentials.createTokenUrlWithScopes();
@@ -143,7 +140,7 @@ public void createTokenUrlWithScopes_empty_scopes() {
}
@Test
- public void createTokenUrlWithScopes_single_scope() {
+ void createTokenUrlWithScopes_single_scope() {
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setScopes(Arrays.asList("foo")).build();
String tokenUrlWithScopes = credentials.createTokenUrlWithScopes();
@@ -155,7 +152,7 @@ public void createTokenUrlWithScopes_single_scope() {
}
@Test
- public void createTokenUrlWithScopes_multiple_scopes() {
+ void createTokenUrlWithScopes_multiple_scopes() {
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder()
.setScopes(Arrays.asList(null, "foo", "", "bar"))
@@ -170,7 +167,7 @@ public void createTokenUrlWithScopes_multiple_scopes() {
}
@Test
- public void createTokenUrlWithScopes_defaultScopes() {
+ void createTokenUrlWithScopes_defaultScopes() {
ComputeEngineCredentials credentials = ComputeEngineCredentials.newBuilder().build();
credentials =
(ComputeEngineCredentials)
@@ -185,7 +182,7 @@ public void createTokenUrlWithScopes_defaultScopes() {
}
@Test
- public void createScoped() {
+ void createScoped() {
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setScopes(null).build();
ComputeEngineCredentials credentialsWithScopes =
@@ -197,7 +194,7 @@ public void createScoped() {
}
@Test
- public void createScoped_defaultScopes() {
+ void createScoped_defaultScopes() {
GoogleCredentials credentials =
ComputeEngineCredentials.create().createScoped(null, Arrays.asList("foo"));
Collection scopes = ((ComputeEngineCredentials) credentials).getScopes();
@@ -207,7 +204,7 @@ public void createScoped_defaultScopes() {
}
@Test
- public void getRequestMetadata_hasAccessToken() throws IOException {
+ void getRequestMetadata_hasAccessToken() throws IOException {
String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
transportFactory.transport.setAccessToken(accessToken);
@@ -219,44 +216,45 @@ public void getRequestMetadata_hasAccessToken() throws IOException {
}
@Test
- public void getRequestMetadata_missingServiceAccount_throws() {
+ void getRequestMetadata_missingServiceAccount_throws() {
String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
transportFactory.transport.setAccessToken(accessToken);
transportFactory.transport.setTokenRequestStatusCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
- try {
- credentials.getRequestMetadata(CALL_URI);
- fail("Expected error refreshing token.");
- } catch (IOException expected) {
- String message = expected.getMessage();
- assertTrue(message.contains(Integer.toString(HttpStatusCodes.STATUS_CODE_NOT_FOUND)));
- // Message should mention scopes are missing on the VM.
- assertTrue(message.contains("scope"));
- }
+
+ IOException exception =
+ assertThrows(
+ IOException.class,
+ () -> credentials.getRequestMetadata(CALL_URI),
+ "Expected error refreshing token.");
+ String message = exception.getMessage();
+ assertTrue(message.contains(Integer.toString(HttpStatusCodes.STATUS_CODE_NOT_FOUND)));
+ assertTrue(message.contains("scope"), "Message should mention scopes are missing on the VM.");
}
@Test
- public void getRequestMetadata_serverError_throws() {
+ void getRequestMetadata_serverError_throws() {
String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
transportFactory.transport.setAccessToken(accessToken);
transportFactory.transport.setTokenRequestStatusCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR);
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
- try {
- credentials.getRequestMetadata(CALL_URI);
- fail("Expected error refreshing token.");
- } catch (IOException expected) {
- String message = expected.getMessage();
- assertTrue(message.contains(Integer.toString(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)));
- assertTrue(message.contains("Unexpected"));
- }
+
+ IOException exception =
+ assertThrows(
+ IOException.class,
+ () -> credentials.getRequestMetadata(CALL_URI),
+ "Expected error refreshing token.");
+ String message = exception.getMessage();
+ assertTrue(message.contains(Integer.toString(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)));
+ assertTrue(message.contains("Unexpected"));
}
@Test
- public void equals_true() throws IOException {
+ void equals_true() {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
@@ -267,7 +265,7 @@ public void equals_true() throws IOException {
}
@Test
- public void equals_false_transportFactory() throws IOException {
+ void equals_false_transportFactory() {
MockHttpTransportFactory httpTransportFactory = new MockHttpTransportFactory();
MockMetadataServerTransportFactory serverTransportFactory =
new MockMetadataServerTransportFactory();
@@ -282,7 +280,7 @@ public void equals_false_transportFactory() throws IOException {
}
@Test
- public void toString_containsFields() throws IOException {
+ void toString_containsFields() {
MockMetadataServerTransportFactory serverTransportFactory =
new MockMetadataServerTransportFactory();
String expectedToString =
@@ -297,7 +295,7 @@ public void toString_containsFields() throws IOException {
}
@Test
- public void hashCode_equals() throws IOException {
+ void hashCode_equals() throws IOException {
MockMetadataServerTransportFactory serverTransportFactory =
new MockMetadataServerTransportFactory();
ComputeEngineCredentials credentials =
@@ -312,7 +310,7 @@ public void hashCode_equals() throws IOException {
}
@Test
- public void serialize() throws IOException, ClassNotFoundException {
+ void serialize() throws IOException, ClassNotFoundException {
MockMetadataServerTransportFactory serverTransportFactory =
new MockMetadataServerTransportFactory();
ComputeEngineCredentials credentials =
@@ -333,7 +331,7 @@ public void serialize() throws IOException, ClassNotFoundException {
}
@Test
- public void getAccount_sameAs() throws IOException {
+ void getAccount_sameAs() {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
String defaultAccountEmail = "mail@mail.com";
@@ -345,7 +343,7 @@ public void getAccount_sameAs() throws IOException {
}
@Test
- public void getAccount_missing_throws() {
+ void getAccount_missing_throws() {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
String defaultAccountEmail = "mail@mail.com";
@@ -370,18 +368,18 @@ public LowLevelHttpResponse execute() throws IOException {
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
- try {
- credentials.getAccount();
- fail("Fetching default service account should have failed");
- } catch (RuntimeException e) {
- assertEquals("Failed to get service account", e.getMessage());
- assertNotNull(e.getCause());
- assertTrue(e.getCause().getMessage().contains("404"));
- }
+ RuntimeException exception =
+ assertThrows(
+ RuntimeException.class,
+ credentials::getAccount,
+ "Fetching default service account should have failed");
+ assertEquals("Failed to get service account", exception.getMessage());
+ assertNotNull(exception.getCause());
+ assertTrue(exception.getCause().getMessage().contains("404"));
}
@Test
- public void getAccount_emptyContent_throws() {
+ void getAccount_emptyContent_throws() {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
String defaultAccountEmail = "mail@mail.com";
@@ -405,18 +403,18 @@ public LowLevelHttpResponse execute() throws IOException {
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
- try {
- credentials.getAccount();
- fail("Fetching default service account should have failed");
- } catch (RuntimeException e) {
- assertEquals("Failed to get service account", e.getMessage());
- assertNotNull(e.getCause());
- assertTrue(e.getCause().getMessage().contains("Empty content"));
- }
+ RuntimeException exception =
+ assertThrows(
+ RuntimeException.class,
+ credentials::getAccount,
+ "Fetching default service account should have failed");
+ assertEquals("Failed to get service account", exception.getMessage());
+ assertNotNull(exception.getCause());
+ assertTrue(exception.getCause().getMessage().contains("Empty content"));
}
@Test
- public void sign_sameAs() throws IOException {
+ void sign_sameAs() {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
final String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
String defaultAccountEmail = "mail@mail.com";
@@ -432,7 +430,7 @@ public void sign_sameAs() throws IOException {
}
@Test
- public void sign_getAccountFails() throws IOException {
+ void sign_getAccountFails() {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
final String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
byte[] expectedSignature = {0xD, 0xE, 0xA, 0xD};
@@ -442,17 +440,14 @@ public void sign_getAccountFails() throws IOException {
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
- try {
- credentials.sign(expectedSignature);
- fail();
- } catch (SigningException ex) {
- assertNotNull(ex.getMessage());
- assertNotNull(ex.getCause());
- }
+ SigningException exception =
+ assertThrows(SigningException.class, () -> credentials.sign(expectedSignature));
+ assertNotNull(exception.getMessage());
+ assertNotNull(exception.getCause());
}
@Test
- public void sign_accessDenied_throws() {
+ void sign_accessDenied_throws() {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
final String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
String defaultAccountEmail = "mail@mail.com";
@@ -481,19 +476,17 @@ public LowLevelHttpResponse execute() throws IOException {
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
- try {
- byte[] bytes = {0xD, 0xE, 0xA, 0xD};
- credentials.sign(bytes);
- fail("Signing should have failed");
- } catch (SigningException e) {
- assertEquals("Failed to sign the provided bytes", e.getMessage());
- assertNotNull(e.getCause());
- assertTrue(e.getCause().getMessage().contains("403"));
- }
+ byte[] bytes = {0xD, 0xE, 0xA, 0xD};
+ SigningException exception =
+ assertThrows(
+ SigningException.class, () -> credentials.sign(bytes), "Signing should have failed");
+ assertEquals("Failed to sign the provided bytes", exception.getMessage());
+ assertNotNull(exception.getCause());
+ assertTrue(exception.getCause().getMessage().contains("403"));
}
@Test
- public void sign_serverError_throws() {
+ void sign_serverError_throws() {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
final String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
String defaultAccountEmail = "mail@mail.com";
@@ -522,19 +515,17 @@ public LowLevelHttpResponse execute() throws IOException {
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
- try {
- byte[] bytes = {0xD, 0xE, 0xA, 0xD};
- credentials.sign(bytes);
- fail("Signing should have failed");
- } catch (SigningException e) {
- assertEquals("Failed to sign the provided bytes", e.getMessage());
- assertNotNull(e.getCause());
- assertTrue(e.getCause().getMessage().contains("500"));
- }
+ byte[] bytes = {0xD, 0xE, 0xA, 0xD};
+ SigningException exception =
+ assertThrows(
+ SigningException.class, () -> credentials.sign(bytes), "Signing should have failed");
+ assertEquals("Failed to sign the provided bytes", exception.getMessage());
+ assertNotNull(exception.getCause());
+ assertTrue(exception.getCause().getMessage().contains("500"));
}
@Test
- public void sign_emptyContent_throws() {
+ void sign_emptyContent_throws() {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
String defaultAccountEmail = "mail@mail.com";
@@ -562,19 +553,17 @@ public LowLevelHttpResponse execute() throws IOException {
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
- try {
- byte[] bytes = {0xD, 0xE, 0xA, 0xD};
- credentials.sign(bytes);
- fail("Signing should have failed");
- } catch (SigningException e) {
- assertEquals("Failed to sign the provided bytes", e.getMessage());
- assertNotNull(e.getCause());
- assertTrue(e.getCause().getMessage().contains("Empty content"));
- }
+ byte[] bytes = {0xD, 0xE, 0xA, 0xD};
+ SigningException exception =
+ assertThrows(
+ SigningException.class, () -> credentials.sign(bytes), "Signing should have failed");
+ assertEquals("Failed to sign the provided bytes", exception.getMessage());
+ assertNotNull(exception.getCause());
+ assertTrue(exception.getCause().getMessage().contains("Empty content"));
}
@Test
- public void idTokenWithAudience_sameAs() throws IOException {
+ void idTokenWithAudience_sameAs() throws IOException {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
transportFactory.transport.setIdToken(STANDARD_ID_TOKEN);
ComputeEngineCredentials credentials =
@@ -595,7 +584,7 @@ public void idTokenWithAudience_sameAs() throws IOException {
}
@Test
- public void idTokenWithAudience_standard() throws IOException {
+ void idTokenWithAudience_standard() throws IOException {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
@@ -614,7 +603,7 @@ public void idTokenWithAudience_standard() throws IOException {
@Test
@SuppressWarnings("unchecked")
- public void idTokenWithAudience_full() throws IOException {
+ void idTokenWithAudience_full() throws IOException {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
@@ -628,16 +617,14 @@ public void idTokenWithAudience_full() throws IOException {
.build();
tokenCredential.refresh();
Payload p = tokenCredential.getIdToken().getJsonWebSignature().getPayload();
- if (!p.containsKey("google")) {
- assertFalse("Full ID Token format not provided", false);
- }
+ assertTrue(p.containsKey("google"), "Full ID Token format not provided");
ArrayMap googleClaim = (ArrayMap) p.get("google");
- assert (googleClaim.containsKey("compute_engine"));
+ assertTrue(googleClaim.containsKey("compute_engine"));
}
@Test
@SuppressWarnings("unchecked")
- public void idTokenWithAudience_license() throws IOException {
+ void idTokenWithAudience_license() throws IOException {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
ComputeEngineCredentials credentials =
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
@@ -653,10 +640,8 @@ public void idTokenWithAudience_license() throws IOException {
.build();
tokenCredential.refresh();
Payload p = tokenCredential.getIdToken().getJsonWebSignature().getPayload();
- if (!p.containsKey("google")) {
- assertFalse("Full ID Token format not provided", false);
- }
+ assertTrue(p.containsKey("google"), "Full ID Token format not provided");
ArrayMap googleClaim = (ArrayMap) p.get("google");
- assert (googleClaim.containsKey("license"));
+ assertTrue(googleClaim.containsKey("license"));
}
}
diff --git a/oauth2_http/javatests/com/google/auth/oauth2/CredentialAccessBoundaryTest.java b/oauth2_http/javatests/com/google/auth/oauth2/CredentialAccessBoundaryTest.java
index ac042e065..a43f8ac7a 100644
--- a/oauth2_http/javatests/com/google/auth/oauth2/CredentialAccessBoundaryTest.java
+++ b/oauth2_http/javatests/com/google/auth/oauth2/CredentialAccessBoundaryTest.java
@@ -31,25 +31,22 @@
package com.google.auth.oauth2;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.auth.oauth2.CredentialAccessBoundary.AccessBoundaryRule;
import com.google.auth.oauth2.CredentialAccessBoundary.AccessBoundaryRule.AvailabilityCondition;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
+import org.junit.jupiter.api.Test;
/** Tests for {@link CredentialAccessBoundary} and encompassing classes. */
-@RunWith(JUnit4.class)
-public class CredentialAccessBoundaryTest {
+class CredentialAccessBoundaryTest {
@Test
- public void credentialAccessBoundary() {
+ void credentialAccessBoundary() {
AvailabilityCondition availabilityCondition =
AvailabilityCondition.newBuilder().setExpression("expression").build();
@@ -92,27 +89,25 @@ public void credentialAccessBoundary() {
}
@Test
- public void credentialAccessBoundary_nullRules_throws() {
- try {
- CredentialAccessBoundary.newBuilder().build();
- fail("Should fail.");
- } catch (NullPointerException e) {
- // Expected.
- }
+ void credentialAccessBoundary_nullRules_throws() {
+ assertThrows(
+ NullPointerException.class,
+ () -> CredentialAccessBoundary.newBuilder().build(),
+ "Should fail.");
}
@Test
- public void credentialAccessBoundary_withoutRules_throws() {
- try {
- CredentialAccessBoundary.newBuilder().setRules(new ArrayList()).build();
- fail("Should fail.");
- } catch (IllegalArgumentException e) {
- assertEquals("At least one access boundary rule must be provided.", e.getMessage());
- }
+ void credentialAccessBoundary_withoutRules_throws() {
+ IllegalArgumentException exception =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> CredentialAccessBoundary.newBuilder().setRules(new ArrayList<>()).build(),
+ "Should fail.");
+ assertEquals("At least one access boundary rule must be provided.", exception.getMessage());
}
@Test
- public void credentialAccessBoundary_ruleCountExceeded_throws() {
+ void credentialAccessBoundary_ruleCountExceeded_throws() {
AccessBoundaryRule rule =
AccessBoundaryRule.newBuilder()
.setAvailableResource("resource")
@@ -124,16 +119,14 @@ public void credentialAccessBoundary_ruleCountExceeded_throws() {
builder.addRule(rule);
}
- try {
- builder.build();
- fail("Should fail.");
- } catch (IllegalArgumentException e) {
- assertEquals("The provided list has more than 10 access boundary rules.", e.getMessage());
- }
+ IllegalArgumentException exception =
+ assertThrows(IllegalArgumentException.class, builder::build, "Should fail.");
+ assertEquals(
+ "The provided list has more than 10 access boundary rules.", exception.getMessage());
}
@Test
- public void credentialAccessBoundary_toJson() {
+ void credentialAccessBoundary_toJson() {
AvailabilityCondition availabilityCondition =
AvailabilityCondition.newBuilder()
.setExpression("expression")
@@ -172,7 +165,7 @@ public void credentialAccessBoundary_toJson() {
}
@Test
- public void accessBoundaryRule_allFields() {
+ void accessBoundaryRule_allFields() {
AvailabilityCondition availabilityCondition =
AvailabilityCondition.newBuilder().setExpression("expression").build();
@@ -192,7 +185,7 @@ public void accessBoundaryRule_allFields() {
}
@Test
- public void accessBoundaryRule_requiredFields() {
+ void accessBoundaryRule_requiredFields() {
AccessBoundaryRule rule =
AccessBoundaryRule.newBuilder()
.setAvailableResource("resource")
@@ -206,79 +199,83 @@ public void accessBoundaryRule_requiredFields() {
}
@Test
- public void accessBoundaryRule_withEmptyAvailableResource_throws() {
- try {
- AccessBoundaryRule.newBuilder()
- .setAvailableResource("")
- .addAvailablePermission("permission")
- .build();
- fail("Should fail.");
- } catch (IllegalArgumentException e) {
- assertEquals("The provided availableResource is empty.", e.getMessage());
- }
+ void accessBoundaryRule_withEmptyAvailableResource_throws() {
+ IllegalArgumentException exception =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ AccessBoundaryRule.newBuilder()
+ .setAvailableResource("")
+ .addAvailablePermission("permission")
+ .build();
+ },
+ "Should fail.");
+ assertEquals("The provided availableResource is empty.", exception.getMessage());
}
@Test
- public void accessBoundaryRule_withoutAvailableResource_throws() {
- try {
- AccessBoundaryRule.newBuilder().addAvailablePermission("permission").build();
- fail("Should fail.");
- } catch (NullPointerException e) {
- // Expected.
- }
+ void accessBoundaryRule_withoutAvailableResource_throws() {
+ assertThrows(
+ NullPointerException.class,
+ () -> AccessBoundaryRule.newBuilder().addAvailablePermission("permission").build(),
+ "Should fail.");
}
@Test
- public void accessBoundaryRule_withoutAvailablePermissions_throws() {
- try {
- AccessBoundaryRule.newBuilder().setAvailableResource("resource").build();
- fail("Should fail.");
- } catch (NullPointerException e) {
- // Expected.
- }
+ void accessBoundaryRule_withoutAvailablePermissions_throws() {
+ assertThrows(
+ NullPointerException.class,
+ () -> AccessBoundaryRule.newBuilder().setAvailableResource("resource").build(),
+ "Should fail.");
}
@Test
- public void accessBoundaryRule_withEmptyAvailablePermissions_throws() {
- try {
- AccessBoundaryRule.newBuilder()
- .setAvailableResource("resource")
- .setAvailablePermissions(new ArrayList())
- .build();
- fail("Should fail.");
- } catch (IllegalArgumentException e) {
- assertEquals("The list of provided availablePermissions is empty.", e.getMessage());
- }
+ void accessBoundaryRule_withEmptyAvailablePermissions_throws() {
+ IllegalArgumentException exception =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ AccessBoundaryRule.newBuilder()
+ .setAvailableResource("resource")
+ .setAvailablePermissions(new ArrayList())
+ .build();
+ },
+ "Should fail.");
+ assertEquals("The list of provided availablePermissions is empty.", exception.getMessage());
}
@Test
- public void accessBoundaryRule_withNullAvailablePermissions_throws() {
- try {
- AccessBoundaryRule.newBuilder()
- .setAvailableResource("resource")
- .addAvailablePermission(null)
- .build();
- fail("Should fail.");
- } catch (IllegalArgumentException e) {
- assertEquals("One of the provided available permissions is null.", e.getMessage());
- }
+ void accessBoundaryRule_withNullAvailablePermissions_throws() {
+ IllegalArgumentException exception =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ AccessBoundaryRule.newBuilder()
+ .setAvailableResource("resource")
+ .addAvailablePermission(null)
+ .build();
+ },
+ "Should fail.");
+ assertEquals("One of the provided available permissions is null.", exception.getMessage());
}
@Test
- public void accessBoundaryRule_withEmptyAvailablePermission_throws() {
- try {
- AccessBoundaryRule.newBuilder()
- .setAvailableResource("resource")
- .addAvailablePermission("")
- .build();
- fail("Should fail.");
- } catch (IllegalArgumentException e) {
- assertEquals("One of the provided available permissions is empty.", e.getMessage());
- }
+ void accessBoundaryRule_withEmptyAvailablePermission_throws() {
+ IllegalArgumentException exception =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ AccessBoundaryRule.newBuilder()
+ .setAvailableResource("resource")
+ .addAvailablePermission("")
+ .build();
+ },
+ "Should fail.");
+ assertEquals("One of the provided available permissions is empty.", exception.getMessage());
}
@Test
- public void availabilityCondition_allFields() {
+ void availabilityCondition_allFields() {
AvailabilityCondition availabilityCondition =
AvailabilityCondition.newBuilder()
.setExpression("expression")
@@ -292,7 +289,7 @@ public void availabilityCondition_allFields() {
}
@Test
- public void availabilityCondition_expressionOnly() {
+ void availabilityCondition_expressionOnly() {
AvailabilityCondition availabilityCondition =
AvailabilityCondition.newBuilder().setExpression("expression").build();
@@ -302,22 +299,20 @@ public void availabilityCondition_expressionOnly() {
}
@Test
- public void availabilityCondition_nullExpression_throws() {
- try {
- AvailabilityCondition.newBuilder().setExpression(null).build();
- fail("Should fail.");
- } catch (NullPointerException e) {
- // Expected.
- }
+ void availabilityCondition_nullExpression_throws() {
+ assertThrows(
+ NullPointerException.class,
+ () -> AvailabilityCondition.newBuilder().setExpression(null).build(),
+ "Should fail.");
}
@Test
- public void availabilityCondition_emptyExpression_throws() {
- try {
- AvailabilityCondition.newBuilder().setExpression("").build();
- fail("Should fail.");
- } catch (IllegalArgumentException e) {
- assertEquals("The provided expression is empty.", e.getMessage());
- }
+ void availabilityCondition_emptyExpression_throws() {
+ IllegalArgumentException exception =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> AvailabilityCondition.newBuilder().setExpression("").build(),
+ "Should fail.");
+ assertEquals("The provided expression is empty.", exception.getMessage());
}
}
diff --git a/oauth2_http/javatests/com/google/auth/oauth2/functional/FTServiceAccountCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/functional/FTServiceAccountCredentialsTest.java
index e70db86a2..afe7eac7d 100644
--- a/oauth2_http/javatests/com/google/auth/oauth2/functional/FTServiceAccountCredentialsTest.java
+++ b/oauth2_http/javatests/com/google/auth/oauth2/functional/FTServiceAccountCredentialsTest.java
@@ -31,11 +31,11 @@
package com.google.auth.oauth2.functional;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
@@ -49,11 +49,10 @@
import com.google.auth.oauth2.IdToken;
import com.google.auth.oauth2.IdTokenCredentials;
import com.google.auth.oauth2.IdTokenProvider;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public final class FTServiceAccountCredentialsTest {
+class FTServiceAccountCredentialsTest {
private final String cloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform";
private final String cloudTasksUrl =
@@ -66,19 +65,19 @@ public final class FTServiceAccountCredentialsTest {
"https://compute.googleapis.com/compute/v1/projects/gcloud-devel/zones/us-central1-a/instances";
@Test
- public void NoScopeNoAudienceComputeTest() throws Exception {
+ void NoScopeNoAudienceComputeTest() throws Exception {
HttpResponse response = executeRequestWithCredentialsWithoutScope(computeUrl);
assertEquals(200, response.getStatusCode());
}
@Test
- public void NoScopeNoAudienceBigQueryTest() throws Exception {
+ void NoScopeNoAudienceBigQueryTest() throws Exception {
HttpResponse response = executeRequestWithCredentialsWithoutScope(bigQueryUrl);
assertEquals(200, response.getStatusCode());
}
@Test
- public void NoScopeNoAudienceOnePlatformTest() throws Exception {
+ void NoScopeNoAudienceOnePlatformTest() throws Exception {
HttpResponse response = executeRequestWithCredentialsWithoutScope(cloudTasksUrl);
assertEquals(200, response.getStatusCode());
}
@@ -86,7 +85,7 @@ public void NoScopeNoAudienceOnePlatformTest() throws Exception {
// TODO: add Storage case
@Test
- public void AudienceSetNoScopeTest() throws Exception {
+ void AudienceSetNoScopeTest() throws Exception {
final GoogleCredentials credentials = GoogleCredentials.getApplicationDefault();
IdTokenCredentials tokenCredential =
@@ -107,62 +106,62 @@ public void AudienceSetNoScopeTest() throws Exception {
}
@Test
- public void ScopeSetNoAudienceStorageTest() throws Exception {
+ void ScopeSetNoAudienceStorageTest() throws Exception {
HttpResponse response = executeRequestWithCredentialsWithScope(storageUrl, cloudPlatformScope);
assertEquals(200, response.getStatusCode());
}
@Test
- public void ScopeSetNoAudienceComputeTest() throws Exception {
+ void ScopeSetNoAudienceComputeTest() throws Exception {
HttpResponse response = executeRequestWithCredentialsWithScope(computeUrl, cloudPlatformScope);
assertEquals(200, response.getStatusCode());
}
@Test
- public void ScopeSetNoAudienceBigQueryTest() throws Exception {
+ void ScopeSetNoAudienceBigQueryTest() throws Exception {
HttpResponse response = executeRequestWithCredentialsWithScope(bigQueryUrl, cloudPlatformScope);
assertEquals(200, response.getStatusCode());
}
@Test
- public void ScopeSetNoAudienceOnePlatformTest() throws Exception {
+ void ScopeSetNoAudienceOnePlatformTest() throws Exception {
HttpResponse response =
executeRequestWithCredentialsWithScope(cloudTasksUrl, cloudPlatformScope);
assertEquals(200, response.getStatusCode());
}
@Test
- public void WrongScopeComputeTest() throws Exception {
+ void WrongScopeComputeTest() throws Exception {
executeRequestWrongScope(computeUrl);
}
@Test
- public void WrongScopeStorageTest() throws Exception {
+ void WrongScopeStorageTest() throws Exception {
executeRequestWrongScope(storageUrl);
}
@Test
- public void WrongScopeBigQueryTest() throws Exception {
+ void WrongScopeBigQueryTest() throws Exception {
executeRequestWrongScope(bigQueryUrl);
}
@Test
- public void WrongScopeOnePlatformTest() throws Exception {
+ void WrongScopeOnePlatformTest() throws Exception {
executeRequestWrongScope(cloudTasksUrl);
}
- private void executeRequestWrongScope(String serviceUri)
- throws FileNotFoundException, IOException {
+ private void executeRequestWrongScope(String serviceUri) {
String expectedMessage = "403 Forbidden";
- try {
- executeRequestWithCredentialsWithScope(
- serviceUri, "https://www.googleapis.com/auth/adexchange.buyer");
- fail("Should throw exception: " + expectedMessage);
- } catch (IOException expected) {
- assertTrue(expected.getMessage().contains(expectedMessage));
- }
+ IOException exception =
+ assertThrows(
+ IOException.class,
+ () ->
+ executeRequestWithCredentialsWithScope(
+ serviceUri, "https://www.googleapis.com/auth/adexchange.buyer"),
+ "Should throw exception: " + expectedMessage);
+ assertTrue(exception.getMessage().contains(expectedMessage));
}
private HttpResponse executeRequestWithCredentialsWithoutScope(String serviceUrl)
diff --git a/oauth2_http/pom.xml b/oauth2_http/pom.xml
index 6852cce09..0e59a9890 100644
--- a/oauth2_http/pom.xml
+++ b/oauth2_http/pom.xml
@@ -81,7 +81,6 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M5
@@ -90,13 +89,6 @@
sponge_log
-
-
- org.apache.maven.surefire
- surefire-junit47
- 3.0.0-M5
-
-
org.apache.maven.plugins
@@ -143,6 +135,11 @@
junit
test