KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > impl > calendar > DailyCalendarTest


1 /*
2  * Copyright 2004-2006 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  */

16 package org.quartz.impl.calendar;
17
18 import org.quartz.SerializationTestSupport;
19
20 /**
21  * Unit test for DailyCalendar.
22  */

23 public class DailyCalendarTest extends SerializationTestSupport {
24     private static final String JavaDoc[] VERSIONS = new String JavaDoc[] {"1.5.2"};
25     
26     public void testStringStartEndTimes() {
27         DailyCalendar dailyCalendar = new DailyCalendar("TestCal", "1:20", "14:50");
28         assertTrue(dailyCalendar.toString().indexOf("01:20:00:000 - 14:50:00:000") > 0);
29         
30         dailyCalendar = new DailyCalendar("TestCal", "1:20:1:456", "14:50:15:2");
31         assertTrue(dailyCalendar.toString().indexOf("01:20:01:456 - 14:50:15:002") > 0);
32     }
33     
34     public void testStringInvertTimeRange() {
35         DailyCalendar dailyCalendar = new DailyCalendar("TestCal", "1:20", "14:50");
36         dailyCalendar.setInvertTimeRange(true);
37         assertTrue(dailyCalendar.toString().indexOf("inverted: true") > 0);
38
39         dailyCalendar.setInvertTimeRange(false);
40         assertTrue(dailyCalendar.toString().indexOf("inverted: false") > 0);
41     }
42     
43     /**
44      * Get the object to serialize when generating serialized file for future
45      * tests, and against which to validate deserialized object.
46      */

47     protected Object JavaDoc getTargetObject() {
48         DailyCalendar c = new DailyCalendar("TestCal", "01:20:01:456", "14:50:15:002");
49         c.setDescription("description");
50         c.setInvertTimeRange(true);
51         
52         return c;
53     }
54     
55     /**
56      * Get the Quartz versions for which we should verify
57      * serialization backwards compatibility.
58      */

59     protected String JavaDoc[] getVersions() {
60         return VERSIONS;
61     }
62     
63     /**
64      * Verify that the target object and the object we just deserialized
65      * match.
66      */

67     protected void verifyMatch(Object JavaDoc target, Object JavaDoc deserialized) {
68         DailyCalendar targetCalendar = (DailyCalendar)target;
69         DailyCalendar deserializedCalendar = (DailyCalendar)deserialized;
70         
71         assertNotNull(deserializedCalendar);
72         assertEquals(targetCalendar.getDescription(), deserializedCalendar.getDescription());
73         assertTrue(deserializedCalendar.getInvertTimeRange());
74         assertNull(deserializedCalendar.getTimeZone());
75         assertTrue(deserializedCalendar.toString().indexOf("01:20:01:456 - 14:50:15:002") > 0);
76     }
77 }
78
Popular Tags