Search in sources :

Example 1 with DatagramSocketImplFactory

use of java.net.DatagramSocketImplFactory in project robovm by robovm.

the class OldDatagramSocketImplFactoryTest method test_createDatagramSocketImpl.

public void test_createDatagramSocketImpl() throws IllegalArgumentException, IOException {
    if (isTestable) {
        DatagramSocketImplFactory factory = new TestDatagramSocketImplFactory();
        assertFalse(isCreateDatagramSocketImpl);
        DatagramSocket.setDatagramSocketImplFactory(factory);
        try {
            new java.net.DatagramSocket();
            assertTrue(isCreateDatagramSocketImpl);
            assertTrue(isDatagramSocketImplCalled);
        } catch (Exception e) {
            fail("Exception during test : " + e.getMessage());
        }
        try {
            DatagramSocket.setDatagramSocketImplFactory(factory);
            fail("SocketException was not thrown.");
        } catch (SocketException se) {
        //expected
        }
        try {
            DatagramSocket.setDatagramSocketImplFactory(null);
            fail("SocketException was not thrown.");
        } catch (SocketException se) {
        //expected
        }
    } else {
        TestDatagramSocketImplFactory dsf = new TestDatagramSocketImplFactory();
        DatagramSocketImpl dsi = dsf.createDatagramSocketImpl();
        try {
            assertNull(dsi.getOption(0));
        } catch (SocketException e) {
            fail("SocketException was thrown.");
        }
    }
}
Also used : SocketException(java.net.SocketException) DatagramSocketImpl(java.net.DatagramSocketImpl) DatagramSocket(java.net.DatagramSocket) DatagramSocketImplFactory(java.net.DatagramSocketImplFactory) SocketException(java.net.SocketException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 DatagramSocket (java.net.DatagramSocket)1 DatagramSocketImpl (java.net.DatagramSocketImpl)1 DatagramSocketImplFactory (java.net.DatagramSocketImplFactory)1 SocketException (java.net.SocketException)1