test: common: SocketChannelTests for JEP380/Java, not-yet conn/bound · kohlschutter/junixsocket@e72f960 (original) (raw)
`@@ -19,15 +19,19 @@
`
19
19
``
20
20
`import static org.junit.jupiter.api.Assertions.assertEquals;
`
21
21
`import static org.junit.jupiter.api.Assertions.assertFalse;
`
``
22
`+
import static org.junit.jupiter.api.Assertions.assertThrows;
`
22
23
`import static org.junit.jupiter.api.Assertions.assertTrue;
`
23
24
`import static org.junit.jupiter.api.Assertions.fail;
`
24
25
``
25
26
`import java.io.IOException;
`
26
27
`import java.net.SocketAddress;
`
27
28
`import java.net.SocketException;
`
28
29
`import java.net.SocketTimeoutException;
`
``
30
`+
import java.net.StandardSocketOptions;
`
29
31
`import java.nio.ByteBuffer;
`
30
32
`import java.nio.channels.ClosedChannelException;
`
``
33
`+
import java.nio.channels.NotYetBoundException;
`
``
34
`+
import java.nio.channels.NotYetConnectedException;
`
31
35
`import java.nio.channels.ServerSocketChannel;
`
32
36
`import java.nio.channels.SocketChannel;
`
33
37
`import java.util.Objects;
`
`@@ -159,7 +163,11 @@ private void testDoubleBind(boolean reuseAddress) throws Exception {
`
159
163
` });
`
160
164
``
161
165
`try (ServerSocketChannel ssc2 = selectorProvider().openServerSocketChannel()) {
`
162
``
`-
ssc2.socket().setReuseAddress(reuseAddress);
`
``
166
`+
try {
`
``
167
`+
ssc2.setOption(StandardSocketOptions.SO_REUSEADDR, reuseAddress);
`
``
168
`+
} catch (UnsupportedOperationException e) {
`
``
169
`+
// ignore
`
``
170
`+
}
`
163
171
``
164
172
`try {
`
165
173
`wasRebound.set(true);
`
`@@ -406,4 +414,22 @@ protected SocketAddress resolveAddressForSecondBind(SocketAddress originalAddres
`
406
414
`protected boolean socketDomainPermitsDoubleBind() {
`
407
415
`return false;
`
408
416
` }
`
``
417
+
``
418
`+
@Test
`
``
419
`+
public void testReadNotConnectedYet() throws Exception {
`
``
420
`+
SocketChannel sc = newSocketChannel();
`
``
421
`+
assertThrows(NotYetConnectedException.class, () -> sc.read(ByteBuffer.allocate(1)));
`
``
422
`+
}
`
``
423
+
``
424
`+
@Test
`
``
425
`+
public void testWriteNotConnectedYet() throws Exception {
`
``
426
`+
SocketChannel sc = newSocketChannel();
`
``
427
`+
assertThrows(NotYetConnectedException.class, () -> sc.write(ByteBuffer.allocate(1)));
`
``
428
`+
}
`
``
429
+
``
430
`+
@Test
`
``
431
`+
public void testAcceptNotBoundYet() throws Exception {
`
``
432
`+
ServerSocketChannel sc = newServerSocketChannel();
`
``
433
`+
assertThrows(NotYetBoundException.class, sc::accept);
`
``
434
`+
}
`
409
435
`}
`