From 8c0a268b451495f51f3f3c0593bbda338219ce1d Mon Sep 17 00:00:00 2001 From: "Philip K. Warren" Date: Wed, 8 Nov 2023 13:49:56 -0600 Subject: [PATCH] Update to junit 5 and disable wildcard imports (#61) --- .editorconfig | 6 ++++++ build.gradle.kts | 7 ++++++- conformance/build.gradle.kts | 3 ++- .../java/build/buf/protovalidate/ValidatorTest.java | 13 +++++++------ gradle/libs.versions.toml | 4 ++-- .../ValidatorDifferentJavaPackagesTest.java | 2 +- .../protovalidate/ValidatorDynamicMessageTest.java | 2 +- .../internal/celext/CustomOverloadTest.java | 2 +- 8 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..2a60a688 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +[*] +charset = utf-8 + +[*.java] +ij_java_class_count_to_use_import_on_demand = 999 +ij_java_use_single_class_imports = true diff --git a/build.gradle.kts b/build.gradle.kts index d96ece56..856d34be 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -203,6 +203,7 @@ allprojects { java { importOrder() removeUnusedImports() + replaceRegex("Remove wildcard imports", "import\\s+[^\\*\\s]+\\*;(\\r\\n|\\r|\\n)", "$1") googleJavaFormat() endWithNewline() trimTrailingWhitespace() @@ -215,6 +216,9 @@ allprojects { } } } + tasks.withType().configureEach { + useJUnitPlatform() + } } mavenPublishing { @@ -272,7 +276,8 @@ dependencies { implementation(libs.jakarta.mail.api) testImplementation(libs.assertj) - testImplementation(libs.junit) + testImplementation(platform(libs.junit.bom)) + testImplementation("org.junit.jupiter:junit-jupiter") errorprone(libs.errorprone) } diff --git a/conformance/build.gradle.kts b/conformance/build.gradle.kts index 0e2a943b..121e15c0 100644 --- a/conformance/build.gradle.kts +++ b/conformance/build.gradle.kts @@ -82,7 +82,8 @@ dependencies { implementation(libs.protobuf.java) implementation(libs.assertj) - implementation(libs.junit) + implementation(platform(libs.junit.bom)) + testImplementation("org.junit.jupiter:junit-jupiter") errorprone(libs.errorprone) } diff --git a/conformance/src/test/java/build/buf/protovalidate/ValidatorTest.java b/conformance/src/test/java/build/buf/protovalidate/ValidatorTest.java index 0b214233..748c0f33 100644 --- a/conformance/src/test/java/build/buf/protovalidate/ValidatorTest.java +++ b/conformance/src/test/java/build/buf/protovalidate/ValidatorTest.java @@ -15,6 +15,7 @@ package build.buf.protovalidate; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import build.buf.protovalidate.exceptions.ExecutionException; import build.buf.protovalidate.exceptions.ValidationException; @@ -47,14 +48,14 @@ import com.google.protobuf.Duration; import com.google.protobuf.Timestamp; import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ValidatorTest { private Validator validator; - @Before + @BeforeEach public void setUp() { Config config = Config.newBuilder().build(); validator = new Validator(config); @@ -219,10 +220,10 @@ public void strictRepeatedMin() throws Exception { assertThat(validate.getViolations()).hasSize(1); } - @Test(expected = ExecutionException.class) - public void testDynRuntimeError() throws Exception { + @Test + public void testDynRuntimeError() { DynRuntimeError invalid = DynRuntimeError.newBuilder().setA(123).build(); - validator.validate(invalid); + assertThatThrownBy(() -> validator.validate(invalid)).isInstanceOf(ExecutionException.class); } @Test diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 61ee7811..36c3734a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ assertj = "3.24.2" cel = "0.3.21" ipaddress = "5.4.0" -junit = "4.13.2" +junit = "5.10.1" # When updating, make sure to update buf.gen.yaml and src/test/resources/proto/buf.gen.*.yaml versions to match # and regenerate code with 'make generate'. protobuf = "3.25.0" @@ -15,7 +15,7 @@ errorprone = { module = "com.google.errorprone:error_prone_core", version = "2.2 guava = { module = "com.google.guava:guava", version = "32.1.3-jre" } ipaddress = { module = "com.github.seancfoley:ipaddress", version.ref = "ipaddress" } jakarta-mail-api = { module = "jakarta.mail:jakarta.mail-api", version = "2.1.2" } -junit = { module = "junit:junit", version.ref = "junit" } +junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" } maven-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.25.3" } mail = { module = "javax.mail:mail", version = "1.4.7"} nullaway = { module = "com.uber.nullaway:nullaway", version = "0.10.16" } diff --git a/src/test/java/build/buf/protovalidate/ValidatorDifferentJavaPackagesTest.java b/src/test/java/build/buf/protovalidate/ValidatorDifferentJavaPackagesTest.java index 8a27d535..2485fd8d 100644 --- a/src/test/java/build/buf/protovalidate/ValidatorDifferentJavaPackagesTest.java +++ b/src/test/java/build/buf/protovalidate/ValidatorDifferentJavaPackagesTest.java @@ -22,7 +22,7 @@ import com.google.protobuf.Message; import java.util.Collections; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * protovalidate-java contains protoc generated classes for the