Ray Milkey

Refactor test to use Guava EqualsTester

Change-Id: I337acb65a71579f7d36f66c38548e2f6cdc31596
...@@ -21,12 +21,12 @@ import org.onlab.packet.IpPrefix; ...@@ -21,12 +21,12 @@ import org.onlab.packet.IpPrefix;
21 import org.onlab.packet.MacAddress; 21 import org.onlab.packet.MacAddress;
22 import org.onlab.packet.VlanId; 22 import org.onlab.packet.VlanId;
23 23
24 +import com.google.common.testing.EqualsTester;
25 +
24 import static org.hamcrest.MatcherAssert.assertThat; 26 import static org.hamcrest.MatcherAssert.assertThat;
25 -import static org.hamcrest.Matchers.containsString;
26 import static org.hamcrest.Matchers.equalTo; 27 import static org.hamcrest.Matchers.equalTo;
27 import static org.hamcrest.Matchers.instanceOf; 28 import static org.hamcrest.Matchers.instanceOf;
28 import static org.hamcrest.Matchers.is; 29 import static org.hamcrest.Matchers.is;
29 -import static org.hamcrest.Matchers.not;
30 import static org.hamcrest.Matchers.notNullValue; 30 import static org.hamcrest.Matchers.notNullValue;
31 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; 31 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
32 import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility; 32 import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
...@@ -121,33 +121,6 @@ public class CriteriaTest { ...@@ -121,33 +121,6 @@ public class CriteriaTest {
121 } 121 }
122 122
123 /** 123 /**
124 - * Checks the equals() and toString() methods of a Criterion class.
125 - *
126 - * @param c1 first object to compare
127 - * @param c1match object that should be equal to the first
128 - * @param c2 object that should be not equal to the first
129 - * @param clazz Class object for the Criterion subclass
130 - * @param <T> type of the arguments
131 - */
132 - private <T extends Criterion> void checkEqualsAndToString(T c1, T c1match,
133 - T c2, Class clazz) {
134 - assertThat(c1, instanceOf(clazz));
135 - assertThat(c1match, instanceOf(clazz));
136 - assertThat(c2, instanceOf(clazz));
137 -
138 - assertThat(c1, is(equalTo(c1match)));
139 - assertThat(c1, is(not(equalTo(c2))));
140 - assertThat(c1, is(not(equalTo(new Object()))));
141 -
142 - // Make sure the enumerated type appears in the toString() output and
143 - // the toString output is unique.
144 - assertThat(c1.toString(), containsString(c1.type().toString()));
145 - assertThat(c1.toString(), equalTo(c1match.toString()));
146 - assertThat(c1.toString(), not(equalTo(c2.toString())));
147 - }
148 -
149 -
150 - /**
151 * Check that the Criteria class is a valid utility class. 124 * Check that the Criteria class is a valid utility class.
152 */ 125 */
153 @Test 126 @Test
...@@ -193,17 +166,10 @@ public class CriteriaTest { ...@@ -193,17 +166,10 @@ public class CriteriaTest {
193 */ 166 */
194 @Test 167 @Test
195 public void testPortCriterionEquals() { 168 public void testPortCriterionEquals() {
196 - checkEqualsAndToString(matchInPort1, sameAsMatchInPort1, matchInPort2, 169 + new EqualsTester()
197 - Criteria.PortCriterion.class); 170 + .addEqualityGroup(matchInPort1, sameAsMatchInPort1)
198 - } 171 + .addEqualityGroup(matchInPort2)
199 - 172 + .testEquals();
200 - /**
201 - * Test the hashCode() method of the PortCriterion class.
202 - */
203 - @Test
204 - public void testPortCriterionHashCode() {
205 - assertThat(matchInPort1.hashCode(), is(equalTo(sameAsMatchInPort1.hashCode())));
206 - assertThat(matchInPort1.hashCode(), is(not(equalTo(matchInPort2.hashCode()))));
207 } 173 }
208 174
209 // EthCriterion class 175 // EthCriterion class
...@@ -239,20 +205,12 @@ public class CriteriaTest { ...@@ -239,20 +205,12 @@ public class CriteriaTest {
239 */ 205 */
240 @Test 206 @Test
241 public void testEthCriterionEquals() { 207 public void testEthCriterionEquals() {
242 - checkEqualsAndToString(matchEth1, sameAsMatchEth1, matchEth2, 208 + new EqualsTester()
243 - Criteria.EthCriterion.class); 209 + .addEqualityGroup(matchEth1, sameAsMatchEth1)
210 + .addEqualityGroup(matchEth2)
211 + .testEquals();
244 } 212 }
245 213
246 - /**
247 - * Test the hashCode() method of the EthCriterion class.
248 - */
249 - @Test
250 - public void testEthCriterionHashCode() {
251 - assertThat(matchEth1.hashCode(), is(equalTo(sameAsMatchEth1.hashCode())));
252 - assertThat(matchEth1.hashCode(), is(not(equalTo(matchEth2.hashCode()))));
253 - }
254 -
255 -
256 // TcpPortCriterion class 214 // TcpPortCriterion class
257 215
258 /** 216 /**
...@@ -286,20 +244,12 @@ public class CriteriaTest { ...@@ -286,20 +244,12 @@ public class CriteriaTest {
286 */ 244 */
287 @Test 245 @Test
288 public void testTcpPortCriterionEquals() { 246 public void testTcpPortCriterionEquals() {
289 - checkEqualsAndToString(matchTcpPort1, sameAsMatchTcpPort1, matchTcpPort2, 247 + new EqualsTester()
290 - Criteria.TcpPortCriterion.class); 248 + .addEqualityGroup(matchTcpPort1, sameAsMatchTcpPort1)
249 + .addEqualityGroup(matchTcpPort2)
250 + .testEquals();
291 } 251 }
292 252
293 - /**
294 - * Test the hashCode() method of the TcpPortCriterion class.
295 - */
296 - @Test
297 - public void testTcpPortCriterionHashCode() {
298 - assertThat(matchTcpPort1.hashCode(), is(equalTo(sameAsMatchTcpPort1.hashCode())));
299 - assertThat(matchTcpPort1.hashCode(), is(not(equalTo(matchTcpPort2.hashCode()))));
300 - }
301 -
302 -
303 // EthTypeCriterion class 253 // EthTypeCriterion class
304 254
305 /** 255 /**
...@@ -321,20 +271,12 @@ public class CriteriaTest { ...@@ -321,20 +271,12 @@ public class CriteriaTest {
321 */ 271 */
322 @Test 272 @Test
323 public void testEthTypeCriterionEquals() { 273 public void testEthTypeCriterionEquals() {
324 - checkEqualsAndToString(matchEthType1, sameAsMatchEthType1, matchEthType2, 274 + new EqualsTester()
325 - Criteria.EthTypeCriterion.class); 275 + .addEqualityGroup(matchEthType1, sameAsMatchEthType1)
326 - } 276 + .addEqualityGroup(matchEthType2)
327 - 277 + .testEquals();
328 - /**
329 - * Test the hashCode() method of the EthTypeCriterion class.
330 - */
331 - @Test
332 - public void testEthTypeCriterionHashCode() {
333 - assertThat(matchInPort1.hashCode(), is(equalTo(sameAsMatchInPort1.hashCode())));
334 - assertThat(matchInPort1.hashCode(), is(not(equalTo(matchInPort2.hashCode()))));
335 } 278 }
336 279
337 -
338 // VlanIdCriterion class 280 // VlanIdCriterion class
339 281
340 /** 282 /**
...@@ -355,17 +297,10 @@ public class CriteriaTest { ...@@ -355,17 +297,10 @@ public class CriteriaTest {
355 */ 297 */
356 @Test 298 @Test
357 public void testVlanIdCriterionEquals() { 299 public void testVlanIdCriterionEquals() {
358 - checkEqualsAndToString(matchVlanId1, sameAsMatchVlanId1, matchVlanId2, 300 + new EqualsTester()
359 - Criteria.VlanIdCriterion.class); 301 + .addEqualityGroup(matchVlanId1, sameAsMatchVlanId1)
360 - } 302 + .addEqualityGroup(matchVlanId2)
361 - 303 + .testEquals();
362 - /**
363 - * Test the hashCode() method of the VlanIdCriterion class.
364 - */
365 - @Test
366 - public void testVlanIdCriterionHashCode() {
367 - assertThat(matchVlanId1.hashCode(), is(equalTo(sameAsMatchVlanId1.hashCode())));
368 - assertThat(matchVlanId1.hashCode(), is(not(equalTo(matchVlanId2.hashCode()))));
369 } 304 }
370 305
371 // VlanPcpCriterion class 306 // VlanPcpCriterion class
...@@ -388,17 +323,10 @@ public class CriteriaTest { ...@@ -388,17 +323,10 @@ public class CriteriaTest {
388 */ 323 */
389 @Test 324 @Test
390 public void testVlanPcpCriterionEquals() { 325 public void testVlanPcpCriterionEquals() {
391 - checkEqualsAndToString(matchVlanPcp1, sameAsMatchVlanPcp1, matchVlanPcp2, 326 + new EqualsTester()
392 - Criteria.VlanPcpCriterion.class); 327 + .addEqualityGroup(matchVlanPcp1, sameAsMatchVlanPcp1)
393 - } 328 + .addEqualityGroup(matchVlanPcp2)
394 - 329 + .testEquals();
395 - /**
396 - * Test the hashCode() method of the VlnPcpCriterion class.
397 - */
398 - @Test
399 - public void testVlanPcpCriterionHashCode() {
400 - assertThat(matchVlanPcp1.hashCode(), is(equalTo(sameAsMatchVlanPcp1.hashCode())));
401 - assertThat(matchVlanPcp1.hashCode(), is(not(equalTo(matchVlanPcp2.hashCode()))));
402 } 330 }
403 331
404 // IpProtocolCriterion class 332 // IpProtocolCriterion class
...@@ -421,17 +349,10 @@ public class CriteriaTest { ...@@ -421,17 +349,10 @@ public class CriteriaTest {
421 */ 349 */
422 @Test 350 @Test
423 public void testIpProtocolCriterionEquals() { 351 public void testIpProtocolCriterionEquals() {
424 - checkEqualsAndToString(matchIpProtocol1, sameAsMatchIpProtocol1, 352 + new EqualsTester()
425 - matchIpProtocol2, Criteria.IPProtocolCriterion.class); 353 + .addEqualityGroup(matchIpProtocol1, sameAsMatchIpProtocol1)
426 - } 354 + .addEqualityGroup(matchIpProtocol2)
427 - 355 + .testEquals();
428 - /**
429 - * Test the hashCode() method of the IpProtocolCriterion class.
430 - */
431 - @Test
432 - public void testIpProtocolCriterionHashCode() {
433 - assertThat(matchIpProtocol1.hashCode(), is(equalTo(sameAsMatchIpProtocol1.hashCode())));
434 - assertThat(matchIpProtocol1.hashCode(), is(not(equalTo(matchIpProtocol2.hashCode()))));
435 } 356 }
436 357
437 // IPCriterion class 358 // IPCriterion class
...@@ -467,17 +388,10 @@ public class CriteriaTest { ...@@ -467,17 +388,10 @@ public class CriteriaTest {
467 */ 388 */
468 @Test 389 @Test
469 public void testIPCriterionEquals() { 390 public void testIPCriterionEquals() {
470 - checkEqualsAndToString(matchIp1, sameAsMatchIp1, matchIp2, 391 + new EqualsTester()
471 - Criteria.IPCriterion.class); 392 + .addEqualityGroup(matchIp1, sameAsMatchIp1)
472 - } 393 + .addEqualityGroup(matchIp2)
473 - 394 + .testEquals();
474 - /**
475 - * Test the hashCode() method of the IpCriterion class.
476 - */
477 - @Test
478 - public void testIPCriterionHashCode() {
479 - assertThat(matchIp1.hashCode(), is(equalTo(sameAsMatchIp1.hashCode())));
480 - assertThat(matchIp1.hashCode(), is(not(equalTo(matchIp2.hashCode()))));
481 } 395 }
482 396
483 // LambdaCriterion class 397 // LambdaCriterion class
...@@ -500,17 +414,10 @@ public class CriteriaTest { ...@@ -500,17 +414,10 @@ public class CriteriaTest {
500 */ 414 */
501 @Test 415 @Test
502 public void testLambdaCriterionEquals() { 416 public void testLambdaCriterionEquals() {
503 - checkEqualsAndToString(matchLambda1, sameAsMatchLambda1, matchLambda2, 417 + new EqualsTester()
504 - Criteria.LambdaCriterion.class); 418 + .addEqualityGroup(matchLambda1, sameAsMatchLambda1)
505 - } 419 + .addEqualityGroup(matchLambda2)
506 - 420 + .testEquals();
507 - /**
508 - * Test the hashCode() method of the LambdaCriterion class.
509 - */
510 - @Test
511 - public void testLambdaCriterionHashCode() {
512 - assertThat(matchLambda1.hashCode(), is(equalTo(sameAsMatchLambda1.hashCode())));
513 - assertThat(matchLambda1.hashCode(), is(not(equalTo(matchLambda2.hashCode()))));
514 } 421 }
515 422
516 // OpticalSignalTypeCriterion class 423 // OpticalSignalTypeCriterion class
...@@ -533,18 +440,9 @@ public class CriteriaTest { ...@@ -533,18 +440,9 @@ public class CriteriaTest {
533 */ 440 */
534 @Test 441 @Test
535 public void testOpticalSignalTypeCriterionEquals() { 442 public void testOpticalSignalTypeCriterionEquals() {
536 - checkEqualsAndToString(matchSignalLambda1, sameAsMatchSignalLambda1, 443 + new EqualsTester()
537 - matchSignalLambda2, 444 + .addEqualityGroup(matchSignalLambda1, sameAsMatchSignalLambda1)
538 - Criteria.OpticalSignalTypeCriterion.class); 445 + .addEqualityGroup(matchSignalLambda2)
539 - } 446 + .testEquals();
540 -
541 - /**
542 - * Test the hashCode() method of the OpticalSignalTypeCriterion class.
543 - */
544 - @Test
545 - public void testOpticalSignalTypeCriterionHashCode() {
546 - assertThat(matchSignalLambda1.hashCode(), is(equalTo(sameAsMatchSignalLambda1.hashCode())));
547 - assertThat(matchSignalLambda1.hashCode(), is(not(equalTo(matchSignalLambda2.hashCode()))));
548 } 447 }
549 -
550 } 448 }
......