Test for the DateParser class.
| 4 | * Test for the DateParser class. |
| 5 | */ |
| 6 | public class DateParserTest { |
| 7 | /** |
| 8 | * Test the ISO8601 date. |
| 9 | * Date grammar: |
| 10 | * Year: |
| 11 | * YYYY (eg 1997) |
| 12 | * Year and month: |
| 13 | * YYYY-MM (eg 1997-07) |
| 14 | * Complete date: |
| 15 | * YYYY-MM-DD (eg 1997-07-16) |
| 16 | * Complete date plus hours and minutes: |
| 17 | * YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00) |
| 18 | * Complete date plus hours, minutes and seconds: |
| 19 | * YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00) |
| 20 | * Complete date plus hours, minutes, seconds and a decimal fraction of a second |
| 21 | * YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00) |
| 22 | * where: |
| 23 | * |
| 24 | * YYYY = four-digit year |
| 25 | * MM = two-digit month (01=January, etc.) |
| 26 | * DD = two-digit day of month (01 through 31) |
| 27 | * hh = two digits of hour (00 through 23) (am/pm NOT allowed) |
| 28 | * mm = two digits of minute (00 through 59) |
| 29 | * ss = two digits of second (00 through 59) |
| 30 | * s = one or more digits representing a decimal fraction of a second |
| 31 | * TZD = time zone designator (Z or +hh:mm or -hh:mm) |
| 32 | * |
| 33 | * @throws Exception |
| 34 | */ |
| 35 | public void testisISO8601Date() throws Exception { |
| 36 | DateParser p = new DateParser(); |
| 37 | p.parse( "2011" ); |
| 38 | p.parse( "2011-02" ); |
| 39 | p.parse( "2011-02-12" ); |
| 40 | p.parse( "2011-03-01T13" ); |
| 41 | p.parse( "2011-02-01T13:00" ); |
| 42 | p.parse( "2011-02-01T13:00:00" ); |
| 43 | p.parse( "2011-02-01T13:00:00Z" ); |
| 44 | p.parse( "2011-02-01T13:00:00+01:00" ); |
| 45 | p.parse( "2011-02-01T13:00:00-03:00" ); |
| 46 | |
| 47 | try { |
| 48 | p.parse( "" ); |
| 49 | throw new Exception("Invalid date passed!"); |
| 50 | } catch (InvalidDateException e) {} |
| 51 | try { |
| 52 | p.parse( "2011-" ); |
| 53 | throw new Exception("Invalid date passed!"); |
| 54 | } catch (InvalidDateException e) {} |
| 55 | try { |
| 56 | p.parse( "2011-02-" ); |
| 57 | throw new Exception("Invalid date passed!"); |
| 58 | } catch (InvalidDateException e) {} |
| 59 | |
| 60 | try { |
| 61 | p.parse( "2011-02-01T" ); |
| 62 | throw new Exception("Invalid date passed!"); |
| 63 | } catch (InvalidDateException e) {} |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…