TimeIntervalParser { public static long[] parse(String paramText) { if ( paramText == null || paramText.trim().length() == 0 ) { return new long[0]; } String[] params = paramText.split( "," ); long[] result = new long[params.length]; for ( int i = 0; i < params.length; i++ ) { result[i] = parseSingle( params[i] ); } return result; } private  TimeIntervalParser(); static long[] parse(String paramText); static long parseSingle(String param);  }
@Test public void testParse() { String input = "2d10h49m10s789ms"; long expected = 211750789; long[] result = TimeIntervalParser.parse( input ); assertEquals( 1, result.length ); assertEquals( expected, result[0] ); }
@Test public void testParse2() { String input = "10h49m789ms"; long expected = 10 * 3600000 + 49 * 60000 + 789; long[] result = TimeIntervalParser.parse( input ); assertEquals( 1, result.length ); assertEquals( expected, result[0] ); }
@Test public void testParse3() { String input = " 10h49m789 , 12h "; long expected1 = 10 * 3600000 + 49 * 60000 + 789; long expected2 = 12 * 3600000; long[] result = TimeIntervalParser.parse( input ); assertEquals( 2, result.length ); assertEquals( expected1, result[0] ); assertEquals( expected2, result[1] ); }
@Test public void testParse4() { String input = " 15957, 3500000 "; long expected1 = 15957; long expected2 = 3500000; long[] result = TimeIntervalParser.parse( input ); assertEquals( 2, result.length ); assertEquals( expected1, result[0] ); assertEquals( expected2, result[1] ); }
@Test public void testParse5() { String input = ""; long[] result = TimeIntervalParser.parse( input ); assertEquals( 0, result.length ); }
@Test public void testParse6() { String input = null; long[] result = TimeIntervalParser.parse( input ); assertEquals( 0, result.length ); }
@Test public void testParse7() { String input = " "; long[] result = TimeIntervalParser.parse( input ); assertEquals( 0, result.length ); }
@Test public void testParse8() { String input = " -15957, 3500000 "; long expected1 = -15957; long expected2 = 3500000; long[] result = TimeIntervalParser.parse( input ); assertEquals( 2, result.length ); assertEquals( expected1, result[0] ); assertEquals( expected2, result[1] ); }
@Test public void testParse9() { String input = " -10h49m789 , -8h "; long expected1 = -( 10 * 3600000 + 49 * 60000 + 789 ); long expected2 = -( 8 * 3600000 ); long[] result = TimeIntervalParser.parse( input ); assertEquals( 2, result.length ); assertEquals( expected1, result[0] ); assertEquals( expected2, result[1] ); }