You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/01/27 19:21:24 UTC
[commons-codec] branch master updated: Port some tests from IO to NIO APIs
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git
The following commit(s) were added to refs/heads/master by this push:
new 08c4d7cb Port some tests from IO to NIO APIs
08c4d7cb is described below
commit 08c4d7cb3a862c663742bb1240c824ca9fe14df4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jan 27 14:21:20 2023 -0500
Port some tests from IO to NIO APIs
---
.../commons/codec/digest/DigestUtilsTest.java | 42 +++++++++++-----------
.../codec/digest/MessageDigestAlgorithmsTest.java | 2 +-
2 files changed, 21 insertions(+), 23 deletions(-)
diff --git a/src/test/java/org/apache/commons/codec/digest/DigestUtilsTest.java b/src/test/java/org/apache/commons/codec/digest/DigestUtilsTest.java
index e480e686..1c78781c 100644
--- a/src/test/java/org/apache/commons/codec/digest/DigestUtilsTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/DigestUtilsTest.java
@@ -18,14 +18,19 @@
package org.apache.commons.codec.digest;
import static org.apache.commons.codec.binary.StringUtils.getBytesUtf8;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.file.Files;
@@ -43,7 +48,6 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-
/**
* Tests DigestUtils methods.
*
@@ -54,9 +58,9 @@ public class DigestUtilsTest {
private final byte[] testData = new byte[1024 * 1024];
- private File testFile;
+ private Path testFile;
- private File testRandomAccessFile;
+ private Path testRandomAccessFile;
private RandomAccessFile testRandomAccessFileWrapper;
@@ -72,12 +76,8 @@ public class DigestUtilsTest {
return testData;
}
- File getTestFile() {
- return testFile;
- }
-
Path getTestPath() {
- return testFile.toPath();
+ return testFile;
}
RandomAccessFile getTestRandomAccessFile() {
@@ -87,27 +87,25 @@ public class DigestUtilsTest {
@BeforeEach
public void setUp() throws Exception {
new Random().nextBytes(testData);
- testFile = File.createTempFile(DigestUtilsTest.class.getName(), ".dat");
- try (final FileOutputStream fos = new FileOutputStream(testFile)) {
+ testFile = Files.createTempFile(DigestUtilsTest.class.getName(), ".dat");
+ try (final OutputStream fos = Files.newOutputStream(testFile)) {
fos.write(testData);
}
- testRandomAccessFile = File.createTempFile(DigestUtilsTest.class.getName(), ".dat");
- try (final FileOutputStream fos = new FileOutputStream(testRandomAccessFile)) {
+ testRandomAccessFile = Files.createTempFile(DigestUtilsTest.class.getName(), ".dat");
+ try (final OutputStream fos = Files.newOutputStream(testRandomAccessFile)) {
fos.write(testData);
}
- testRandomAccessFileWrapper = new RandomAccessFile(testRandomAccessFile, "rw");
+ testRandomAccessFileWrapper = new RandomAccessFile(testRandomAccessFile.toFile(), "rw");
}
@AfterEach
- public void tearDown() {
- if (!testFile.delete()) {
- testFile.deleteOnExit();
- }
-
- if (!testRandomAccessFile.delete()) {
- testRandomAccessFile.deleteOnExit();
+ public void tearDown() throws IOException {
+ if (testRandomAccessFileWrapper != null) {
+ testRandomAccessFileWrapper.close();
}
+ Files.deleteIfExists(testFile);
+ Files.deleteIfExists(testRandomAccessFile);
}
@Test
diff --git a/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmsTest.java b/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmsTest.java
index b688e598..f8033229 100644
--- a/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmsTest.java
+++ b/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmsTest.java
@@ -98,7 +98,7 @@ public class MessageDigestAlgorithmsTest {
}
private File getTestFile() {
- return digestUtilsTest.getTestFile();
+ return digestUtilsTest.getTestPath().toFile();
}
private Path getTestPath() {