### Question:
GoTimeUtil { public static Integer durationSeconds(String duration) { BigDecimal ns = durationNs(duration); if (ns == null) { return null; } BigDecimal sec = ns.divide(new BigDecimal(1_000_000_000)); if (sec.compareTo(new BigDecimal(Integer.MAX_VALUE)) > 0) { throw new IllegalArgumentException("Integer Overflow"); } return sec.intValue(); } private  GoTimeUtil(); static Integer durationSeconds(String duration); static BigDecimal durationNs(String durationP);  }### Answer:
@Test public void testConversion() { Assert.assertEquals(new Integer(23), GoTimeUtil.durationSeconds("23s")); Assert.assertEquals(new Integer(0), GoTimeUtil.durationSeconds("0.5s")); Assert.assertEquals(new Integer(0), GoTimeUtil.durationSeconds("3ms")); Assert.assertEquals(new Integer(0), GoTimeUtil.durationSeconds("3ns")); Assert.assertEquals(new Integer(1), GoTimeUtil.durationSeconds("1002ms")); Assert.assertEquals(new Integer(123), GoTimeUtil.durationSeconds("2m3s")); Assert.assertEquals(new Integer(3663), GoTimeUtil.durationSeconds("1h1m3s")); Assert.assertEquals(new Integer(1810), GoTimeUtil.durationSeconds("0.5h0.1m4s")); Assert.assertEquals(new Integer(-15), GoTimeUtil.durationSeconds("-15s")); Assert.assertEquals(new Integer(30), GoTimeUtil.durationSeconds("2h-119.5m")); }
@Test public void testEmpty() { assertNull(GoTimeUtil.durationSeconds(null)); assertNull(GoTimeUtil.durationSeconds("")); assertNull(GoTimeUtil.durationSeconds(" ")); }
@Test(expected = IllegalArgumentException.class) public void testErrorOverflow() { GoTimeUtil.durationSeconds(Integer.MAX_VALUE + "0s"); }
@Test(expected = IllegalArgumentException.class) public void testErrorNoUnit() { GoTimeUtil.durationSeconds("145"); }
@Test(expected = IllegalArgumentException.class) public void testErrorUnknownUnit() { GoTimeUtil.durationSeconds("1w"); }
@Test(expected = IllegalArgumentException.class) public void testErrorUnparsable() { GoTimeUtil.durationSeconds("ms"); }
@Test public void testConversion() { assertEquals(new Integer(23), durationSeconds("23s")); assertEquals(new Integer(0), durationSeconds("0.5s")); assertEquals(new Integer(0), durationSeconds("3ms")); assertEquals(new Integer(0), durationSeconds("3ns")); assertEquals(new Integer(1), durationSeconds("1002ms")); assertEquals(new Integer(123), durationSeconds("2m3s")); assertEquals(new Integer(3663), durationSeconds("1h1m3s")); assertEquals(new Integer(1810), durationSeconds("0.5h0.1m4s")); assertEquals(new Integer(-15), durationSeconds("-15s")); assertEquals(new Integer(30), durationSeconds("2h-119.5m")); }
@Test public void testEmpty() { assertNull(durationSeconds(null)); assertNull(durationSeconds("")); assertNull(durationSeconds(" ")); }
@Test(expected = IllegalArgumentException.class) public void testErrorOverflow() { durationSeconds(Integer.MAX_VALUE + "0s"); }
@Test(expected = IllegalArgumentException.class) public void testErrorNoUnit() { durationSeconds("145"); }
@Test(expected = IllegalArgumentException.class) public void testErrorUnknownUnit() { durationSeconds("1w"); }
@Test(expected = IllegalArgumentException.class) public void testErrorUnparsable() { durationSeconds("ms"); }