Code example for ServerSocket

Methods: bind, close, isBound

0
    /** 
     * @tests java.net.ServerSocket#isBound() 
     */ 
    public void test_isBound() throws IOException { 
        InetAddress addr = InetAddress.getLocalHost();
        ServerSocket serverSocket = new ServerSocket();
        assertFalse("Socket indicated bound when it should be (1)",
                serverSocket.isBound());
 
        // now bind and validate bound ok 
        serverSocket.bind(new InetSocketAddress(addr, 0));
        assertTrue("Socket indicated  not bound when it should be (1)",
                serverSocket.isBound());
        serverSocket.close();
 
        // now do with some of the other constructors 
        serverSocket = new ServerSocket(0);
        assertTrue("Socket indicated  not bound when it should be (2)",
                serverSocket.isBound());
        serverSocket.close();