### Question:
DurationPropertyDefinition extends PropertyDefinition<Long> { @Override public Long decodeValue(String value) throws PropertyException { ifNull(value); if (allowUnlimited && value.trim().equalsIgnoreCase(UNLIMITED)) { return -1L; } long ms; try { ms = DurationUnit.parseValue(value); } catch (NumberFormatException e) { throw PropertyException.illegalPropertyValueException(this, value); } if (ms % baseUnit.getDuration() != 0) { throw PropertyException.illegalPropertyValueException(this, value); } Long i = (long) baseUnit.fromMilliSeconds(ms); try { validateValue(i); } catch (PropertyException e) { throw PropertyException.illegalPropertyValueException(this, value); } return i; } private  DurationPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d,
      String propertyName, EnumSet<PropertyOption> options,
      AdministratorAction adminAction,
      DefaultBehaviorProvider<Long> defaultBehavior, DurationUnit baseUnit,
      DurationUnit maximumUnit, Long lowerLimit, Long upperLimit,
      boolean allowUnlimited); static Builder createBuilder(AbstractManagedObjectDefinition<?, ?> d,
      String propertyName); DurationUnit getBaseUnit(); DurationUnit getMaximumUnit(); long getLowerLimit(); Long getUpperLimit(); boolean isAllowUnlimited(); @Override void validateValue(Long value); @Override String encodeValue(Long value); @Override Long decodeValue(String value); @Override R accept(PropertyDefinitionVisitor<R, P> v, P p); @Override R accept(PropertyValueVisitor<R, P> v, Long value, P p); @Override void toString(StringBuilder builder); @Override int compare(Long o1, Long o2);  }### Answer:
@Test public void testIsAllowUnlimited1() { DurationPropertyDefinition.Builder builder = createTestBuilder(); builder.setAllowUnlimited(true); DurationPropertyDefinition spd = buildTestDefinition(builder); spd.decodeValue("unlimited"); }
@Test(expectedExceptions = PropertyException.class) public void testIsAllowUnlimited2() { DurationPropertyDefinition.Builder builder = createTestBuilder(); builder.setAllowUnlimited(false); DurationPropertyDefinition spd = buildTestDefinition(builder); spd.decodeValue("unlimited"); }
@Test(dataProvider = "decodeValueData") public void testDecodeValue(String value, Long expectedValue) { DurationPropertyDefinition.Builder builder = createTestBuilder(); builder.setAllowUnlimited(true); builder.setBaseUnit(DurationUnit.HOURS); builder.setMaximumUnit(DurationUnit.DAYS); DurationPropertyDefinition spd = buildTestDefinition(builder); assertEquals(spd.decodeValue(value), expectedValue); }
@Test(dataProvider = "decodeValueData2", expectedExceptions = {PropertyException.class}) public void testDecodeValue(String value) { DurationPropertyDefinition.Builder builder = createTestBuilder(); builder.setAllowUnlimited(false); builder.setBaseUnit(DurationUnit.HOURS); builder.setMaximumUnit(DurationUnit.DAYS); builder.setLowerLimit(5L); builder.setUpperLimit(10L); DurationPropertyDefinition spd = buildTestDefinition(builder); spd.decodeValue(value); }