From b6f4637b43a0cb92fb4c4193adac30cc39e131bf Mon Sep 17 00:00:00 2001 From: svc-excavator-bot Date: Wed, 2 Oct 2024 13:32:34 +0000 Subject: [PATCH] Excavator: Switch to JUnit 5 to parallelize tests and speed up CI --- .../src/test/java/ClassNameNoPackageTest.java | 2 +- .../com/palantir/javapoet/AbstractTypesTest.java | 2 +- .../palantir/javapoet/AnnotatedTypeNameTest.java | 15 ++++++++++----- .../com/palantir/javapoet/AnnotationSpecTest.java | 2 +- .../java/com/palantir/javapoet/CodeBlockTest.java | 2 +- .../com/palantir/javapoet/CodeWriterTest.java | 2 +- .../java/com/palantir/javapoet/FieldSpecTest.java | 2 +- .../com/palantir/javapoet/FileReadingTest.java | 8 ++++---- .../com/palantir/javapoet/FileWritingTest.java | 7 +++---- .../com/palantir/javapoet/MethodSpecTest.java | 6 +++--- .../com/palantir/javapoet/NameAllocatorTest.java | 2 +- .../com/palantir/javapoet/ParameterSpecTest.java | 6 +++--- .../java/com/palantir/javapoet/TypeNameTest.java | 2 +- .../test/java/com/palantir/javapoet/UtilTest.java | 2 +- 14 files changed, 32 insertions(+), 28 deletions(-) diff --git a/javapoet/src/test/java/ClassNameNoPackageTest.java b/javapoet/src/test/java/ClassNameNoPackageTest.java index f7d2222c..2852c567 100644 --- a/javapoet/src/test/java/ClassNameNoPackageTest.java +++ b/javapoet/src/test/java/ClassNameNoPackageTest.java @@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import com.palantir.javapoet.ClassName; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Since it is impossible to import classes from the default package into other diff --git a/javapoet/src/test/java/com/palantir/javapoet/AbstractTypesTest.java b/javapoet/src/test/java/com/palantir/javapoet/AbstractTypesTest.java index 3fa18a7a..56525a95 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/AbstractTypesTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/AbstractTypesTest.java @@ -42,7 +42,7 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import javax.tools.JavaFileObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; public abstract class AbstractTypesTest { protected abstract Elements getElements(); diff --git a/javapoet/src/test/java/com/palantir/javapoet/AnnotatedTypeNameTest.java b/javapoet/src/test/java/com/palantir/javapoet/AnnotatedTypeNameTest.java index 1f40b692..7fe3a1a0 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/AnnotatedTypeNameTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/AnnotatedTypeNameTest.java @@ -21,7 +21,8 @@ import java.lang.annotation.Target; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class AnnotatedTypeNameTest { @@ -38,14 +39,18 @@ public class AnnotatedTypeNameTest { @Target(ElementType.TYPE_USE) public @interface TypeUseAnnotation {} - @Test(expected = NullPointerException.class) + @Test public void nullAnnotationArray() { - TypeName.BOOLEAN.annotated((AnnotationSpec[]) null); + Assertions.assertThrows(NullPointerException.class, () -> { + TypeName.BOOLEAN.annotated((AnnotationSpec[]) null); + }); } - @Test(expected = NullPointerException.class) + @Test public void nullAnnotationList() { - TypeName.DOUBLE.annotated((List) null); + Assertions.assertThrows(NullPointerException.class, () -> { + TypeName.DOUBLE.annotated((List) null); + }); } @Test diff --git a/javapoet/src/test/java/com/palantir/javapoet/AnnotationSpecTest.java b/javapoet/src/test/java/com/palantir/javapoet/AnnotationSpecTest.java index 72f974e0..62e030df 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/AnnotationSpecTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/AnnotationSpecTest.java @@ -25,7 +25,7 @@ import java.lang.annotation.RetentionPolicy; import javax.lang.model.element.TypeElement; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; @SuppressWarnings("ClassCanBeStatic") public final class AnnotationSpecTest { diff --git a/javapoet/src/test/java/com/palantir/javapoet/CodeBlockTest.java b/javapoet/src/test/java/com/palantir/javapoet/CodeBlockTest.java index 430773d9..37570164 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/CodeBlockTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/CodeBlockTest.java @@ -22,7 +22,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; public final class CodeBlockTest { @Test diff --git a/javapoet/src/test/java/com/palantir/javapoet/CodeWriterTest.java b/javapoet/src/test/java/com/palantir/javapoet/CodeWriterTest.java index a67298ae..fd6f6f6d 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/CodeWriterTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/CodeWriterTest.java @@ -18,7 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CodeWriterTest { diff --git a/javapoet/src/test/java/com/palantir/javapoet/FieldSpecTest.java b/javapoet/src/test/java/com/palantir/javapoet/FieldSpecTest.java index 0cfdacb2..8dfe7a83 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/FieldSpecTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/FieldSpecTest.java @@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import javax.lang.model.element.Modifier; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class FieldSpecTest { @Test diff --git a/javapoet/src/test/java/com/palantir/javapoet/FileReadingTest.java b/javapoet/src/test/java/com/palantir/javapoet/FileReadingTest.java index 1fe18606..6b39030c 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/FileReadingTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/FileReadingTest.java @@ -19,6 +19,7 @@ import com.google.common.collect.Iterables; import com.google.common.io.ByteStreams; +import java.io.File; import java.io.IOException; import java.net.URI; import java.nio.charset.StandardCharsets; @@ -35,9 +36,8 @@ import javax.tools.StandardJavaFileManager; import javax.tools.StandardLocation; import javax.tools.ToolProvider; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -45,8 +45,8 @@ public class FileReadingTest { // Used for storing compilation output. - @Rule - public final TemporaryFolder temporaryFolder = new TemporaryFolder(); + @TempDir + public File temporaryFolder ; @Test public void javaFileObjectUri() { diff --git a/javapoet/src/test/java/com/palantir/javapoet/FileWritingTest.java b/javapoet/src/test/java/com/palantir/javapoet/FileWritingTest.java index aa569b5e..03daf63d 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/FileWritingTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/FileWritingTest.java @@ -28,9 +28,8 @@ import java.util.Date; import javax.lang.model.element.Element; import javax.lang.model.element.Modifier; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; @@ -38,8 +37,8 @@ @RunWith(JUnit4.class) public final class FileWritingTest { // Used for testing java.io File behavior. - @Rule - public final TemporaryFolder tmp = new TemporaryFolder(); + @TempDir + public File tmp ; // Used for testing java.nio.file Path behavior. private final FileSystem fs = Jimfs.newFileSystem(Configuration.unix()); diff --git a/javapoet/src/test/java/com/palantir/javapoet/MethodSpecTest.java b/javapoet/src/test/java/com/palantir/javapoet/MethodSpecTest.java index b7d22003..730c6ec3 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/MethodSpecTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/MethodSpecTest.java @@ -43,9 +43,9 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import javax.tools.JavaFileObject; -import org.junit.Before; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; @SuppressWarnings({"ClassCanBeStatic", "TypeParameterUnusedInFormals", "StrictUnusedVariable", "UnusedMethod"}) public final class MethodSpecTest { @@ -55,7 +55,7 @@ public final class MethodSpecTest { private Elements elements; private Types types; - @Before + @BeforeEach public void before() { elements = compilation.getElements(); types = compilation.getTypes(); diff --git a/javapoet/src/test/java/com/palantir/javapoet/NameAllocatorTest.java b/javapoet/src/test/java/com/palantir/javapoet/NameAllocatorTest.java index b209874f..df8128fd 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/NameAllocatorTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/NameAllocatorTest.java @@ -18,7 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import org.junit.Test; +import org.junit.jupiter.api.Test; public final class NameAllocatorTest { diff --git a/javapoet/src/test/java/com/palantir/javapoet/ParameterSpecTest.java b/javapoet/src/test/java/com/palantir/javapoet/ParameterSpecTest.java index 075a2938..dae8fa50 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/ParameterSpecTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/ParameterSpecTest.java @@ -30,9 +30,9 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.util.Elements; -import org.junit.Before; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; @SuppressWarnings({"ClassCanBeStatic", "StrictUnusedVariable"}) public class ParameterSpecTest { @@ -41,7 +41,7 @@ public class ParameterSpecTest { private Elements elements; - @Before + @BeforeEach public void before() { elements = compilation.getElements(); } diff --git a/javapoet/src/test/java/com/palantir/javapoet/TypeNameTest.java b/javapoet/src/test/java/com/palantir/javapoet/TypeNameTest.java index c58d9b13..cba61537 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/TypeNameTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/TypeNameTest.java @@ -23,7 +23,7 @@ import java.util.List; import java.util.Set; import java.util.UUID; -import org.junit.Test; +import org.junit.jupiter.api.Test; @SuppressWarnings("ClassCanBeStatic") public class TypeNameTest { diff --git a/javapoet/src/test/java/com/palantir/javapoet/UtilTest.java b/javapoet/src/test/java/com/palantir/javapoet/UtilTest.java index bf0b9c55..98754082 100644 --- a/javapoet/src/test/java/com/palantir/javapoet/UtilTest.java +++ b/javapoet/src/test/java/com/palantir/javapoet/UtilTest.java @@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class UtilTest { @Test