restructuring
[lwes-java.git] / src / test / lwes / util / IPAddressTest.java
blob3f877905763b212456c8661a65992265db92b146
1 package org.lwes.util;
2 /**
3 * @author fmaritato
4 */
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 {
17 @Test
18 public void testEmptyConstructor() {
19 IPAddress ip = new IPAddress();
20 assertEquals("IPAddress.toString incorrect. ", "0.0.0.0", ip.toString());
23 @Test
24 public void testStringConstructor() {
25 IPAddress ip = new IPAddress("192.168.1.1");
26 assertEquals("IPAddress.toString incorrect.", "192.168.1.1", ip.toString());
29 @Test
30 public void testByteConstructor() {
31 byte[] ipBytes = new byte[]{
32 (byte) 192,
33 (byte) 168,
34 (byte) 1,
35 (byte) 1,
37 IPAddress ip = new IPAddress(ipBytes);
38 assertEquals("Byte constructor incorrect", "192.168.1.1", ip.toString());
41 @Test
42 public void testInetConstructor() throws UnknownHostException {
43 IPAddress ip = new IPAddress(InetAddress.getByAddress(new byte[]
44 {(byte) 127, (byte) 0, (byte) 0, (byte) 1}
45 ));
46 assertEquals("Inet constructor incorrect", "127.0.0.1", ip.toString());
49 @Test
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());