### Question:
ChargeRange { public boolean amountIsWithinRange(final BigDecimal amountProportionalTo) { return to.map(bigDecimal -> from.compareTo(amountProportionalTo) <= 0 && bigDecimal.compareTo(amountProportionalTo) > 0) .orElseGet(() -> from.compareTo(amountProportionalTo) <= 0); } ChargeRange(
      final BigDecimal from,
      @SuppressWarnings("OptionalUsedAsFieldOrParameterType") final Optional<BigDecimal> to); boolean amountIsWithinRange(final BigDecimal amountProportionalTo); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void amountIsWithinRange() throws Exception { final ChargeRange testSubject1 = new ChargeRange(BigDecimal.TEN, Optional.empty()); Assert.assertFalse(testSubject1.amountIsWithinRange(BigDecimal.ZERO)); Assert.assertFalse(testSubject1.amountIsWithinRange(BigDecimal.ONE)); Assert.assertTrue(testSubject1.amountIsWithinRange(BigDecimal.TEN)); Assert.assertTrue(testSubject1.amountIsWithinRange(BigDecimal.TEN.add(BigDecimal.ONE))); final ChargeRange testSubject2 = new ChargeRange(BigDecimal.ZERO, Optional.of(BigDecimal.TEN)); Assert.assertTrue(testSubject2.amountIsWithinRange(BigDecimal.ZERO)); Assert.assertTrue(testSubject2.amountIsWithinRange(BigDecimal.ONE)); Assert.assertFalse(testSubject2.amountIsWithinRange(BigDecimal.TEN)); Assert.assertFalse(testSubject2.amountIsWithinRange(BigDecimal.TEN.add(BigDecimal.ONE))); }