/** *Testcreatewhenclosed.
*/ publicvoid testCreate2() throws IOException { var impl = new PlatformSocketImpl(false);
impl.close();
expectThrows(IOException.class, () -> impl.create(true));
}
/** *Testconnectwhennotcreated.
*/ publicvoid testConnect1() throws IOException { try (var ss = new ServerSocket(0)) { var impl = new PlatformSocketImpl(false); var address = ss.getInetAddress(); int port = ss.getLocalPort();
expectThrows(IOException.class, () -> impl.connect(address, port));
}
}
/** *Testconnectwithunsupportedaddresstype.
*/ publicvoid testConnect2() throws IOException { try (var impl = new PlatformSocketImpl(false)) {
impl.create(true); var remote = new SocketAddress() { };
expectThrows(IOException.class, () -> impl.connect(remote, 0));
}
}
/** *Testconnectwithanunresolvedaddress.
*/ publicvoid testConnect3() throws IOException { try (var impl = new PlatformSocketImpl(false)) {
impl.create(true); var remote = new InetSocketAddress("blah-blah.blah-blah", 80);
expectThrows(IOException.class, () -> impl.connect(remote, 0));
}
}
/** *Testconnectwhenalreadyconnected.
*/ publicvoid testConnect4() throws IOException { try (var ss = new ServerSocket(); var impl = new PlatformSocketImpl(false)) { var loopback = InetAddress.getLoopbackAddress();
ss.bind(new InetSocketAddress(loopback, 0));
impl.create(true); int port = ss.getLocalPort();
impl.connect(loopback, port);
expectThrows(IOException.class, () -> impl.connect(loopback, port));
}
}
/** *Testconnectwhenclosed.
*/ publicvoid testConnect5() throws IOException { try (var ss = new ServerSocket(0)) { var impl = new PlatformSocketImpl(false);
impl.close();
String host = ss.getInetAddress().getHostAddress(); int port = ss.getLocalPort();
expectThrows(IOException.class, () -> impl.connect(host, port));
}
}
/** *Testbindwhennotcreated.
*/ publicvoid testBind1() throws IOException { var impl = new PlatformSocketImpl(false); var loopback = InetAddress.getLoopbackAddress();
expectThrows(IOException.class, () -> impl.bind(loopback, 0));
}
/** *Testlistenwhenclosed.
*/ publicvoid testListen3() throws IOException { var impl = new PlatformSocketImpl(false);
impl.close();
expectThrows(IOException.class, () -> impl.listen(16));
}
/** *Testacceptwhennotcreated.
*/ publicvoid testAccept1() throws IOException { var impl = new PlatformSocketImpl(true); var si = new PlatformSocketImpl(false);
expectThrows(IOException.class, () -> impl.accept(si));
}
/** *Testacceptwhennotbound.
*/ publicvoid testAccept2() throws IOException { try (var impl = new PlatformSocketImpl(true)) {
impl.create(true); var si = new PlatformSocketImpl(false);
expectThrows(IOException.class, () -> impl.accept(si));
}
}
/** *Testacceptwhennotastreamsocket.
*/ publicvoid testAccept3() throws IOException { try (var impl = new PlatformSocketImpl(false)) {
impl.create(false);
impl.bind(InetAddress.getLoopbackAddress(), 0); var si = new PlatformSocketImpl(false);
expectThrows(IOException.class, () -> impl.accept(si));
}
}
/** *Testacceptwhenclosed.
*/ publicvoid testAccept4() throws IOException { var impl = new PlatformSocketImpl(true);
impl.close(); var si = new PlatformSocketImpl(false);
expectThrows(IOException.class, () -> impl.accept(si));
}
/** *TestacceptwithSocketImplthatisalreadycreated.
*/ publicvoid testAccept5() throws IOException { try (var impl = new PlatformSocketImpl(true); var si = new PlatformSocketImpl(false)) {
impl.create(true);
impl.bind(InetAddress.getLoopbackAddress(), 0);
si.create(true);
expectThrows(IOException.class, () -> impl.accept(si));
}
}
/** *TestacceptwithSocketImplthatisclosed.
*/ publicvoid testAccept6() throws IOException { try (var impl = new PlatformSocketImpl(true); var si = new PlatformSocketImpl(false)) {
impl.create(true);
impl.bind(InetAddress.getLoopbackAddress(), 0);
si.create(true);
si.close();
expectThrows(IOException.class, () -> impl.accept(si));
}
}
/** *Testavailablewhennotcreated.
*/ publicvoid testAvailable1() throws IOException { var impl = new PlatformSocketImpl(false);
expectThrows(IOException.class, () -> impl.available());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.