public TolerantLongComparison isWithin(long tolerance) {
    return new TolerantLongComparison() {
      @Override
      public void of(long expected) {
        Long actual = LongSubject.this.actual;
        checkNotNull(
            actual, "actual value cannot be null. tolerance=%s expected=%s", tolerance, expected);
        checkTolerance(tolerance);

        if (!equalWithinTolerance(actual, expected, tolerance)) {
          failWithoutActual(
              fact("expected", Long.toString(expected)),
              butWas(),
              fact("outside tolerance", Long.toString(tolerance)));
        }
      }
    };
  }
@Test
  public void isWithinOf() {
    assertThat(20000L).isWithin(0L).of(20000L);
    assertThat(20000L).isWithin(1L).of(20000L);
    assertThat(20000L).isWithin(10000L).of(20000L);
    assertThat(20000L).isWithin(10000L).of(30000L);
    assertThat(Long.MIN_VALUE).isWithin(1L).of(Long.MIN_VALUE + 1);
    assertThat(Long.MAX_VALUE).isWithin(1L).of(Long.MAX_VALUE - 1);
    assertThat(Long.MAX_VALUE / 2).isWithin(Long.MAX_VALUE).of(-Long.MAX_VALUE / 2);
    assertThat(-Long.MAX_VALUE / 2).isWithin(Long.MAX_VALUE).of(Long.MAX_VALUE / 2);

    assertThatIsWithinFails(20000L, 9999L, 30000L);
    assertThatIsWithinFails(20000L, 10000L, 30001L);
    assertThatIsWithinFails(Long.MIN_VALUE, 0L, Long.MAX_VALUE);
    assertThatIsWithinFails(Long.MAX_VALUE, 0L, Long.MIN_VALUE);
    assertThatIsWithinFails(Long.MIN_VALUE, 1L, Long.MIN_VALUE + 2);
    assertThatIsWithinFails(Long.MAX_VALUE, 1L, Long.MAX_VALUE - 2);
    // Don't fall for rollover
    assertThatIsWithinFails(Long.MIN_VALUE, 1L, Long.MAX_VALUE);
    assertThatIsWithinFails(Long.MAX_VALUE, 1L, Long.MIN_VALUE);
  }