1919import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
2020import static org .junit .jupiter .api .Assertions .assertEquals ;
2121
22- import java .io .BufferedOutputStream ;
2322import java .io .IOException ;
2423import java .io .InputStream ;
25- import java .io .OutputStream ;
2624import java .nio .file .Files ;
2725import java .nio .file .Path ;
2826import java .util .Arrays ;
4139 */
4240public class MemoryMappedFileInputStreamTest {
4341
42+ private static final byte [] EMPTY_BYTE_ARRAY = new byte [0 ];
43+
4444 @ TempDir
4545 Path tempDir ;
4646
@@ -53,11 +53,7 @@ void afterEach() {
5353 }
5454
5555 private Path createTestFile (final int size ) throws IOException {
56- final Path file = Files .createTempFile (tempDir , null , null );
57- try (OutputStream outputStream = new BufferedOutputStream (Files .newOutputStream (file ))) {
58- Files .write (file , RandomUtils .nextBytes (size ));
59- }
60- return file ;
56+ return Files .write (Files .createTempFile (tempDir , null , null ), RandomUtils .nextBytes (size ));
6157 }
6258
6359 @ Test
@@ -80,7 +76,7 @@ void testEmptyFile() throws IOException {
8076 // test
8177 try (InputStream inputStream = new MemoryMappedFileInputStream (file )) {
8278 // verify
83- assertArrayEquals (new byte [ 0 ] , IOUtils .toByteArray (inputStream ));
79+ assertArrayEquals (EMPTY_BYTE_ARRAY , IOUtils .toByteArray (inputStream ));
8480 }
8581 }
8682
@@ -148,7 +144,7 @@ void testSkipEmpty() throws IOException {
148144 try (InputStream inputStream = new MemoryMappedFileInputStream (file )) {
149145 assertEquals (0 , inputStream .skip (5 ));
150146 // verify
151- assertArrayEquals (new byte [ 0 ] , IOUtils .toByteArray (inputStream ));
147+ assertArrayEquals (EMPTY_BYTE_ARRAY , IOUtils .toByteArray (inputStream ));
152148 }
153149 }
154150
@@ -208,7 +204,7 @@ void testSkipPastEof() throws IOException {
208204 IOUtils .toByteArray (inputStream , 5 );
209205 assertEquals (95 , inputStream .skip (96 ));
210206 // verify
211- assertArrayEquals (new byte [ 0 ] , IOUtils .toByteArray (inputStream ));
207+ assertArrayEquals (EMPTY_BYTE_ARRAY , IOUtils .toByteArray (inputStream ));
212208 }
213209 }
214210
0 commit comments