Skip to content

Commit a0a6db8

Browse files
committed
Fix interface discovery in CloseShieldChannel #800
Sort members
1 parent 2542ebc commit a0a6db8

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ The <action> type attribute can be add,update,fix,remove.
5656
<action type="fix" dev="pkarwasz" due-to="Piotr P. Karwasz">IOUtils.toByteArray(InputStream) now throws IOException on byte array overflow.</action>
5757
<action type="fix" dev="ggregory" due-to="Gary Gregory, Piotr P. Karwasz">Javadoc general improvements.</action>
5858
<action type="fix" dev="ggregory" due-to="Piotr P. Karwasz">IOUtils.toByteArray() now throws EOFException when not enough data is available #796.</action>
59+
<action type="fix" dev="pkarwasz" due-to="Piotr P. Karwasz">Fix interface discovery in `CloseShieldChannel` #800.</action>
5960
<!-- ADD -->
6061
<action dev="ggregory" type="add" due-to="strangelookingnerd, Gary Gregory">FileUtils#byteCountToDisplaySize() supports Zettabyte, Yottabyte, Ronnabyte and Quettabyte #763.</action>
6162
<action dev="ggregory" type="add" due-to="strangelookingnerd, Gary Gregory">Add org.apache.commons.io.FileUtils.ONE_RB #763.</action>

src/test/java/org/apache/commons/io/channels/CloseShieldChannelTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ void testCloseIsShielded(final Class<? extends Channel> channelClass) throws Exc
119119
verify(channel, times(2)).isOpen();
120120
}
121121

122+
@Test
123+
void testCorrectlyDetectsInterfaces(@TempDir Path tempDir) throws IOException {
124+
final Path testFile = tempDir.resolve("test.txt");
125+
FileUtils.touch(testFile.toFile());
126+
try (FileChannel channel = FileChannel.open(testFile); Channel shield = CloseShieldChannel.wrap(channel)) {
127+
assertInstanceOf(SeekableByteChannel.class, shield);
128+
assertInstanceOf(GatheringByteChannel.class, shield);
129+
assertInstanceOf(WritableByteChannel.class, shield);
130+
assertInstanceOf(ScatteringByteChannel.class, shield);
131+
assertInstanceOf(ReadableByteChannel.class, shield);
132+
assertInstanceOf(InterruptibleChannel.class, shield);
133+
assertInstanceOf(ByteChannel.class, shield);
134+
assertInstanceOf(Channel.class, shield);
135+
// These are not interfaces, so can not be implemented
136+
assertFalse(shield instanceof FileChannel, "not FileChannel");
137+
}
138+
}
139+
122140
@Test
123141
void testDoesNotDoubleWrap() {
124142
final ByteChannel channel = mock(ByteChannel.class);
@@ -286,22 +304,4 @@ void testWritableByteChannelMethods() throws Exception {
286304
assertThrows(ClosedChannelException.class, () -> shield.write(null));
287305
verifyNoMoreInteractions(channel);
288306
}
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-
}
307307
}

0 commit comments

Comments
 (0)