You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2025/07/14 17:33:42 UTC
(maven-resolver) 01/01: Deprecate methods that are in JUnir and/or the JDK
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch 1520
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
commit 69c0d018fa4cadf3f1379ba9ba700efc86a2f179
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Mon Jul 14 13:33:30 2025 -0400
Deprecate methods that are in JUnir and/or the JDK
---
.../internal/impl/DefaultFileProcessorTest.java | 15 ++++--------
.../internal/impl/DefaultMetadataResolverTest.java | 18 +++++++++-----
.../aether/internal/test/util/TestFileUtils.java | 28 +++++++++++++++++++++-
3 files changed, 44 insertions(+), 17 deletions(-)
diff --git a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultFileProcessorTest.java b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultFileProcessorTest.java
index 7de414b8..1e24bc57 100644
--- a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultFileProcessorTest.java
+++ b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultFileProcessorTest.java
@@ -27,16 +27,17 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.aether.internal.test.util.TestFileUtils;
import org.eclipse.aether.spi.io.FileProcessor.ProgressListener;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-/**
- */
public class DefaultFileProcessorTest {
+ @TempDir
private File targetDir;
private DefaultFileProcessor fileProcessor;
@@ -47,12 +48,6 @@ public class DefaultFileProcessorTest {
fileProcessor = new DefaultFileProcessor();
}
- @AfterEach
- void teardown() throws Exception {
- TestFileUtils.deleteFile(targetDir);
- fileProcessor = null;
- }
-
@Test
void testCopy() throws IOException {
String data = "testCopy\nasdf";
diff --git a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultMetadataResolverTest.java b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultMetadataResolverTest.java
index 93502638..ec52e82e 100644
--- a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultMetadataResolverTest.java
+++ b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultMetadataResolverTest.java
@@ -48,11 +48,16 @@ import org.eclipse.aether.transfer.MetadataNotFoundException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-/**
- */
public class DefaultMetadataResolverTest {
private DefaultMetadataResolver resolver;
@@ -75,6 +80,9 @@ public class DefaultMetadataResolverTest {
private RecordingRepositoryListener listener;
+ @TempDir
+ private File tempDirectory;
+
@BeforeEach
void setup() throws Exception {
remoteRepositoryFilterSources = new HashMap<>();
@@ -93,9 +101,7 @@ public class DefaultMetadataResolverTest {
remoteRepositoryFilterManager,
new DefaultPathProcessor());
repository = new RemoteRepository.Builder(
- "test-DMRT",
- "default",
- TestFileUtils.createTempDir().toURI().toURL().toString())
+ "test-DMRT", "default", tempDirectory.toURI().toURL().toString())
.build();
metadata = new DefaultMetadata("gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
connector = new RecordingRepositoryConnector();
diff --git a/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java b/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java
index 3eae72db..a8ea5915 100644
--- a/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java
+++ b/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java
@@ -26,6 +26,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
@@ -128,10 +129,26 @@ public class TestFileUtils {
return tmpFile;
}
+ /**
+ * Creates a temporary directory.
+ *
+ * @return the temporary directory
+ * @throws IOException if an I/O error occurs
+ * @deprecated use @TempDir (JUnit 5} Or TemporaryFolder (JUnit 4) instead
+ */
+ @Deprecated
public static File createTempDir() throws IOException {
return createTempDir("");
}
+ /**
+ * Creates a temporary directory.
+ *
+ * @return the temporary directory
+ * @throws IOException if an I/O error occurs
+ * @deprecated use @TempDir (JUnit 5} Or TemporaryFolder (JUnit 4) instead
+ */
+ @Deprecated
public static File createTempDir(String suffix) throws IOException {
mkdirs(TMP);
File tmpFile = File.createTempFile("tmpdir-", suffix, TMP);
@@ -189,6 +206,15 @@ public class TestFileUtils {
return total;
}
+ /**
+ * Reads the contents of a file into a byte array.
+ *
+ * @param file the file to read
+ * @return the contents of the file as a byte array
+ * @throws IOException if an I/O error occurs
+ * @deprecated use {@code Files.readAllBytes(Path)} instead
+ */
+ @Deprecated
public static byte[] readBytes(File file) throws IOException {
RandomAccessFile in = null;
try {
@@ -232,7 +258,7 @@ public class TestFileUtils {
}
public static String readString(File file) throws IOException {
- byte[] content = readBytes(file);
+ byte[] content = Files.readAllBytes(file.toPath());
return new String(content, StandardCharsets.UTF_8);
}