ScheduleCalculatorFactory { public static Schedule getScheduleCalculator(final String name) { final Schedule schedule = s_instances.get(name); if (schedule == null) { throw new IllegalArgumentException("Could not get schedule calculator with name " + name); } return schedule; }  static Schedule getScheduleCalculator(final String name); static Schedule getScheduleCalculator(final String name, final DayOfWeek dayOfWeek); static Schedule getScheduleCalculator(final String name, final int dayOfMonth, final Month monthOfYear); static final String DAILY; static final String WEEKLY; static final String WEEKLY_ON_DAY; static final String MONTHLY; static final String FIRST_OF_MONTH; static final String END_OF_MONTH; static final String MONTHLY_ON_DAY; static final String QUARTERLY; static final String QUARTERLY_EOM; static final String SEMI_ANNUAL; static final String SEMI_ANNUAL_EOM; static final String ANNUAL; static final String FIRST_OF_YEAR; static final String END_OF_YEAR; static final String ANNUAL_ON_DAY_AND_MONTH; static final String ANNUAL_EOM; static final DailyScheduleCalculator DAILY_CALCULATOR; static final WeeklyScheduleCalculator WEEKLY_CALCULATOR; static final MonthlyScheduleCalculator MONTHLY_CALCULATOR; static final FirstOfMonthScheduleCalculator FIRST_OF_MONTH_CALCULATOR; static final EndOfMonthScheduleCalculator END_OF_MONTH_CALCULATOR; static final QuarterlyScheduleCalculator QUARTERLY_CALCULATOR; static final EndOfMonthQuarterlyScheduleCalculator QUARTERLY_EOM_CALCULATOR; static final SemiAnnualScheduleCalculator SEMI_ANNUAL_CALCULATOR; static final EndOfMonthSemiAnnualScheduleCalculator SEMI_ANNUAL_EOM_CALCULATOR; static final AnnualScheduleCalculator ANNUAL_CALCULATOR; static final FirstOfYearScheduleCalculator FIRST_OF_YEAR_CALCULATOR; static final EndOfYearScheduleCalculator END_OF_YEAR_CALCULATOR; static final EndOfMonthAnnualScheduleCalculator ANNUAL_EOM_CALCULATOR; }
@Test(expectedExceptions = IllegalArgumentException.class) public void testBadName1() { ScheduleCalculatorFactory.getScheduleCalculator("A"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullName1() { ScheduleCalculatorFactory.getScheduleCalculator(null, DayOfWeek.WEDNESDAY); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testBadName2() { ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.DAILY, DayOfWeek.WEDNESDAY); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullName2() { ScheduleCalculatorFactory.getScheduleCalculator(null, 31, Month.DECEMBER); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testBadName3() { ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.DAILY, 23, Month.APRIL); }
@Test public void test() { assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.DAILY), ScheduleCalculatorFactory.DAILY_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.WEEKLY), ScheduleCalculatorFactory.WEEKLY_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.MONTHLY), ScheduleCalculatorFactory.MONTHLY_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.FIRST_OF_MONTH), ScheduleCalculatorFactory.FIRST_OF_MONTH_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.END_OF_MONTH), ScheduleCalculatorFactory.END_OF_MONTH_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.QUARTERLY), ScheduleCalculatorFactory.QUARTERLY_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.QUARTERLY_EOM), ScheduleCalculatorFactory.QUARTERLY_EOM_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.SEMI_ANNUAL), ScheduleCalculatorFactory.SEMI_ANNUAL_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.SEMI_ANNUAL_EOM), ScheduleCalculatorFactory.SEMI_ANNUAL_EOM_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.ANNUAL), ScheduleCalculatorFactory.ANNUAL_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.FIRST_OF_YEAR), ScheduleCalculatorFactory.FIRST_OF_YEAR_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.END_OF_YEAR), ScheduleCalculatorFactory.END_OF_YEAR_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.ANNUAL_EOM), ScheduleCalculatorFactory.ANNUAL_EOM_CALCULATOR); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.WEEKLY_ON_DAY, DayOfWeek.MONDAY), new WeeklyScheduleOnDayCalculator(DayOfWeek.MONDAY)); assertEquals(ScheduleCalculatorFactory.getScheduleCalculator(ScheduleCalculatorFactory.ANNUAL_ON_DAY_AND_MONTH, 11, Month.APRIL), new AnnualScheduleOnDayAndMonthCalculator(11, Month.APRIL)); }