### Question:
Interval { public static Interval parse(String s) { if (s.isEmpty()) { return NONE; } Matcher matcher = INTERVAL_PATTERN.matcher(s); if (!(matcher.matches() && matcher.groupCount() == 2)) { throw new IllegalArgumentException(s + " is not a valid interval. It must follow the pattern " + INTERVAL_PATTERN.pattern()); } return new Interval(Integer.parseInt(matcher.group(1)), Units.fromCode(matcher.group(2))); } Interval(int length, Units units); static Interval parse(String s); int getLength(); Units getUnits(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final Interval NONE; }### Answer:
@Test public void parseIntervals() { assertEquals(parse("15min"), new Interval(15, MINUTES)); assertEquals(parse("1hr"), new Interval(1, HOURS)); assertEquals(parse("1d"), new Interval(1, DAYS)); assertExceptionThrown("15minutes"); assertExceptionThrown("15 minutes"); assertExceptionThrown("min15"); assertExceptionThrown("12.2hr"); assertExceptionThrown("1d3min"); assertExceptionThrown("1d 3min"); }