Skip to content

Commit 719f8fd

Browse files
lqiu96AbgarSim
andauthored
chore: Migrate tests to JUnit5 (#4052)
* feat: Migrate to JUnit 5 and add parallel test execution * feat: Migrate tests to JUnit5 * chore: Add surefire-junit-platform dep for ITs * chore: Fix broken tests * chore: Upgrade existing integration tests to JUnit 5 syntax and features * chore: Upgrade ITNightlyBigQueryTest to JUnit 5 features and package-private * chore: Make the tests package-private * feat: migrate tests to JUnit 5 assertThrows and static imports * chore: Remove wildcard imports * chore: revert samples to use junit4 * chore: Address code comments * chore: Close connection after test --------- Co-authored-by: AbgarSim <[email protected]>
1 parent fac16a8 commit 719f8fd

File tree

90 files changed

+1576
-1598
lines changed

Some content is hidden

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

90 files changed

+1576
-1598
lines changed

google-cloud-bigquery/pom.xml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,18 @@
162162
<scope>test</scope>
163163
</dependency>
164164
<dependency>
165-
<groupId>junit</groupId>
166-
<artifactId>junit</artifactId>
165+
<groupId>org.junit.jupiter</groupId>
166+
<artifactId>junit-jupiter-api</artifactId>
167+
<scope>test</scope>
168+
</dependency>
169+
<dependency>
170+
<groupId>org.junit.jupiter</groupId>
171+
<artifactId>junit-jupiter-engine</artifactId>
172+
<scope>test</scope>
173+
</dependency>
174+
<dependency>
175+
<groupId>org.mockito</groupId>
176+
<artifactId>mockito-junit-jupiter</artifactId>
167177
<scope>test</scope>
168178
</dependency>
169179
<dependency>
@@ -207,6 +217,20 @@
207217

208218
<build>
209219
<plugins>
220+
<!-- Declare `surefire-junit-platform` here as shared-configs pulls in surefire-junit47 -->
221+
<!-- which is for JUnit4 and not JUnit5. Declare this here until upstream is fixed -->
222+
<plugin>
223+
<groupId>org.apache.maven.plugins</groupId>
224+
<artifactId>maven-failsafe-plugin</artifactId>
225+
<version>3.5.2</version>
226+
<dependencies>
227+
<dependency>
228+
<groupId>org.apache.maven.surefire</groupId>
229+
<artifactId>surefire-junit-platform</artifactId>
230+
<version>${surefire.version}</version>
231+
</dependency>
232+
</dependencies>
233+
</plugin>
210234
<plugin>
211235
<!-- Allow script to run, so we can run benchmarks. -->
212236
<groupId>org.codehaus.mojo</groupId>

google-cloud-bigquery/src/test/java/MetadataCacheStatsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
package com.google.cloud.bigquery;
1818

19-
import static org.junit.Assert.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
2020

2121
import com.google.api.services.bigquery.model.MetadataCacheStatistics;
2222
import com.google.common.collect.ImmutableList;
2323
import com.google.common.truth.Truth;
2424
import java.util.List;
2525
import java.util.stream.Collectors;
26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

28-
public class MetadataCacheStatsTest {
28+
class MetadataCacheStatsTest {
2929
private static List<com.google.api.services.bigquery.model.TableMetadataCacheUsage>
3030
TABLE_METADATA_CACHE_USAGE_PB_LIST =
3131
ImmutableList.of(
@@ -44,7 +44,7 @@ public class MetadataCacheStatsTest {
4444
new MetadataCacheStatistics().setTableMetadataCacheUsage(TABLE_METADATA_CACHE_USAGE_PB_LIST);
4545

4646
@Test
47-
public void testToPbAndFromPb() {
47+
void testToPbAndFromPb() {
4848
assertEquals(METADATA_CACHE_STATISTICS_PB, METADATA_CACHE_STATS.toPb());
4949
compareMetadataCacheStats(
5050
METADATA_CACHE_STATS, MetadataCacheStats.fromPb(METADATA_CACHE_STATISTICS_PB));

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.cloud.bigquery;
1818

19-
import static org.junit.Assert.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
2020

2121
import com.google.api.services.bigquery.model.Dataset;
2222
import com.google.cloud.bigquery.Acl.DatasetAclEntity;
@@ -31,12 +31,12 @@
3131
import com.google.cloud.bigquery.Acl.View;
3232
import com.google.common.collect.ImmutableList;
3333
import java.util.List;
34-
import org.junit.Test;
34+
import org.junit.jupiter.api.Test;
3535

36-
public class AclTest {
36+
class AclTest {
3737

3838
@Test
39-
public void testDatasetEntity() {
39+
void testDatasetEntity() {
4040
DatasetId datasetId = DatasetId.of("dataset");
4141
List<String> targetTypes = ImmutableList.of("VIEWS");
4242
DatasetAclEntity entity = new DatasetAclEntity(datasetId, targetTypes);
@@ -47,7 +47,7 @@ public void testDatasetEntity() {
4747
}
4848

4949
@Test
50-
public void testDomainEntity() {
50+
void testDomainEntity() {
5151
Domain entity = new Domain("d1");
5252
assertEquals("d1", entity.getDomain());
5353
assertEquals(Type.DOMAIN, entity.getType());
@@ -56,7 +56,7 @@ public void testDomainEntity() {
5656
}
5757

5858
@Test
59-
public void testGroupEntity() {
59+
void testGroupEntity() {
6060
Group entity = new Group("g1");
6161
assertEquals("g1", entity.getIdentifier());
6262
assertEquals(Type.GROUP, entity.getType());
@@ -65,7 +65,7 @@ public void testGroupEntity() {
6565
}
6666

6767
@Test
68-
public void testSpecialGroupEntity() {
68+
void testSpecialGroupEntity() {
6969
Group entity = Group.ofAllAuthenticatedUsers();
7070
assertEquals("allAuthenticatedUsers", entity.getIdentifier());
7171
Dataset.Access pb = entity.toPb();
@@ -85,7 +85,7 @@ public void testSpecialGroupEntity() {
8585
}
8686

8787
@Test
88-
public void testUserEntity() {
88+
void testUserEntity() {
8989
User entity = new User("u1");
9090
assertEquals("u1", entity.getEmail());
9191
assertEquals(Type.USER, entity.getType());
@@ -94,7 +94,7 @@ public void testUserEntity() {
9494
}
9595

9696
@Test
97-
public void testViewEntity() {
97+
void testViewEntity() {
9898
TableId viewId = TableId.of("project", "dataset", "view");
9999
View entity = new View(viewId);
100100
assertEquals(viewId, entity.getId());
@@ -104,7 +104,7 @@ public void testViewEntity() {
104104
}
105105

106106
@Test
107-
public void testRoutineEntity() {
107+
void testRoutineEntity() {
108108
RoutineId routineId = RoutineId.of("project", "dataset", "routine");
109109
Acl.Routine entity = new Acl.Routine(routineId);
110110
assertEquals(routineId, entity.getId());
@@ -114,15 +114,15 @@ public void testRoutineEntity() {
114114
}
115115

116116
@Test
117-
public void testIamMemberEntity() {
117+
void testIamMemberEntity() {
118118
IamMember entity = new IamMember("member1");
119119
assertEquals("member1", entity.getIamMember());
120120
Dataset.Access pb = entity.toPb();
121121
assertEquals(entity, Entity.fromPb(pb));
122122
}
123123

124124
@Test
125-
public void testOf() {
125+
void testOf() {
126126
Acl acl = Acl.of(Group.ofAllAuthenticatedUsers(), Role.READER);
127127
assertEquals(Group.ofAllAuthenticatedUsers(), acl.getEntity());
128128
assertEquals(Role.READER, acl.getRole());
@@ -139,7 +139,7 @@ public void testOf() {
139139
}
140140

141141
@Test
142-
public void testOfWithCondition() {
142+
void testOfWithCondition() {
143143
Expr expr = new Expr("expression", "title", "description", "location");
144144
Acl acl = Acl.of(Group.ofAllAuthenticatedUsers(), Role.READER, expr);
145145
Dataset.Access pb = acl.toPb();

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AnnotationsTest.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
package com.google.cloud.bigquery;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20-
import static org.junit.Assert.fail;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
2121

2222
import com.google.api.client.util.Data;
2323
import java.util.Collections;
2424
import java.util.HashMap;
2525
import java.util.Map;
26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

2828
public class AnnotationsTest {
2929
@Test
30-
public void testFromUser() {
30+
void testFromUser() {
3131
assertThat(Annotations.fromUser(null).userMap()).isNull();
3232

3333
HashMap<String, String> user = new HashMap<>();
@@ -43,7 +43,7 @@ public void testFromUser() {
4343
}
4444

4545
@Test
46-
public void testFromToPb() {
46+
void testFromToPb() {
4747
assertThat(Annotations.fromPb(null).toPb()).isNull();
4848

4949
HashMap<String, String> pb = new HashMap<>();
@@ -60,17 +60,13 @@ public void testFromToPb() {
6060
}
6161

6262
@Test
63-
public void testNullKey() {
64-
try {
65-
Annotations.fromUser(Collections.singletonMap((String) null, "foo"));
66-
fail("null key shouldn't work");
67-
} catch (IllegalArgumentException e) {
68-
}
63+
void testNullKey() {
64+
assertThrows(
65+
IllegalArgumentException.class,
66+
() -> Annotations.fromUser(Collections.singletonMap((String) null, "foo")));
6967

70-
try {
71-
Annotations.fromPb(Collections.singletonMap((String) null, "foo"));
72-
fail("null key shouldn't work");
73-
} catch (IllegalArgumentException e) {
74-
}
68+
assertThrows(
69+
IllegalArgumentException.class,
70+
() -> Annotations.fromPb(Collections.singletonMap((String) null, "foo")));
7571
}
7672
}

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AvroOptionsTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package com.google.cloud.bigquery;
1818

19-
import static org.junit.Assert.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
public class AvroOptionsTest {
2424

@@ -27,7 +27,7 @@ public class AvroOptionsTest {
2727
AvroOptions.newBuilder().setUseAvroLogicalTypes(USE_AVRO_LOGICAL_TYPES).build();
2828

2929
@Test
30-
public void testToBuilder() {
30+
void testToBuilder() {
3131
compareAvroOptions(AVRO_OPTIONS, AVRO_OPTIONS.toBuilder().build());
3232
AvroOptions avroOptions = AVRO_OPTIONS.toBuilder().setUseAvroLogicalTypes(false).build();
3333
assertEquals(false, avroOptions.useAvroLogicalTypes());
@@ -36,13 +36,13 @@ public void testToBuilder() {
3636
}
3737

3838
@Test
39-
public void testBuilder() {
39+
void testBuilder() {
4040
assertEquals(FormatOptions.AVRO, AVRO_OPTIONS.getType());
4141
assertEquals(USE_AVRO_LOGICAL_TYPES, AVRO_OPTIONS.useAvroLogicalTypes());
4242
}
4343

4444
@Test
45-
public void testToAndFromPb() {
45+
void testToAndFromPb() {
4646
compareAvroOptions(AVRO_OPTIONS, AvroOptions.fromPb(AVRO_OPTIONS.toPb()));
4747
AvroOptions avroOptions =
4848
AvroOptions.newBuilder().setUseAvroLogicalTypes(USE_AVRO_LOGICAL_TYPES).build();

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigLakeConfigurationTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
package com.google.cloud.bigquery;
1818

19-
import static org.junit.Assert.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

23-
public class BigLakeConfigurationTest {
23+
class BigLakeConfigurationTest {
2424

2525
private static final String STORAGE_URI = "gs://storage-uri";
2626
private static final String FILE_FORMAT = "PARQUET";
@@ -43,20 +43,20 @@ public class BigLakeConfigurationTest {
4343
.setConnectionId(CONNECTION_ID);
4444

4545
@Test
46-
public void testToBuilder() {
46+
void testToBuilder() {
4747
assertEquals(STORAGE_URI, BIG_LAKE_CONFIGURATION.getStorageUri());
4848
assertEquals(FILE_FORMAT, BIG_LAKE_CONFIGURATION.getFileFormat());
4949
assertEquals(TABLE_FORMAT, BIG_LAKE_CONFIGURATION.getTableFormat());
5050
assertEquals(CONNECTION_ID, BIG_LAKE_CONFIGURATION.getConnectionId());
5151
}
5252

5353
@Test
54-
public void testToPb() {
54+
void testToPb() {
5555
assertBigLakeConfiguration(BIG_LAKE_CONFIGURATION_PB, BIG_LAKE_CONFIGURATION.toPb());
5656
}
5757

5858
@Test
59-
public void testFromPb() {
59+
void testFromPb() {
6060
assertBigLakeConfiguration(
6161
BIG_LAKE_CONFIGURATION, BigLakeConfiguration.fromPb(BIG_LAKE_CONFIGURATION_PB));
6262
}

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryErrorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package com.google.cloud.bigquery;
1818

19-
import static org.junit.Assert.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
public class BigQueryErrorTest {
2424

@@ -32,7 +32,7 @@ public class BigQueryErrorTest {
3232
new BigQueryError(REASON, LOCATION, MESSAGE);
3333

3434
@Test
35-
public void testConstructor() {
35+
void testConstructor() {
3636
assertEquals(REASON, ERROR.getReason());
3737
assertEquals(LOCATION, ERROR.getLocation());
3838
assertEquals(DEBUG_INFO, ERROR.getDebugInfo());
@@ -44,7 +44,7 @@ public void testConstructor() {
4444
}
4545

4646
@Test
47-
public void testToAndFromPb() {
47+
void testToAndFromPb() {
4848
compareBigQueryError(ERROR, BigQueryError.fromPb(ERROR.toPb()));
4949
compareBigQueryError(ERROR_INCOMPLETE, BigQueryError.fromPb(ERROR_INCOMPLETE.toPb()));
5050
}

0 commit comments

Comments
 (0)