Updated the testEqualityIPv4 and testEqualityIPv6 to use
Google's EqualsTester.
Showing
1 changed file
with
25 additions
and
58 deletions
... | @@ -18,6 +18,7 @@ package org.onlab.packet; | ... | @@ -18,6 +18,7 @@ package org.onlab.packet; |
18 | import java.net.InetAddress; | 18 | import java.net.InetAddress; |
19 | 19 | ||
20 | import com.google.common.net.InetAddresses; | 20 | import com.google.common.net.InetAddresses; |
21 | +import com.google.common.testing.EqualsTester; | ||
21 | import org.junit.Test; | 22 | import org.junit.Test; |
22 | 23 | ||
23 | import static org.hamcrest.Matchers.is; | 24 | import static org.hamcrest.Matchers.is; |
... | @@ -728,19 +729,16 @@ public class IpAddressTest { | ... | @@ -728,19 +729,16 @@ public class IpAddressTest { |
728 | */ | 729 | */ |
729 | @Test | 730 | @Test |
730 | public void testEqualityIPv4() { | 731 | public void testEqualityIPv4() { |
731 | - IpAddress addr1, addr2; | 732 | + new EqualsTester() |
732 | - | 733 | + .addEqualityGroup(IpAddress.valueOf("1.2.3.4"), |
733 | - addr1 = IpAddress.valueOf("1.2.3.4"); | 734 | + IpAddress.valueOf("1.2.3.4")) |
734 | - addr2 = IpAddress.valueOf("1.2.3.4"); | 735 | + .addEqualityGroup(IpAddress.valueOf("1.2.3.5"), |
735 | - assertThat(addr1, is(addr2)); | 736 | + IpAddress.valueOf("1.2.3.5")) |
736 | - | 737 | + .addEqualityGroup(IpAddress.valueOf("0.0.0.0"), |
737 | - addr1 = IpAddress.valueOf("0.0.0.0"); | 738 | + IpAddress.valueOf("0.0.0.0")) |
738 | - addr2 = IpAddress.valueOf("0.0.0.0"); | 739 | + .addEqualityGroup(IpAddress.valueOf("255.255.255.255"), |
739 | - assertThat(addr1, is(addr2)); | 740 | + IpAddress.valueOf("255.255.255.255")) |
740 | - | 741 | + .testEquals(); |
741 | - addr1 = IpAddress.valueOf("255.255.255.255"); | ||
742 | - addr2 = IpAddress.valueOf("255.255.255.255"); | ||
743 | - assertThat(addr1, is(addr2)); | ||
744 | } | 742 | } |
745 | 743 | ||
746 | /** | 744 | /** |
... | @@ -748,51 +746,20 @@ public class IpAddressTest { | ... | @@ -748,51 +746,20 @@ public class IpAddressTest { |
748 | */ | 746 | */ |
749 | @Test | 747 | @Test |
750 | public void testEqualityIPv6() { | 748 | public void testEqualityIPv6() { |
751 | - IpAddress addr1, addr2; | 749 | + new EqualsTester() |
752 | - | 750 | + .addEqualityGroup( |
753 | - addr1 = IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8888"); | 751 | + IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8888"), |
754 | - addr2 = IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8888"); | 752 | + IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8888")) |
755 | - assertThat(addr1, is(addr2)); | 753 | + .addEqualityGroup( |
756 | - | 754 | + IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:888a"), |
757 | - addr1 = IpAddress.valueOf("::"); | 755 | + IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:888a")) |
758 | - addr2 = IpAddress.valueOf("::"); | 756 | + .addEqualityGroup( |
759 | - assertThat(addr1, is(addr2)); | 757 | + IpAddress.valueOf("::"), |
760 | - | 758 | + IpAddress.valueOf("::")) |
761 | - addr1 = IpAddress.valueOf("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); | 759 | + .addEqualityGroup( |
762 | - addr2 = IpAddress.valueOf("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); | 760 | + IpAddress.valueOf("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"), |
763 | - assertThat(addr1, is(addr2)); | 761 | + IpAddress.valueOf("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")) |
764 | - } | 762 | + .testEquals(); |
765 | - | ||
766 | - /** | ||
767 | - * Tests non-equality of {@link IpAddress} for IPv4. | ||
768 | - */ | ||
769 | - @Test | ||
770 | - public void testNonEqualityIPv4() { | ||
771 | - IpAddress addr1, addr2, addr3, addr4; | ||
772 | - | ||
773 | - addr1 = IpAddress.valueOf("1.2.3.4"); | ||
774 | - addr2 = IpAddress.valueOf("1.2.3.5"); | ||
775 | - addr3 = IpAddress.valueOf("0.0.0.0"); | ||
776 | - addr4 = IpAddress.valueOf("255.255.255.255"); | ||
777 | - assertThat(addr1, is(not(addr2))); | ||
778 | - assertThat(addr3, is(not(addr2))); | ||
779 | - assertThat(addr4, is(not(addr2))); | ||
780 | - } | ||
781 | - | ||
782 | - /** | ||
783 | - * Tests non-equality of {@link IpAddress} for IPv6. | ||
784 | - */ | ||
785 | - @Test | ||
786 | - public void testNonEqualityIPv6() { | ||
787 | - IpAddress addr1, addr2, addr3, addr4; | ||
788 | - | ||
789 | - addr1 = IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8888"); | ||
790 | - addr2 = IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:888A"); | ||
791 | - addr3 = IpAddress.valueOf("::"); | ||
792 | - addr4 = IpAddress.valueOf("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); | ||
793 | - assertThat(addr1, is(not(addr2))); | ||
794 | - assertThat(addr3, is(not(addr2))); | ||
795 | - assertThat(addr4, is(not(addr2))); | ||
796 | } | 763 | } |
797 | 764 | ||
798 | /** | 765 | /** | ... | ... |
-
Please register or login to post a comment