@@ -52,39 +52,39 @@ abstract class AbstractSeekableByteChannelTest {
5252 class BasicTest {
5353
5454 @ Test
55- void testInitialPosition () throws IOException {
56- assertEquals (0 , channel .position ());
55+ void testCloseMultipleTimes () throws IOException {
56+ channel .close ();
57+ channel .close (); // Should not throw
58+ assertFalse (channel .isOpen ());
5759 }
5860
5961 @ Test
60- void testIsClosedAfterClose () throws IOException {
62+ void testIsOpenAfterClose () throws IOException {
6163 channel .close ();
6264 assertFalse (channel .isOpen ());
6365 }
6466
6567 @ Test
66- void testMultipleClose () throws IOException {
67- channel .close ();
68- channel .close (); // Should not throw
69- assertFalse (channel .isOpen ());
68+ void testIsOpennOnNew () {
69+ assertTrue (channel .isOpen ());
7070 }
7171
7272 @ Test
73- void testNewEntitySize () throws IOException {
74- assertEquals (0 , channel .size ());
73+ void testPositionOnNew () throws IOException {
74+ assertEquals (0 , channel .position ());
7575 }
7676
7777 @ Test
78- void testNewIsOpen () {
79- assertTrue ( channel .isOpen ());
78+ void testSizeOnNew () throws IOException {
79+ assertEquals ( 0 , channel .size ());
8080 }
8181 }
8282
8383 @ Nested
8484 class IntegrationTest {
8585
8686 @ Test
87- void ConcurrentPositionAndSizeQueries () throws IOException {
87+ void testConcurrentPositionAndSizeQueries () throws IOException {
8888 final byte [] data = "test data" .getBytes ();
8989 channel .write (ByteBuffer .wrap (data ));
9090 final long size = channel .size ();
@@ -167,11 +167,6 @@ void testWritePositionReadVerify() throws IOException {
167167 @ Nested
168168 class PositionTest {
169169
170- @ Test
171- void testNegativePosition () {
172- assertThrows (IllegalArgumentException .class , () -> channel .position (-1 ));
173- }
174-
175170 @ Test
176171 void testPositionBeyondSize () throws IOException {
177172 channel .write (ByteBuffer .wrap ("test" .getBytes ()));
@@ -193,6 +188,11 @@ void testPositionInBounds(final long newPosition, final long expectedPosition) t
193188 assertEquals (expectedPosition , channel .position ());
194189 }
195190
191+ @ Test
192+ void testPositionNegative () {
193+ assertThrows (IllegalArgumentException .class , () -> channel .position (-1 ));
194+ }
195+
196196 @ Test
197197 void testPositionOnClosed () throws IOException {
198198 channel .close ();
@@ -278,12 +278,20 @@ void testReadSingleByte() throws IOException {
278278 class SizeTest {
279279
280280 @ Test
281- void testSameSizeOnOverwrite () throws IOException {
282- channel .write (ByteBuffer .wrap ("Hello World" .getBytes ()));
281+ void testSizeAfterTruncateToLargerSize () throws IOException {
282+ channel .write (ByteBuffer .wrap ("Hello" .getBytes ()));
283+ assertEquals (5 , channel .size ());
284+ channel .truncate (10 );
285+ assertEquals (5 , channel .size ()); // Size should remain unchanged
286+ }
287+
288+ @ Test
289+ void testSizeAfterWrite () throws IOException {
290+ assertEquals (0 , channel .size ());
291+ channel .write (ByteBuffer .wrap ("Hello" .getBytes ()));
292+ assertEquals (5 , channel .size ());
293+ channel .write (ByteBuffer .wrap (" World" .getBytes ()));
283294 assertEquals (11 , channel .size ());
284- channel .position (6 );
285- channel .write (ByteBuffer .wrap ("Test" .getBytes ()));
286- assertEquals (11 , channel .size ()); // Size should not change
287295 }
288296
289297 @ Test
@@ -292,6 +300,15 @@ void testSizeOnClosed() throws IOException {
292300 assertThrows (ClosedChannelException .class , () -> channel .size ());
293301 }
294302
303+ @ Test
304+ void testSizeSameOnOverwrite () throws IOException {
305+ channel .write (ByteBuffer .wrap ("Hello World" .getBytes ()));
306+ assertEquals (11 , channel .size ());
307+ channel .position (6 );
308+ channel .write (ByteBuffer .wrap ("Test" .getBytes ()));
309+ assertEquals (11 , channel .size ()); // Size should not change
310+ }
311+
295312 @ Test
296313 void testTruncateNegative () {
297314 assertThrows (IllegalArgumentException .class , () -> channel .truncate (-1 ));
@@ -308,23 +325,6 @@ void testTruncateShrinks() throws IOException {
308325 assertEquals (5 , channel .position ());
309326 }
310327 }
311-
312- @ Test
313- void testTruncateToLargerSize () throws IOException {
314- channel .write (ByteBuffer .wrap ("Hello" .getBytes ()));
315- assertEquals (5 , channel .size ());
316- channel .truncate (10 );
317- assertEquals (5 , channel .size ()); // Size should remain unchanged
318- }
319-
320- @ Test
321- void testWriteGrowsSize () throws IOException {
322- assertEquals (0 , channel .size ());
323- channel .write (ByteBuffer .wrap ("Hello" .getBytes ()));
324- assertEquals (5 , channel .size ());
325- channel .write (ByteBuffer .wrap (" World" .getBytes ()));
326- assertEquals (11 , channel .size ());
327- }
328328 }
329329
330330 @ Nested
@@ -367,6 +367,13 @@ void testWriteSingleByte() throws IOException {
367367 assertEquals (1 , channel .size ());
368368 }
369369
370+ @ Test
371+ void testWriteToClosedChannel () throws IOException {
372+ channel .close ();
373+ final ByteBuffer buffer = ByteBuffer .wrap ("test" .getBytes ());
374+ assertThrows (ClosedChannelException .class , () -> channel .write (buffer ));
375+ }
376+
370377 @ Test
371378 void tesWriteBytes () throws IOException {
372379 final byte [] data = "Hello, World!" .getBytes ();
@@ -376,13 +383,6 @@ void tesWriteBytes() throws IOException {
376383 assertEquals (data .length , channel .position ());
377384 assertEquals (data .length , channel .size ());
378385 }
379-
380- @ Test
381- void writeToClosedChannel () throws IOException {
382- channel .close ();
383- final ByteBuffer buffer = ByteBuffer .wrap ("test" .getBytes ());
384- assertThrows (ClosedChannelException .class , () -> channel .write (buffer ));
385- }
386386 }
387387
388388 private SeekableByteChannel channel ;
0 commit comments