1818package org .apache .commons .codec .digest ;
1919
2020import static org .apache .commons .codec .binary .StringUtils .getBytesUtf8 ;
21- import static org .junit .jupiter .api .Assertions .*;
21+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
22+ import static org .junit .jupiter .api .Assertions .assertEquals ;
23+ import static org .junit .jupiter .api .Assertions .assertFalse ;
24+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
25+ import static org .junit .jupiter .api .Assertions .assertThrows ;
26+ import static org .junit .jupiter .api .Assertions .assertTrue ;
2227import static org .junit .jupiter .api .Assumptions .assumeTrue ;
2328
2429import java .io .ByteArrayInputStream ;
2530import java .io .File ;
2631import java .io .FileInputStream ;
27- import java .io .FileOutputStream ;
2832import java .io .IOException ;
33+ import java .io .OutputStream ;
2934import java .io .RandomAccessFile ;
3035import java .nio .ByteBuffer ;
3136import java .nio .file .Files ;
4348import org .junit .jupiter .api .BeforeEach ;
4449import org .junit .jupiter .api .Test ;
4550
46-
4751/**
4852 * Tests DigestUtils methods.
4953 *
@@ -54,9 +58,9 @@ public class DigestUtilsTest {
5458
5559 private final byte [] testData = new byte [1024 * 1024 ];
5660
57- private File testFile ;
61+ private Path testFile ;
5862
59- private File testRandomAccessFile ;
63+ private Path testRandomAccessFile ;
6064
6165 private RandomAccessFile testRandomAccessFileWrapper ;
6266
@@ -72,12 +76,8 @@ byte[] getTestData() {
7276 return testData ;
7377 }
7478
75- File getTestFile () {
76- return testFile ;
77- }
78-
7979 Path getTestPath () {
80- return testFile . toPath () ;
80+ return testFile ;
8181 }
8282
8383 RandomAccessFile getTestRandomAccessFile () {
@@ -87,27 +87,25 @@ RandomAccessFile getTestRandomAccessFile() {
8787 @ BeforeEach
8888 public void setUp () throws Exception {
8989 new Random ().nextBytes (testData );
90- testFile = File .createTempFile (DigestUtilsTest .class .getName (), ".dat" );
91- try (final FileOutputStream fos = new FileOutputStream (testFile )) {
90+ testFile = Files .createTempFile (DigestUtilsTest .class .getName (), ".dat" );
91+ try (final OutputStream fos = Files . newOutputStream (testFile )) {
9292 fos .write (testData );
9393 }
9494
95- testRandomAccessFile = File .createTempFile (DigestUtilsTest .class .getName (), ".dat" );
96- try (final FileOutputStream fos = new FileOutputStream (testRandomAccessFile )) {
95+ testRandomAccessFile = Files .createTempFile (DigestUtilsTest .class .getName (), ".dat" );
96+ try (final OutputStream fos = Files . newOutputStream (testRandomAccessFile )) {
9797 fos .write (testData );
9898 }
99- testRandomAccessFileWrapper = new RandomAccessFile (testRandomAccessFile , "rw" );
99+ testRandomAccessFileWrapper = new RandomAccessFile (testRandomAccessFile . toFile () , "rw" );
100100 }
101101
102102 @ AfterEach
103- public void tearDown () {
104- if (!testFile .delete ()) {
105- testFile .deleteOnExit ();
106- }
107-
108- if (!testRandomAccessFile .delete ()) {
109- testRandomAccessFile .deleteOnExit ();
103+ public void tearDown () throws IOException {
104+ if (testRandomAccessFileWrapper != null ) {
105+ testRandomAccessFileWrapper .close ();
110106 }
107+ Files .deleteIfExists (testFile );
108+ Files .deleteIfExists (testRandomAccessFile );
111109 }
112110
113111 @ Test
0 commit comments