1 package org.apache.jcs.auxiliary.disk.jdbc.mysql.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Date;
23
24 import junit.framework.TestCase;
25
26 /***
27 * Unit tests for the schedule parser.
28 * <p>
29 * @author Aaron Smuts
30 */
31 public class ScheduleParserUtilUnitTest
32 extends TestCase
33 {
34
35 /***
36 * Verify that we get an exception and not a null pointer for null input.
37 */
38 public void testGetDatesWithNullInput()
39 {
40 try
41 {
42 ScheduleParser.createDatesForSchedule( null );
43
44 fail( "Should have thrown an exception" );
45 }
46 catch ( ScheduleFormatException e )
47 {
48
49 }
50 }
51
52 /***
53 * Verify that we get an exception and not a null pointer for null input.
54 */
55 public void testGetDateWithNullInput()
56 {
57 try
58 {
59 ScheduleParser.getDateForSchedule( null );
60
61 fail( "Should have thrown an exception" );
62 }
63 catch ( ScheduleFormatException e )
64 {
65
66 }
67 }
68
69 /***
70 * Verify that we get one date for one date.
71 * @throws ScheduleFormatException
72 */
73 public void testGetsDatesSingle()
74 throws ScheduleFormatException
75 {
76 String schedule = "12:34:56";
77 Date[] dates = ScheduleParser.createDatesForSchedule( schedule );
78
79 assertEquals( "Wrong number of dates returned.", 1, dates.length );
80 }
81 /***
82 * Verify that we get one date for one date.
83 * @throws ScheduleFormatException
84 */
85 public void testGetsDatesMultiple()
86 throws ScheduleFormatException
87 {
88 String schedule = "12:34:56,03:51:00,12:34:12";
89 Date[] dates = ScheduleParser.createDatesForSchedule( schedule );
90
91 assertEquals( "Wrong number of dates returned.", 3, dates.length );
92 }
93
94 /***
95 * Verify that we get an exception for a single bad date in a list.
96 */
97 public void testGetDatesMalformedNoColon()
98 {
99 try
100 {
101 String schedule = "12:34:56,03:51:00,123234";
102 ScheduleParser.createDatesForSchedule( schedule );
103
104 fail( "Should have thrown an exception for a malformed date" );
105 }
106 catch ( ScheduleFormatException e )
107 {
108
109 }
110 }
111 /***
112 * Verify that we get an exception for a schedule that has a non numeric item.
113 */
114 public void testGetDatesMalformedNan()
115 {
116 try
117 {
118 String schedule = "12:34:56,03:51:00,aa:12:12";
119 ScheduleParser.createDatesForSchedule( schedule );
120
121 fail( "Should have thrown an exception for a malformed date" );
122 }
123 catch ( ScheduleFormatException e )
124 {
125
126 }
127 }
128 }