6 import static org
.junit
.Assert
.assertEquals
;
7 import static org
.junit
.Assert
.assertFalse
;
8 import static org
.junit
.Assert
.assertNotSame
;
9 import static org
.junit
.Assert
.assertTrue
;
10 import org
.junit
.Test
;
12 import java
.net
.InetAddress
;
13 import java
.net
.UnknownHostException
;
15 public class IPAddressTest
{
18 public void testEmptyConstructor() {
19 IPAddress ip
= new IPAddress();
20 assertEquals("IPAddress.toString incorrect. ", "0.0.0.0", ip
.toString());
24 public void testStringConstructor() {
25 IPAddress ip
= new IPAddress("192.168.1.1");
26 assertEquals("IPAddress.toString incorrect.", "192.168.1.1", ip
.toString());
30 public void testByteConstructor() {
31 byte[] ipBytes
= new byte[]{
37 IPAddress ip
= new IPAddress(ipBytes
);
38 assertEquals("Byte constructor incorrect", "192.168.1.1", ip
.toString());
42 public void testInetConstructor() throws UnknownHostException
{
43 IPAddress ip
= new IPAddress(InetAddress
.getByAddress(new byte[]
44 {(byte) 127, (byte) 0, (byte) 0, (byte) 1}
46 assertEquals("Inet constructor incorrect", "127.0.0.1", ip
.toString());
50 public void testEquality() throws UnknownHostException
{
51 IPAddress one
= new IPAddress("192.168.1.1");
52 IPAddress two
= new IPAddress("192.168.1.1");
53 assertTrue("192.168.1.1 werent equal", one
.equals(two
));
54 assertEquals("hash codes not equal", one
.hashCode(), two
.hashCode());
56 two
= new IPAddress(InetAddress
.getByName("www.yahoo.com"));
57 assertFalse("InetAddress.getByName not equal", one
.equals(two
));
58 assertNotSame("hash codes equal", one
.hashCode(), two
.hashCode());