use of java.nio.channels.NotYetConnectedException in project robovm by robovm.
the class NotYetConnectedExceptionTest method test_Constructor.
/**
* @tests {@link java.nio.channels.NotYetConnectedException#NotYetConnectedException()}
*/
public void test_Constructor() {
NotYetConnectedException e = new NotYetConnectedException();
assertNull(e.getMessage());
assertNull(e.getLocalizedMessage());
assertNull(e.getCause());
}
use of java.nio.channels.NotYetConnectedException in project robovm by robovm.
the class SocketChannelTest method testWriteByteBuffer_Direct.
public void testWriteByteBuffer_Direct() throws IOException {
assertTrue(this.server1.isBound());
java.nio.ByteBuffer writeBuf = java.nio.ByteBuffer.allocateDirect(CAPACITY_NORMAL);
assertFalse(this.channel1.isRegistered());
assertTrue(this.channel1.isBlocking());
assertFalse(this.channel1.isConnected());
assertFalse(this.channel1.isConnectionPending());
assertTrue(this.channel1.isOpen());
try {
channel1.write(writeBuf);
fail("Should throw NotYetConnectedException");
} catch (NotYetConnectedException e) {
// correct
}
this.channel1.connect(localAddr1);
assertTrue(this.channel1.isBlocking());
assertTrue(this.channel1.isConnected());
assertFalse(this.channel1.isConnectionPending());
assertTrue(this.channel1.isOpen());
assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBuf));
this.channel1.close();
try {
channel1.write(writeBuf);
fail("Should throw ClosedChannelException");
} catch (ClosedChannelException e) {
// correct
}
}
use of java.nio.channels.NotYetConnectedException in project robovm by robovm.
the class SocketChannelTest method testReadByteBufferArray.
/*
* Test method for 'java.nio.channels.SocketChannel.read(ByteBuffer[])'
*/
public void testReadByteBufferArray() throws IOException {
java.nio.ByteBuffer[] byteBuf = null;
MockSocketChannel testMSChannelnull = new MockSocketChannel(null);
MockSocketChannel testMSChannel = new MockSocketChannel(SelectorProvider.provider());
ServerSocket testServer = new ServerSocket(Support_PortManager.getNextPort());
try {
try {
this.channel1.read(byteBuf);
fail("Should throw NPE");
} catch (NullPointerException e) {
// correct
}
byteBuf = new java.nio.ByteBuffer[CAPACITY_NORMAL];
try {
this.channel1.read(byteBuf);
fail("Should throw NotYetConnectedException");
} catch (NotYetConnectedException e) {
// correct
}
long readNum = CAPACITY_NORMAL;
readNum = testMSChannel.read(byteBuf);
assertEquals(0, readNum);
readNum = CAPACITY_NORMAL;
readNum = testMSChannelnull.read(byteBuf);
assertEquals(0, readNum);
} finally {
testServer.close();
}
}
use of java.nio.channels.NotYetConnectedException in project robovm by robovm.
the class DatagramChannelTest method testWriteByteBufferArrayIntInt_NonBlock.
public void testWriteByteBufferArrayIntInt_NonBlock() throws IOException {
ByteBuffer[] writeBuf = new ByteBuffer[2];
writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
InetSocketAddress ipAddr = localAddr1;
// non-block mode
this.channel1.configureBlocking(false);
try {
this.channel1.write(writeBuf, 0, 2);
fail("Should throw NotYetConnectedException.");
} catch (NotYetConnectedException e) {
// correct
}
this.channel1.connect(ipAddr);
assertTrue(this.channel1.isConnected());
assertEquals(CAPACITY_NORMAL * 2, this.channel1.write(writeBuf, 0, 2));
// cannot be buffered again!
assertEquals(0, this.channel1.write(writeBuf, 0, 1));
}
use of java.nio.channels.NotYetConnectedException in project robovm by robovm.
the class DatagramChannelTest method testReadByteBuffer.
// -------------------------------------------------------------------
// Test for read()
// -------------------------------------------------------------------
/*
* Test method for 'DatagramChannelImpl.read(ByteBuffer)'
*/
public void testReadByteBuffer() throws IOException {
ByteBuffer readBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
try {
this.channel1.read(readBuf);
fail("should throw NotYetConnectedException");
} catch (NotYetConnectedException e) {
// correct
}
this.channel1.connect(localAddr1);
assertTrue(this.channel1.isConnected());
this.channel1.configureBlocking(false);
// note : blocking-mode will make the read process endless!
assertEquals(0, this.channel1.read(readBuf));
this.channel1.close();
try {
this.channel1.read(readBuf);
fail("Should throw ClosedChannelException");
} catch (ClosedChannelException e) {
// OK.
}
}
Aggregations