### Question:
OSMReaderUtility { public static long parseDuration(String str) throws IllegalArgumentException { long seconds = 0; if (str == null) return 0; if (str.startsWith("P")) { Duration dur; try { dur = DatatypeFactory.newInstance().newDuration(str); seconds = dur.getTimeInMillis(STATIC_DATE) / 1000; } catch (Exception ex) { throw new IllegalArgumentException("Cannot parse duration tag value: " + str, ex); } return seconds; } try { int index = str.indexOf(":"); if (index > 0) { String hourStr = str.substring(0, index); String minStr = str.substring(index + 1); String secondsStr = "0"; index = minStr.indexOf(":"); if (index > 0) { secondsStr = minStr.substring(index + 1, index + 3); minStr = minStr.substring(0, index); } seconds += Integer.parseInt(hourStr) * 60L * 60; seconds += Integer.parseInt(minStr) * 60L; seconds += Integer.parseInt(secondsStr); return seconds; } else { seconds = Integer.parseInt(str) * 60; } } catch (Exception ex) { throw new IllegalArgumentException("Cannot parse duration tag value: " + str, ex); } return seconds; }  static long parseDuration(String str);  }### Answer:
@Test public void testParseDuration() { assertEquals(10 * 60, OSMReaderUtility.parseDuration("00:10")); assertEquals(35 * 60, OSMReaderUtility.parseDuration("35")); assertEquals(70 * 60, OSMReaderUtility.parseDuration("01:10")); assertEquals(70 * 60 + 2, OSMReaderUtility.parseDuration("01:10:02")); assertEquals(0, OSMReaderUtility.parseDuration(null)); assertEquals(60 * 20 * 60, OSMReaderUtility.parseDuration("20:00")); assertEquals(20 * 60, OSMReaderUtility.parseDuration("0:20:00")); assertEquals((60 * 2 + 20) * 60 + 2, OSMReaderUtility.parseDuration("02:20:02")); assertEquals(31 + 31, OSMReaderUtility.parseDuration("P2M") / (24 * 60 * 60)); assertEquals(2 * 60, OSMReaderUtility.parseDuration("PT2M")); assertEquals((5 * 60 + 12) * 60 + 36, OSMReaderUtility.parseDuration("PT5H12M36S")); }
@Test public void testWrongDurationFormats() { try { OSMReaderUtility.parseDuration("PT5h12m36s"); fail("parseDuration didn't throw when I expected it to"); } catch (IllegalArgumentException expectedException) { assertEquals(expectedException.getMessage(), "Cannot parse duration tag value: PT5h12m36s"); } try { OSMReaderUtility.parseDuration("oh"); fail("parseDuration didn't throw when I expected it to"); } catch (IllegalArgumentException expectedException) { assertEquals(expectedException.getMessage(), "Cannot parse duration tag value: oh"); } try { OSMReaderUtility.parseDuration("01:10:2"); fail("parseDuration didn't throw when I expected it to"); } catch (IllegalArgumentException expectedException) { assertEquals(expectedException.getMessage(), "Cannot parse duration tag value: 01:10:2"); } }