Skip to content

Commit d2010a9

Browse files
authored
chore: Migrate tests to use JUnit5 (#1869)
* chore: migrate tests from JUnit 4 to JUnit 5 * fix: move @test annotations to separate lines * chore: Fix JUnit annotations being on the same line * chore: Add junit ignore deps for dependency plugin * chore: Fix samples imports to use new junit and truth * chore: Fix invalid test * chore: Address some sonatype code smells * chore: Fix lint issues * chore: Remove unnecessary old junit profile * chore: Add junit5 platform runner * chore: Add junit4 test dep back * chore: Add junit4 to ignore in dependency check * chore: Add junit4 to ignore in dependency check * chore: Add junit4 tests to CAB module * chore: Remove hamcrest dependency * chore: Revert Junit5 changes in samples directory * chore: Revert Junit5 changes in samples directory * chore: Remove end of file whitespace * chore: Remove whitespace
1 parent 28099c7 commit d2010a9

File tree

73 files changed

+1723
-1823
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1723
-1823
lines changed

appengine/javatests/com/google/auth/appengine/AppEngineCredentialsTest.java

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131

3232
package com.google.auth.appengine;
3333

34-
import static org.junit.Assert.assertArrayEquals;
35-
import static org.junit.Assert.assertEquals;
36-
import static org.junit.Assert.assertFalse;
37-
import static org.junit.Assert.assertNotNull;
38-
import static org.junit.Assert.assertNotSame;
39-
import static org.junit.Assert.assertTrue;
40-
import static org.junit.Assert.fail;
34+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
35+
import static org.junit.jupiter.api.Assertions.assertEquals;
36+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
37+
import static org.junit.jupiter.api.Assertions.assertNotNull;
38+
import static org.junit.jupiter.api.Assertions.assertNotSame;
39+
import static org.junit.jupiter.api.Assertions.assertTrue;
40+
import static org.junit.jupiter.api.Assertions.fail;
4141

4242
import com.google.auth.Credentials;
4343
import com.google.auth.oauth2.AccessToken;
@@ -51,21 +51,18 @@
5151
import java.util.Date;
5252
import java.util.List;
5353
import java.util.Map;
54-
import org.junit.Test;
55-
import org.junit.runner.RunWith;
56-
import org.junit.runners.JUnit4;
54+
import org.junit.jupiter.api.Test;
5755

5856
/** Unit tests for AppEngineCredentials */
59-
@RunWith(JUnit4.class)
60-
public class AppEngineCredentialsTest extends BaseSerializationTest {
57+
class AppEngineCredentialsTest extends BaseSerializationTest {
6158

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

6764
@Test
68-
public void constructor_usesAppIdentityService() throws IOException {
65+
void constructor_usesAppIdentityService() throws IOException {
6966
String expectedAccessToken = "ExpectedAccessToken";
7067

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

8582
@Test
86-
public void refreshAccessToken_sameAs() throws IOException {
83+
void refreshAccessToken_sameAs() throws IOException {
8784
String expectedAccessToken = "ExpectedAccessToken";
8885

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

10299
@Test
103-
public void getAccount_sameAs() throws IOException {
100+
void getAccount_sameAs() {
104101
MockAppIdentityService appIdentity = new MockAppIdentityService();
105102
appIdentity.setServiceAccountName(EXPECTED_ACCOUNT);
106103
AppEngineCredentials credentials =
@@ -112,7 +109,7 @@ public void getAccount_sameAs() throws IOException {
112109
}
113110

114111
@Test
115-
public void sign_sameAs() throws IOException {
112+
void sign_sameAs() {
116113
byte[] expectedSignature = {0xD, 0xE, 0xA, 0xD};
117114
MockAppIdentityService appIdentity = new MockAppIdentityService();
118115
appIdentity.setSignature(expectedSignature);
@@ -125,7 +122,7 @@ public void sign_sameAs() throws IOException {
125122
}
126123

127124
@Test
128-
public void createScoped_clonesWithScopes() throws IOException {
125+
void createScoped_clonesWithScopes() throws IOException {
129126
String expectedAccessToken = "ExpectedAccessToken";
130127
Collection<String> emptyScopes = Collections.emptyList();
131128

@@ -155,7 +152,7 @@ public void createScoped_clonesWithScopes() throws IOException {
155152
}
156153

157154
@Test
158-
public void equals_true() throws IOException {
155+
void equals_true() {
159156
Collection<String> emptyScopes = Collections.emptyList();
160157
MockAppIdentityService appIdentity = new MockAppIdentityService();
161158

@@ -169,13 +166,12 @@ public void equals_true() throws IOException {
169166
.setScopes(emptyScopes)
170167
.setAppIdentityService(appIdentity)
171168
.build();
172-
assertTrue(credentials.equals(credentials));
173-
assertTrue(credentials.equals(otherCredentials));
174-
assertTrue(otherCredentials.equals(credentials));
169+
assertEquals(credentials, otherCredentials);
170+
assertEquals(otherCredentials, credentials);
175171
}
176172

177173
@Test
178-
public void equals_false_scopes() throws IOException {
174+
void equals_false_scopes() {
179175
Collection<String> emptyScopes = Collections.emptyList();
180176
Collection<String> scopes = Collections.singleton("SomeScope");
181177
MockAppIdentityService appIdentity = new MockAppIdentityService();
@@ -190,12 +186,12 @@ public void equals_false_scopes() throws IOException {
190186
.setScopes(scopes)
191187
.setAppIdentityService(appIdentity)
192188
.build();
193-
assertFalse(credentials.equals(otherCredentials));
194-
assertFalse(otherCredentials.equals(credentials));
189+
assertNotEquals(credentials, otherCredentials);
190+
assertNotEquals(otherCredentials, credentials);
195191
}
196192

197193
@Test
198-
public void toString_containsFields() throws IOException {
194+
void toString_containsFields() {
199195
String expectedToString =
200196
String.format(
201197
"AppEngineCredentials{scopes=[%s], scopesRequired=%b, appIdentityServiceClassName=%s}",
@@ -213,7 +209,7 @@ public void toString_containsFields() throws IOException {
213209
}
214210

215211
@Test
216-
public void hashCode_equals() throws IOException {
212+
void hashCode_equals() {
217213
Collection<String> emptyScopes = Collections.emptyList();
218214
MockAppIdentityService appIdentity = new MockAppIdentityService();
219215
AppEngineCredentials credentials =
@@ -230,7 +226,7 @@ public void hashCode_equals() throws IOException {
230226
}
231227

232228
@Test
233-
public void serialize() throws IOException, ClassNotFoundException {
229+
void serialize() throws IOException, ClassNotFoundException {
234230
Collection<String> scopes = Collections.singleton("SomeScope");
235231
MockAppIdentityService appIdentity = new MockAppIdentityService();
236232
AppEngineCredentials credentials =
@@ -249,7 +245,7 @@ private static void assertContainsBearerToken(Map<String, List<String>> metadata
249245
assertNotNull(token);
250246
String expectedValue = "Bearer " + token;
251247
List<String> authorizations = metadata.get("Authorization");
252-
assertNotNull("Authorization headers not found", authorizations);
253-
assertTrue("Bearer token not found", authorizations.contains(expectedValue));
248+
assertNotNull(authorizations, "Authorization headers not found");
249+
assertTrue(authorizations.contains(expectedValue), "Bearer token not found");
254250
}
255251
}

appengine/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@
6464
<artifactId>guava</artifactId>
6565
</dependency>
6666
<dependency>
67-
<groupId>junit</groupId>
68-
<artifactId>junit</artifactId>
67+
<groupId>org.junit.jupiter</groupId>
68+
<artifactId>junit-jupiter-api</artifactId>
69+
<scope>test</scope>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.junit.jupiter</groupId>
73+
<artifactId>junit-jupiter-engine</artifactId>
6974
<scope>test</scope>
7075
</dependency>
7176
<dependency>

0 commit comments

Comments
 (0)