1 16 package org.quartz; 17 18 import java.text.ParseException ; 19 import java.util.Calendar ; 20 import java.util.TimeZone ; 21 22 public class CronExpressionTest extends SerializationTestSupport { 23 private static final String [] VERSIONS = new String [] {"1.5.2"}; 24 25 private static final TimeZone EST_TIME_ZONE = TimeZone.getTimeZone("US/Eastern"); 26 27 31 protected Object getTargetObject() throws ParseException { 32 CronExpression cronExpression = new CronExpression("0 15 10 * * ? 2005"); 33 cronExpression.setTimeZone(EST_TIME_ZONE); 34 35 return cronExpression; 36 } 37 38 42 protected String [] getVersions() { 43 return VERSIONS; 44 } 45 46 50 protected void verifyMatch(Object target, Object deserialized) { 51 CronExpression targetCronExpression = (CronExpression)target; 52 CronExpression deserializedCronExpression = (CronExpression)deserialized; 53 54 assertNotNull(deserializedCronExpression); 55 assertEquals(targetCronExpression.getCronExpression(), deserializedCronExpression.getCronExpression()); 56 assertEquals(targetCronExpression.getTimeZone(), deserializedCronExpression.getTimeZone()); 57 } 58 59 62 public void testIsSatisfiedBy() throws Exception { 63 CronExpression cronExpression = new CronExpression("0 15 10 * * ? 2005"); 64 65 Calendar cal = Calendar.getInstance(); 66 67 cal.set(2005, Calendar.JUNE, 1, 10, 15, 0); 68 assertTrue(cronExpression.isSatisfiedBy(cal.getTime())); 69 70 cal.set(Calendar.YEAR, 2006); 71 assertFalse(cronExpression.isSatisfiedBy(cal.getTime())); 72 73 cal = Calendar.getInstance(); 74 cal.set(2005, Calendar.JUNE, 1, 10, 16, 0); 75 assertFalse(cronExpression.isSatisfiedBy(cal.getTime())); 76 77 cal = Calendar.getInstance(); 78 cal.set(2005, Calendar.JUNE, 1, 10, 14, 0); 79 assertFalse(cronExpression.isSatisfiedBy(cal.getTime())); 80 } 81 } 82 | Popular Tags |