1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.io.input;
18
19 import static org.junit.jupiter.api.Assertions.assertThrows;
20 import static org.junit.jupiter.api.Assertions.assertTrue;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.nio.channels.FileChannel;
25 import java.nio.file.StandardOpenOption;
26
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33
34
35
36 class BufferedFileChannelInputStreamTest extends AbstractInputStreamTest {
37
38 @SuppressWarnings("resource")
39 @BeforeEach
40 public void setUpInputStreams() throws IOException {
41
42 inputStreams = new InputStream[] {
43 new BufferedFileChannelInputStream(InputPath),
44 new BufferedFileChannelInputStream(InputPath, 123),
45 BufferedFileChannelInputStream.builder().setPath(InputPath).get(),
46 BufferedFileChannelInputStream.builder().setPath(InputPath).setBufferSize(123).get(),
47 BufferedFileChannelInputStream.builder().setURI(InputPath.toUri()).setBufferSize(1024).get(),
48 BufferedFileChannelInputStream.builder().setPath(InputPath).setOpenOptions(StandardOpenOption.READ).get(),
49 BufferedFileChannelInputStream.builder().setFileChannel(FileChannel.open(InputPath)).get(),
50 };
51
52 }
53
54 @Override
55 @Test
56 void testAvailableAfterOpen() throws Exception {
57 for (final InputStream inputStream : inputStreams) {
58 assertTrue(inputStream.available() > 0);
59 }
60 }
61
62 @Test
63 void testBuilderGet() {
64
65 assertThrows(IllegalStateException.class, () -> BufferedFileChannelInputStream.builder().get());
66 }
67
68 @Test
69 void testReadAfterClose() throws Exception {
70 for (final InputStream inputStream : inputStreams) {
71 inputStream.close();
72 assertThrows(IOException.class, inputStream::read);
73 }
74 }
75
76 }