### Question:
TimeUnitParser { public static long parse(String value, TimeUnit timeUnit) { try { return timeUnit.convert(Long.parseLong(value), TimeUnit.MILLISECONDS); } catch (NumberFormatException e) { long millis = PARSER.parsePeriod(value.replace(" ", "")).toStandardDuration().getMillis(); return timeUnit.convert(millis, TimeUnit.MILLISECONDS); } }  static long parse(String value, TimeUnit timeUnit);  }### Answer:
@Test public void shouldParseMillisFromString() throws ParseException { assertEquals( 10, TimeUnitParser.parse( "10ms", TimeUnit.MILLISECONDS ) ); assertEquals( 10000, TimeUnitParser.parse( "10s", TimeUnit.MILLISECONDS ) ); assertEquals( 60000, TimeUnitParser.parse( "1min", TimeUnit.MILLISECONDS ) ); assertEquals( 3600000, TimeUnitParser.parse( "1h", TimeUnit.MILLISECONDS ) ); assertEquals( 3600000, TimeUnitParser.parse( "1hr", TimeUnit.MILLISECONDS ) ); }
@Test public void shouldInterpretValueWithoutSuffixAsMillis() { assertEquals( 10, TimeUnitParser.parse( "10", TimeUnit.MILLISECONDS ) ); assertEquals( 10, TimeUnitParser.parse( "10000", TimeUnit.SECONDS ) ); }
@Test public void shouldParseSecondsFromString() throws ParseException { assertEquals( 0, TimeUnitParser.parse( "10ms", TimeUnit.SECONDS ) ); assertEquals( 10, TimeUnitParser.parse( "10s", TimeUnit.SECONDS ) ); assertEquals( 60, TimeUnitParser.parse( "1min", TimeUnit.SECONDS ) ); assertEquals( 3600, TimeUnitParser.parse( "1h", TimeUnit.SECONDS ) ); assertEquals( 3600, TimeUnitParser.parse( "1hr", TimeUnit.SECONDS ) ); }