Code example for DatagramPacket

Methods: getAddress, setAddress

0
    /** 
     * @tests java.net.DatagramPacket#setAddress(java.net.InetAddress) 
     */ 
    public void test_setAddressLjava_net_InetAddress() throws IOException { 
        InetAddress ia = InetAddress.getByName("127.0.0.1");
        DatagramPacket dp = new DatagramPacket("Hello".getBytes(), 5,
                InetAddress.getLocalHost(), 0);
        dp.setAddress(ia);
        assertEquals("Incorrect address returned", ia, dp.getAddress());
    } 
 
    /** 
     * @tests java.net.DatagramPacket#setData(byte[], int, int) 
     */ 
    public void test_setData$BII() { 
        DatagramPacket dp = new DatagramPacket("Hello".getBytes(), 5);
        dp.setData("Wagga Wagga".getBytes(), 2, 3);
        assertEquals("Incorrect data set", "Wagga Wagga", new String(dp
                .getData()));
    }