LoanDurationInAccountingYearsCalculatorFactory { public LoanDurationInAccountingYearsCalculator create(RecurrenceType recurrenceType) { switch (recurrenceType) { case MONTHLY: return new LoanDurationInAccountingYearsCalculatorFactoryForMonthlyRecurrence(); case WEEKLY: return new LoanDurationInAccountingYearsCalculatorFactoryForWeeklyRecurrence(); case DAILY: return new LoanDurationInAccountingYearsCalculatorFactoryForDailyRecurrence(); default: throw new BusinessRuleException(AccountConstants.NOT_SUPPORTED_DURATION_TYPE); } }  LoanDurationInAccountingYearsCalculator create(RecurrenceType recurrenceType);  }
@Test public void shouldUseWeeklyCalculator() { LoanDurationInAccountingYearsCalculator loanDurationCalculator = loanDurationCalculatorFactory.create(RecurrenceType.WEEKLY); assertThat(loanDurationCalculator, is(instanceOf(LoanDurationInAccountingYearsCalculatorFactoryForWeeklyRecurrence.class))); }
@Test public void shouldUseMonthlyCalculator() { LoanDurationInAccountingYearsCalculator loanDurationCalculator = loanDurationCalculatorFactory.create(RecurrenceType.MONTHLY); assertThat(loanDurationCalculator, is(instanceOf(LoanDurationInAccountingYearsCalculatorFactoryForMonthlyRecurrence.class))); }
@Test public void shouldUseDailyCalculator() { LoanDurationInAccountingYearsCalculator loanDurationCalculator = loanDurationCalculatorFactory.create(RecurrenceType.DAILY); assertThat(loanDurationCalculator, is(instanceOf(LoanDurationInAccountingYearsCalculatorFactoryForDailyRecurrence.class))); }