1 package org.oddjob.schedules.regression; 2 3 import java.text.DateFormat ; 4 import java.text.ParseException ; 5 import java.text.SimpleDateFormat ; 6 import java.util.Date ; 7 8 import org.oddjob.schedules.Interval; 9 import org.oddjob.schedules.Schedule; 10 import org.oddjob.schedules.ScheduleContext; 11 12 15 public class TestScheduleRun { 16 17 private String testDate; 18 19 private Expected expected; 20 21 public void setDate(String date) { 22 this.testDate = date; 23 } 24 25 public String getDate() { 26 return testDate; 27 } 28 29 public void addExpected(Expected expected) { 30 this.expected = expected; 31 } 32 33 public boolean testSchedule(Schedule schedule) { 34 DateFormat testDateFormat = new SimpleDateFormat ("dd-MMM-yy HH:mm"); 35 Date date = null; 36 try { 37 date = testDateFormat.parse(testDate); 38 } catch (ParseException e) { 39 throw new RuntimeException (e); 40 } 41 42 Interval nextDue = schedule.nextDue( 44 new ScheduleContext(date)); 45 boolean result; 46 if (expected == null) { 47 result = true; 48 } 49 else { 50 result = expected.getExpected().equals(nextDue); 51 } 52 System.out.println("Given [" + testDate 53 + "]: next due " + nextDue + ". " + (result ? "OK" : "WRONG - " + expected)); 54 55 return result; 56 } 57 } 58 | Popular Tags |