BinaryNextHop implements NextHop { @Override public int compareTo(NextHop o) { CompareToBuilder builder = (new CompareToBuilder()) .append(getType(), o.getType()); if(o.getType() == Type.Binary) { builder.append(getAddress(), ((BinaryNextHop)o).getAddress()); } return builder.toComparison(); } BinaryNextHop(byte[] address); byte[] getAddress(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(NextHop o); @Override Type getType(); @Override String toString();  }
@Test public void testAllEquals() { BinaryNextHop a = new BinaryNextHop(new byte[] {1, 2, 3, 4}); BinaryNextHop b = new BinaryNextHop(new byte[] {1, 2, 3, 4}); Assert.assertTrue(a.compareTo(b) == 0); }
@Test public void testSmallerSize() { BinaryNextHop a = new BinaryNextHop(new byte[] {1, 2, 3}); BinaryNextHop b = new BinaryNextHop(new byte[] {1, 2, 3, 4}); Assert.assertTrue(a.compareTo(b) < 0); }
@Test public void testLargerSize() { BinaryNextHop a = new BinaryNextHop(new byte[] {1, 2, 3, 4}); BinaryNextHop b = new BinaryNextHop(new byte[] {1, 2, 3}); Assert.assertTrue(a.compareTo(b) > 0); }
@Test public void testSmallerContent() { BinaryNextHop a = new BinaryNextHop(new byte[] {1, 2, 3, 4}); BinaryNextHop b = new BinaryNextHop(new byte[] {1, 2, 3, 5}); Assert.assertTrue(a.compareTo(b) < 0); }
@Test public void testLargerContent() { BinaryNextHop a = new BinaryNextHop(new byte[] {1, 2, 3, 5}); BinaryNextHop b = new BinaryNextHop(new byte[] {1, 2, 3, 4}); Assert.assertTrue(a.compareTo(b) > 0); }