DiskSpaceThreshold { public boolean withinThreshold(DiskSpace diskSpace) { return withinThreshold(diskSpace.getFreeSpace(), diskSpace.getMaxSpace()); } DiskSpaceThreshold(final long threshold, final boolean isPercentage); static DiskSpaceThreshold parse(String thresholdString); long getThresholdValue(); boolean isPercentage(); boolean withinThreshold(DiskSpace diskSpace); boolean withinThreshold(long freeSpace, long maxSpace);  }
@Test public void valueWithinThresholdPasses() { DiskSpaceThreshold t = new DiskSpaceThreshold(1024L, false); assertThat(t.withinThreshold(1200, 1500)).isTrue(); }
@Test public void valueOutsideThresholdFails() { DiskSpaceThreshold t = new DiskSpaceThreshold(1024L, false); assertThat(t.withinThreshold(500, 1500)).isFalse(); }
@Test public void percentageValueWithinThresholdPasses() { DiskSpaceThreshold t = new DiskSpaceThreshold(5L, true); assertThat(t.withinThreshold(600, 1000)).isTrue(); }
@Test public void percentageValueOutsideThresholdFails() { DiskSpaceThreshold t = new DiskSpaceThreshold(5L, true); assertThat(t.withinThreshold(50, 1000)).isFalse(); }
@Test public void percentageWithZeroTotalFails() { DiskSpaceThreshold t = new DiskSpaceThreshold(5L, true); assertThat(t.withinThreshold(0, 0)).isFalse(); }