|
20 | 20 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
21 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; |
22 | 22 | import static org.junit.jupiter.api.Assertions.assertFalse; |
| 23 | +import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
23 | 24 | import static org.junit.jupiter.api.Assertions.assertNotSame; |
24 | 25 | import static org.junit.jupiter.api.Assertions.assertSame; |
25 | 26 | import static org.junit.jupiter.api.Assertions.assertThrows; |
|
32 | 33 | import static org.mockito.Mockito.verifyNoMoreInteractions; |
33 | 34 | import static org.mockito.Mockito.when; |
34 | 35 |
|
| 36 | +import java.io.IOException; |
35 | 37 | import java.nio.channels.AsynchronousByteChannel; |
36 | 38 | import java.nio.channels.AsynchronousChannel; |
37 | 39 | import java.nio.channels.ByteChannel; |
38 | 40 | import java.nio.channels.Channel; |
39 | 41 | import java.nio.channels.ClosedChannelException; |
| 42 | +import java.nio.channels.FileChannel; |
40 | 43 | import java.nio.channels.GatheringByteChannel; |
41 | 44 | import java.nio.channels.InterruptibleChannel; |
42 | 45 | import java.nio.channels.MulticastChannel; |
|
45 | 48 | import java.nio.channels.ScatteringByteChannel; |
46 | 49 | import java.nio.channels.SeekableByteChannel; |
47 | 50 | import java.nio.channels.WritableByteChannel; |
| 51 | +import java.nio.file.Path; |
48 | 52 | import java.util.stream.Stream; |
49 | 53 |
|
| 54 | +import org.apache.commons.io.FileUtils; |
50 | 55 | import org.junit.jupiter.api.Test; |
| 56 | +import org.junit.jupiter.api.io.TempDir; |
51 | 57 | import org.junit.jupiter.params.ParameterizedTest; |
52 | 58 | import org.junit.jupiter.params.provider.MethodSource; |
53 | 59 |
|
@@ -280,4 +286,22 @@ void testWritableByteChannelMethods() throws Exception { |
280 | 286 | assertThrows(ClosedChannelException.class, () -> shield.write(null)); |
281 | 287 | verifyNoMoreInteractions(channel); |
282 | 288 | } |
| 289 | + |
| 290 | + @Test |
| 291 | + void testCorrectlyDetectsInterfaces(@TempDir Path tempDir) throws IOException { |
| 292 | + final Path testFile = tempDir.resolve("test.txt"); |
| 293 | + FileUtils.touch(testFile.toFile()); |
| 294 | + try (FileChannel channel = FileChannel.open(testFile); Channel shield = CloseShieldChannel.wrap(channel)) { |
| 295 | + assertInstanceOf(SeekableByteChannel.class, shield); |
| 296 | + assertInstanceOf(GatheringByteChannel.class, shield); |
| 297 | + assertInstanceOf(WritableByteChannel.class, shield); |
| 298 | + assertInstanceOf(ScatteringByteChannel.class, shield); |
| 299 | + assertInstanceOf(ReadableByteChannel.class, shield); |
| 300 | + assertInstanceOf(InterruptibleChannel.class, shield); |
| 301 | + assertInstanceOf(ByteChannel.class, shield); |
| 302 | + assertInstanceOf(Channel.class, shield); |
| 303 | + // These are not interfaces, so can not be implemented |
| 304 | + assertFalse(shield instanceof FileChannel, "not FileChannel"); |
| 305 | + } |
| 306 | + } |
283 | 307 | } |
0 commit comments