1 package org.olsr.v1.info.api.dto; 2 3 import static org.hamcrest.core.IsEqual.equalTo; 4 import static org.hamcrest.core.IsNull.notNullValue; 5 import static org.junit.Assert.assertThat; 6 7 import java.net.InetAddress; 8 import java.net.UnknownHostException; 9 10 import org.junit.After; 11 import org.junit.Before; 12 import org.junit.Test; 13 14 public class TestJsonInfoConfigSgwPrefix { 15 private JsonInfoConfigSgwPrefix impl = null; 16 17 @Before setUp()18 public void setUp() { 19 this.impl = new JsonInfoConfigSgwPrefix(); 20 } 21 22 @After tearDown()23 public void tearDown() { 24 this.impl = null; 25 } 26 27 @Test(timeout = 8000) testGettersAndSetters()28 public void testGettersAndSetters() throws UnknownHostException { 29 /* initial */ 30 assertThat(this.impl.getPrefix(), equalTo("")); 31 assertThat(Integer.valueOf(this.impl.getLength()), equalTo(Integer.valueOf(0))); 32 33 /* set */ 34 final InetAddress addr = InetAddress.getByName("127.0.0.1"); 35 this.impl.setPrefix(addr); 36 this.impl.setLength(11); 37 38 /* get */ 39 assertThat(this.impl.getPrefix(), equalTo(addr.getHostAddress())); 40 assertThat(Integer.valueOf(this.impl.getLength()), equalTo(Integer.valueOf(11))); 41 } 42 43 @Test(timeout = 8000) testCompareTo()44 public void testCompareTo() throws UnknownHostException { 45 int r; 46 final JsonInfoConfigSgwPrefix other = new JsonInfoConfigSgwPrefix(); 47 final InetAddress addr = InetAddress.getByName("127.0.0.1"); 48 final InetAddress addr2 = InetAddress.getByName("127.0.0.2"); 49 50 /* null */ 51 52 r = this.impl.compareTo(null); 53 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1))); 54 55 /* prefix */ 56 57 final String stringOrg = this.impl.getPrefix(); 58 59 this.impl.setPrefix(null); 60 other.setPrefix(null); 61 r = this.impl.compareTo(other); 62 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(0))); 63 64 this.impl.setPrefix(null); 65 other.setPrefix(addr); 66 r = this.impl.compareTo(other); 67 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1))); 68 69 this.impl.setPrefix(addr); 70 other.setPrefix(null); 71 r = this.impl.compareTo(other); 72 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1))); 73 74 this.impl.setPrefix(addr); 75 other.setPrefix(addr2); 76 r = this.impl.compareTo(other); 77 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1))); 78 79 this.impl.setPrefix(addr2); 80 other.setPrefix(addr); 81 r = this.impl.compareTo(other); 82 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1))); 83 84 this.impl.setPrefix(addr); 85 other.setPrefix(addr); 86 r = this.impl.compareTo(other); 87 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(0))); 88 89 this.impl.setPrefix(InetAddress.getByName(stringOrg)); 90 other.setPrefix(InetAddress.getByName(stringOrg)); 91 92 /* length */ 93 94 final int intOrg = this.impl.getLength(); 95 96 this.impl.setLength(1); 97 other.setLength(2); 98 r = this.impl.compareTo(other); 99 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1))); 100 101 this.impl.setLength(2); 102 other.setLength(1); 103 r = this.impl.compareTo(other); 104 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1))); 105 106 this.impl.setLength(1); 107 other.setLength(1); 108 r = this.impl.compareTo(other); 109 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(0))); 110 111 this.impl.setLength(intOrg); 112 other.setLength(intOrg); 113 } 114 115 @Test(timeout = 8000) testEquals()116 public void testEquals() { 117 boolean r; 118 JsonInfoConfigSgwPrefix other; 119 120 r = this.impl.equals(this.impl); 121 assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE)); 122 123 other = null; 124 r = this.impl.equals(other); 125 assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE)); 126 127 final Object otherObj = new Object(); 128 r = this.impl.equals(otherObj); 129 assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE)); 130 131 other = new JsonInfoConfigSgwPrefix(); 132 r = this.impl.equals(other); 133 assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE)); 134 135 other.setLength(11); 136 r = this.impl.equals(other); 137 assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE)); 138 } 139 140 @Test(timeout = 8000) testHashCode()141 public void testHashCode() throws UnknownHostException { 142 int r = this.impl.hashCode(); 143 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(961))); 144 145 /* set */ 146 final InetAddress addr = InetAddress.getByName("127.0.0.1"); 147 this.impl.setPrefix(addr); 148 this.impl.setLength(11); 149 150 r = this.impl.hashCode(); 151 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-558694929))); 152 } 153 154 @Test(timeout = 8000) testToString()155 public void testToString() { 156 final String r = this.impl.toString(); 157 assertThat(r, notNullValue()); 158 } 159 }