1 package org.umu.cops.stack;
3 import org.junit.Assert;
6 import java.net.InetAddress;
7 import java.net.UnknownHostException;
10 * Tests for the COPSIpv4Address class.
12 public class COPSIpv4AddressTest {
14 @Test(expected = UnknownHostException.class)
15 public void badHost() throws Exception {
16 new COPSIpv4Address("foo");
20 public void localhost() throws Exception {
21 final COPSIpv4Address address = new COPSIpv4Address("localhost");
22 Assert.assertEquals(4, address.getDataLength());
23 Assert.assertArrayEquals(InetAddress.getByName("localhost").getAddress(), address.getAddressBytes());
24 Assert.assertTrue(address.getIpName().equals("localhost") || address.getIpName().equals("127.0.0.1"));
28 public void addrBytes() throws Exception {
29 final byte[] addr = InetAddress.getByName("localhost").getAddress();
30 final COPSIpv4Address address = new COPSIpv4Address(addr);
31 Assert.assertEquals(4, address.getDataLength());
32 Assert.assertArrayEquals(addr, address.getAddressBytes());
33 Assert.assertTrue(address.getIpName().equals("localhost") || address.getIpName().equals("127.0.0.1"));