Skip to content

Commit

Permalink
chore: migrate tests in oauth2_http module from JUnit4 to JUnit5 - th…
Browse files Browse the repository at this point in the history
…ird iteration (#756) (#764)
  • Loading branch information
Captain1653 committed Oct 11, 2021
1 parent d045247 commit e9dfaf9
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,16 @@

package com.google.auth.oauth2;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;

/** Test case for {@link IdTokenCredentials}. */
@RunWith(JUnit4.class)
public class IdTokenCredentialsTest extends BaseSerializationTest {
class IdTokenCredentialsTest extends BaseSerializationTest {

@Test
public void hashCode_equals() throws IOException {
void hashCode_equals() throws IOException {
ComputeEngineCredentialsTest.MockMetadataServerTransportFactory transportFactory =
new ComputeEngineCredentialsTest.MockMetadataServerTransportFactory();
transportFactory.transport.setIdToken(ComputeEngineCredentialsTest.STANDARD_ID_TOKEN);
Expand All @@ -69,7 +66,7 @@ public void hashCode_equals() throws IOException {
}

@Test
public void toString_equals() throws IOException {
void toString_equals() throws IOException {
ComputeEngineCredentialsTest.MockMetadataServerTransportFactory transportFactory =
new ComputeEngineCredentialsTest.MockMetadataServerTransportFactory();
transportFactory.transport.setIdToken(ComputeEngineCredentialsTest.STANDARD_ID_TOKEN);
Expand All @@ -95,7 +92,7 @@ public void toString_equals() throws IOException {
}

@Test
public void serialize() throws IOException, ClassNotFoundException {
void serialize() throws IOException, ClassNotFoundException {

ComputeEngineCredentialsTest.MockMetadataServerTransportFactory transportFactory =
new ComputeEngineCredentialsTest.MockMetadataServerTransportFactory();
Expand Down
25 changes: 11 additions & 14 deletions oauth2_http/javatests/com/google/auth/oauth2/IdTokenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,16 @@

package com.google.auth.oauth2;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
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.assertTrue;

import java.io.IOException;
import java.util.Date;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;

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

private static final String TOKEN_1 =
"eyJhbGciOiJSUzI1NiIsImtpZCI6IjM0OTRiMWU3ODZjZGFkMDkyZTQyMzc2NmJiZTM3ZjU0ZWQ4N2IyMmQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhdWQiOiJodHRwczovL2Zvby5iYXIiLCJhenAiOiJzdmMtMi00MjlAbWluZXJhbC1taW51dGlhLTgyMC5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsInN1YiI6IjEwMDE0NzEwNjk5Njc2NDQ3OTA4NSIsImVtYWlsIjoic3ZjLTItNDI5QG1pbmVyYWwtbWludXRpYS04MjAuaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiaWF0IjoxNTY1Mzg3NTM4LCJleHAiOjE1NjUzOTExMzh9.foo";
Expand All @@ -52,30 +49,30 @@ public class IdTokenTest extends BaseSerializationTest {
private static final Date EXPIRATION_DATE = new Date((long) 1565391138 * 1000);

@Test
public void constructor() throws IOException {
void constructor() throws IOException {
IdToken idToken = IdToken.create(TOKEN_1);
assertEquals(TOKEN_1, idToken.getTokenValue());
assertEquals(EXPIRATION_DATE, idToken.getExpirationTime());
}

@Test
public void equals_true() throws IOException {
void equals_true() throws IOException {
IdToken accessToken = IdToken.create(TOKEN_1);
IdToken otherAccessToken = IdToken.create(TOKEN_1);
assertTrue(accessToken.equals(otherAccessToken));
assertTrue(otherAccessToken.equals(accessToken));
}

@Test
public void equals_false_token() throws IOException {
void equals_false_token() throws IOException {
IdToken accessToken = IdToken.create(TOKEN_1);
IdToken otherAccessToken = IdToken.create(TOKEN_2);
assertFalse(accessToken.equals(otherAccessToken));
assertFalse(otherAccessToken.equals(accessToken));
}

@Test
public void toString_test() throws IOException {
void toString_test() throws IOException {
IdToken accessToken = IdToken.create(TOKEN_1);
String expectedToString =
String.format(
Expand All @@ -85,14 +82,14 @@ public void toString_test() throws IOException {
}

@Test
public void hashCode_equals() throws IOException {
void hashCode_equals() throws IOException {
IdToken accessToken = IdToken.create(TOKEN_1);
IdToken otherAccessToken = IdToken.create(TOKEN_1);
assertEquals(accessToken.hashCode(), otherAccessToken.hashCode());
}

@Test
public void serialize() throws IOException, ClassNotFoundException {
void serialize() throws IOException, ClassNotFoundException {
IdToken accessToken = IdToken.create(TOKEN_1);
IdToken deserializedAccessToken = serializeAndDeserialize(accessToken);
assertEquals(accessToken, deserializedAccessToken);
Expand Down

0 comments on commit e9dfaf9

Please sign in to comment.