@Test
  public void testToStringEqualsAndHashcode() {
    ByteRange a = ByteRanges.fromLastNBytes(4);
    ByteRange b = ByteRanges.fromLastNBytes(4);
    assertEquals("ByteRanges should be equal", a, b);
    assertEquals("ByteRange hashcodes should be equal", a.hashCode(), b.hashCode());
    assertEquals("toString output not as expected", "ByteRange{lastNBytes=4}", a.toString());

    a = ByteRanges.fromOffsetRange(2, 5);
    assertFalse("ByteRanges should not be equal", a.equals(b));
    b = ByteRanges.fromOffsetRange(2, 5);
    assertEquals("ByteRanges should be equal", a, b);
    assertEquals("ByteRange hashcodes should be equal", a.hashCode(), b.hashCode());
    assertEquals("toString output not as expected", "ByteRange{startOffset=2, endOffset=5}", a.toString());

    a = ByteRanges.fromStartOffset(7);
    assertFalse("ByteRanges should not be equal", a.equals(b));
    b = ByteRanges.fromStartOffset(7);
    assertEquals("ByteRanges should be equal", a, b);
    assertEquals("ByteRange hashcodes should be equal", a.hashCode(), b.hashCode());
    assertEquals("toString output not as expected", "ByteRange{startOffset=7}", a.toString());
  }
Test toString, equals, and hashCode methods.
ambry-api/src/test/java/com/github/ambry/router/ByteRangeTest.java