use of java.nio.channels.UnsupportedAddressTypeException in project robovm by robovm.
the class DatagramChannelTest method testConnect_UnsupportedType.
/**
* Test method for 'DatagramChannelImpl.connect(SocketAddress)'
*
* @throws IOException
*/
public void testConnect_UnsupportedType() throws IOException {
assertFalse(this.channel1.isConnected());
class SubSocketAddress extends SocketAddress {
private static final long serialVersionUID = 1L;
public SubSocketAddress() {
super();
}
}
SocketAddress newTypeAddress = new SubSocketAddress();
try {
this.channel1.connect(newTypeAddress);
fail("Should throw an UnsupportedAddressTypeException here.");
} catch (UnsupportedAddressTypeException e) {
// OK.
}
}
use of java.nio.channels.UnsupportedAddressTypeException in project jdk8u_jdk by JetBrains.
the class Bind method testBind.
void testBind() {
SctpChannel channel = null;
try {
channel = SctpChannel.open();
/* TEST 1: empty set if channel is not bound */
check(channel.getAllLocalAddresses().isEmpty(), "getAllLocalAddresses returned non empty set for unbound channel");
/* TEST 2: null to bind the channel to an automatically assigned
* socket address */
channel.bind(null);
/* TEST 3: non empty set if the channel is bound */
check(!channel.getAllLocalAddresses().isEmpty(), "getAllLocalAddresses returned empty set for bound channel");
debug("getAllLocalAddresses on channel bound to the wildcard:\n" + channel.getAllLocalAddresses());
/* TEST 4: AlreadyBoundException if this channel is already bound */
try {
channel.bind(null);
} catch (AlreadyBoundException unused) {
pass();
} catch (IOException ioe) {
unexpected(ioe);
}
/* TEST 5: UnsupportedAddressTypeException */
try {
channel.close();
/* open a new unbound channel for test */
channel = SctpChannel.open();
channel.bind(new UnsupportedSocketAddress());
fail("UnsupportedSocketAddress expected");
} catch (UnsupportedAddressTypeException unused) {
pass();
} catch (IOException ioe) {
unexpected(ioe);
}
/* TEST 6: AlreadyConnectedException */
try {
channel.close();
/* open a new unbound channel for test */
channel = SctpChannel.open();
connectChannel(channel);
channel.bind(null);
fail("AlreadyConnectedException expected");
} catch (AlreadyConnectedException unused) {
pass();
} catch (IOException ioe) {
unexpected(ioe);
}
/* TEST 7: ClosedChannelException - If this channel is closed */
try {
channel.close();
/* open a new unbound channel for test */
channel = SctpChannel.open();
channel.close();
channel.bind(null);
fail("ClosedChannelException expected");
} catch (ClosedChannelException unused) {
pass();
} catch (IOException ioe) {
unexpected(ioe);
}
/* TEST 8: ClosedChannelException if channel is closed */
try {
channel.getAllLocalAddresses();
fail("should have thrown ClosedChannelException");
} catch (ClosedChannelException cce) {
pass();
} catch (Exception ioe) {
unexpected(ioe);
}
} catch (IOException ioe) {
unexpected(ioe);
} finally {
try {
channel.close();
} catch (IOException ioe) {
unexpected(ioe);
}
}
}
Aggregations