Committed by
Gerrit Code Review
Increase coverage by using guava EqualsTester
Change-Id: I2c5cef7258407168c3ef7ab4ec9efdf332457caf
Showing
1 changed file
with
44 additions
and
27 deletions
| ... | @@ -22,8 +22,9 @@ import org.onlab.packet.IpPrefix; | ... | @@ -22,8 +22,9 @@ import org.onlab.packet.IpPrefix; |
| 22 | import org.onlab.packet.MacAddress; | 22 | import org.onlab.packet.MacAddress; |
| 23 | import org.onlab.packet.VlanId; | 23 | import org.onlab.packet.VlanId; |
| 24 | 24 | ||
| 25 | +import com.google.common.testing.EqualsTester; | ||
| 26 | + | ||
| 25 | import static org.hamcrest.MatcherAssert.assertThat; | 27 | import static org.hamcrest.MatcherAssert.assertThat; |
| 26 | -import static org.hamcrest.Matchers.containsString; | ||
| 27 | import static org.hamcrest.Matchers.equalTo; | 28 | import static org.hamcrest.Matchers.equalTo; |
| 28 | import static org.hamcrest.Matchers.instanceOf; | 29 | import static org.hamcrest.Matchers.instanceOf; |
| 29 | import static org.hamcrest.Matchers.is; | 30 | import static org.hamcrest.Matchers.is; |
| ... | @@ -62,23 +63,15 @@ public class InstructionsTest { | ... | @@ -62,23 +63,15 @@ public class InstructionsTest { |
| 62 | * @param c1 first object to compare | 63 | * @param c1 first object to compare |
| 63 | * @param c1match object that should be equal to the first | 64 | * @param c1match object that should be equal to the first |
| 64 | * @param c2 object that should be not equal to the first | 65 | * @param c2 object that should be not equal to the first |
| 65 | - * @param clazz Class object for the Criterion subclass | ||
| 66 | * @param <T> type of the arguments | 66 | * @param <T> type of the arguments |
| 67 | */ | 67 | */ |
| 68 | private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match, | 68 | private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match, |
| 69 | - T c2, Class clazz) { | 69 | + T c2) { |
| 70 | - assertThat(c1, instanceOf(clazz)); | 70 | + |
| 71 | - assertThat(c1match, instanceOf(clazz)); | 71 | + new EqualsTester() |
| 72 | - assertThat(c2, instanceOf(clazz)); | 72 | + .addEqualityGroup(c1, c1match) |
| 73 | - | 73 | + .addEqualityGroup(c2) |
| 74 | - assertThat(c1, is(equalTo(c1match))); | 74 | + .testEquals(); |
| 75 | - assertThat(c1, is(not(equalTo(c2)))); | ||
| 76 | - assertThat(c1, is(not(equalTo(new Object())))); | ||
| 77 | - | ||
| 78 | - // Make sure the toString() output is unique and correct. | ||
| 79 | - assertThat(c1.toString(), containsString("{")); | ||
| 80 | - assertThat(c1.toString(), equalTo(c1match.toString())); | ||
| 81 | - assertThat(c1.toString(), not(equalTo(c2.toString()))); | ||
| 82 | } | 75 | } |
| 83 | 76 | ||
| 84 | /** | 77 | /** |
| ... | @@ -165,8 +158,7 @@ public class InstructionsTest { | ... | @@ -165,8 +158,7 @@ public class InstructionsTest { |
| 165 | 158 | ||
| 166 | @Test | 159 | @Test |
| 167 | public void testOutputInstructionEquals() throws Exception { | 160 | public void testOutputInstructionEquals() throws Exception { |
| 168 | - checkEqualsAndToString(output1, sameAsOutput1, output2, | 161 | + checkEqualsAndToString(output1, sameAsOutput1, output2); |
| 169 | - Instructions.OutputInstruction.class); | ||
| 170 | } | 162 | } |
| 171 | 163 | ||
| 172 | /** | 164 | /** |
| ... | @@ -209,8 +201,7 @@ public class InstructionsTest { | ... | @@ -209,8 +201,7 @@ public class InstructionsTest { |
| 209 | public void testModLambdaInstructionEquals() throws Exception { | 201 | public void testModLambdaInstructionEquals() throws Exception { |
| 210 | checkEqualsAndToString(lambdaInstruction1, | 202 | checkEqualsAndToString(lambdaInstruction1, |
| 211 | sameAsLambdaInstruction1, | 203 | sameAsLambdaInstruction1, |
| 212 | - lambdaInstruction2, | 204 | + lambdaInstruction2); |
| 213 | - L0ModificationInstruction.ModLambdaInstruction.class); | ||
| 214 | } | 205 | } |
| 215 | 206 | ||
| 216 | /** | 207 | /** |
| ... | @@ -273,8 +264,7 @@ public class InstructionsTest { | ... | @@ -273,8 +264,7 @@ public class InstructionsTest { |
| 273 | public void testModEtherInstructionEquals() throws Exception { | 264 | public void testModEtherInstructionEquals() throws Exception { |
| 274 | checkEqualsAndToString(modEtherInstruction1, | 265 | checkEqualsAndToString(modEtherInstruction1, |
| 275 | sameAsModEtherInstruction1, | 266 | sameAsModEtherInstruction1, |
| 276 | - modEtherInstruction2, | 267 | + modEtherInstruction2); |
| 277 | - L2ModificationInstruction.ModEtherInstruction.class); | ||
| 278 | } | 268 | } |
| 279 | 269 | ||
| 280 | /** | 270 | /** |
| ... | @@ -323,8 +313,7 @@ public class InstructionsTest { | ... | @@ -323,8 +313,7 @@ public class InstructionsTest { |
| 323 | public void testModVlanIdInstructionEquals() throws Exception { | 313 | public void testModVlanIdInstructionEquals() throws Exception { |
| 324 | checkEqualsAndToString(modVlanId1, | 314 | checkEqualsAndToString(modVlanId1, |
| 325 | sameAsModVlanId1, | 315 | sameAsModVlanId1, |
| 326 | - modVlanId2, | 316 | + modVlanId2); |
| 327 | - L2ModificationInstruction.ModVlanIdInstruction.class); | ||
| 328 | } | 317 | } |
| 329 | 318 | ||
| 330 | /** | 319 | /** |
| ... | @@ -371,8 +360,7 @@ public class InstructionsTest { | ... | @@ -371,8 +360,7 @@ public class InstructionsTest { |
| 371 | public void testModVlanPcpInstructionEquals() throws Exception { | 360 | public void testModVlanPcpInstructionEquals() throws Exception { |
| 372 | checkEqualsAndToString(modVlanPcp1, | 361 | checkEqualsAndToString(modVlanPcp1, |
| 373 | sameAsModVlanPcp1, | 362 | sameAsModVlanPcp1, |
| 374 | - modVlanPcp2, | 363 | + modVlanPcp2); |
| 375 | - L2ModificationInstruction.ModVlanPcpInstruction.class); | ||
| 376 | } | 364 | } |
| 377 | 365 | ||
| 378 | /** | 366 | /** |
| ... | @@ -435,8 +423,7 @@ public class InstructionsTest { | ... | @@ -435,8 +423,7 @@ public class InstructionsTest { |
| 435 | public void testModIPInstructionEquals() throws Exception { | 423 | public void testModIPInstructionEquals() throws Exception { |
| 436 | checkEqualsAndToString(modIPInstruction1, | 424 | checkEqualsAndToString(modIPInstruction1, |
| 437 | sameAsModIPInstruction1, | 425 | sameAsModIPInstruction1, |
| 438 | - modIPInstruction2, | 426 | + modIPInstruction2); |
| 439 | - L3ModificationInstruction.ModIPInstruction.class); | ||
| 440 | } | 427 | } |
| 441 | 428 | ||
| 442 | /** | 429 | /** |
| ... | @@ -451,5 +438,35 @@ public class InstructionsTest { | ... | @@ -451,5 +438,35 @@ public class InstructionsTest { |
| 451 | is(not(equalTo(modIPInstruction2.hashCode())))); | 438 | is(not(equalTo(modIPInstruction2.hashCode())))); |
| 452 | } | 439 | } |
| 453 | 440 | ||
| 441 | + private Instruction modMplsLabelInstruction1 = Instructions.modMplsLabel(1); | ||
| 442 | + private Instruction sameAsModMplsLabelInstruction1 = Instructions.modMplsLabel(1); | ||
| 443 | + private Instruction modMplsLabelInstruction2 = Instructions.modMplsLabel(2); | ||
| 444 | + | ||
| 445 | + /** | ||
| 446 | + * Test the modMplsLabel method. | ||
| 447 | + */ | ||
| 448 | + @Test | ||
| 449 | + public void testModMplsMethod() { | ||
| 450 | + final Instruction instruction = Instructions.modMplsLabel(33); | ||
| 451 | + final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction = | ||
| 452 | + checkAndConvert(instruction, | ||
| 453 | + Instruction.Type.L2MODIFICATION, | ||
| 454 | + L2ModificationInstruction.ModMplsLabelInstruction.class); | ||
| 455 | + assertThat(modMplsLabelInstruction.label(), is(equalTo(33))); | ||
| 456 | + assertThat(modMplsLabelInstruction.subtype(), | ||
| 457 | + is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL))); | ||
| 458 | + } | ||
| 459 | + | ||
| 460 | + /** | ||
| 461 | + * Test the equals(), hashCode and toString() methods of the | ||
| 462 | + * ModMplsLabelInstruction class. | ||
| 463 | + */ | ||
| 464 | + | ||
| 465 | + @Test | ||
| 466 | + public void testModMplsLabelInstructionEquals() throws Exception { | ||
| 467 | + checkEqualsAndToString(modMplsLabelInstruction1, | ||
| 468 | + sameAsModMplsLabelInstruction1, | ||
| 469 | + modMplsLabelInstruction2); | ||
| 470 | + } | ||
| 454 | 471 | ||
| 455 | } | 472 | } | ... | ... |
-
Please register or login to post a comment