### Question:
DurationUtil { public static Duration parse(String str) { if (StringUtils.isBlank(str)) { return DEFAULT_DURATION; } if (str.contains(MILLIS_SECOND_UNIT)) { Long value = doParse(MILLIS_SECOND_UNIT, str); return value == null ? null : Duration.ofMillis(value); } else if (str.contains(DAY_UNIT)) { Long value = doParse(DAY_UNIT, str); return value == null ? null : Duration.ofDays(value); } else if (str.contains(HOUR_UNIT)) { Long value = doParse(HOUR_UNIT, str); return value == null ? null : Duration.ofHours(value); } else if (str.contains(MINUTE_UNIT)) { Long value = doParse(MINUTE_UNIT, str); return value == null ? null : Duration.ofMinutes(value); } else if (str.contains(SECOND_UNIT)) { Long value = doParse(SECOND_UNIT, str); return value == null ? null : Duration.ofSeconds(value); } try { int millis = Integer.parseInt(str); return Duration.ofMillis(millis); } catch (Exception e) { throw new UnsupportedOperationException(str + " can't parse to duration", e); } }  static Duration parse(String str); static final Duration DEFAULT_DURATION; static final String DAY_UNIT; static final String HOUR_UNIT; static final String MINUTE_UNIT; static final String SECOND_UNIT; static final String MILLIS_SECOND_UNIT; }### Answer:
@Test public void testParse() { Assertions.assertNull(DurationUtil.parse("d")); Assertions.assertNull(DurationUtil.parse("h")); Assertions.assertNull(DurationUtil.parse("m")); Assertions.assertNull(DurationUtil.parse("s")); Assertions.assertNull(DurationUtil.parse("ms")); Assertions.assertEquals(-1L, DurationUtil.parse("").getSeconds()); Assertions.assertEquals(0L, DurationUtil.parse("8").getSeconds()); Assertions.assertEquals(0L, DurationUtil.parse("8ms").getSeconds()); Assertions.assertEquals(8L, DurationUtil.parse("8s").getSeconds()); Assertions.assertEquals(480L, DurationUtil.parse("8m").getSeconds()); Assertions.assertEquals(28800L, DurationUtil.parse("8h").getSeconds()); Assertions.assertEquals(691200L, DurationUtil.parse("8d").getSeconds()); }
@Test public void testParseThrowException() { Assertions.assertThrows(UnsupportedOperationException.class, () -> DurationUtil.parse("a")); Assertions.assertThrows(UnsupportedOperationException.class, () -> DurationUtil.parse("as")); }