### Question:
JobSimpleTriggerMapper extends BaseTriggerMapper { @Override public void mapFormOnEntity(JobForm form, JobFormEntity entity) { Trigger trigger = form.getTrigger(); EndDate endDate = trigger.getEndDate(); JobSimpleTriggerEntity simpleTrigger = new JobSimpleTriggerEntity(); mapCommonTriggerFieldsOnEntity(form, simpleTrigger); IntervalRecurrence recurrence = (IntervalRecurrence) trigger.getRecurrence(); simpleTrigger.setRecurrenceInterval(recurrence.getInterval()); simpleTrigger.setRecurrenceIntervalUnit(recurrence.getUnit().name()); simpleTrigger.setCalendarName(trigger.getCalendarName()); if (endDate == null) { simpleTrigger.setOccurrenceCount(-1); } else if (endDate instanceof RepeatedEndDate) { RepeatedEndDate date = (RepeatedEndDate) endDate; simpleTrigger.setOccurrenceCount(date.getOccurrenceCount()); } else if (endDate instanceof UntilEndDate) { mapEndDate((UntilEndDate) endDate, simpleTrigger); simpleTrigger.setOccurrenceCount(-1); } entity.setSimpleTrigger(simpleTrigger); }  @Override void mapFormOnEntity(JobForm form, JobFormEntity entity); @Override void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity);  }### Answer:
@Test public void should_map_simple_trigger_with_infinite_value_on_entity() throws Exception { IntervalRecurrence recurrence = new IntervalRecurrence.Builder() .withInterval(10) .withUnit(RecurrenceIntervalUnit.DAY) .build(); Trigger trigger = new Trigger.Builder() .withCalendarName("Gregorian") .withRecurrence(recurrence) .build(); JobForm form = formFactory.givenJobFormBuilderWithValues() .withTrigger(trigger) .build(); mapperUnderTest.mapFormOnEntity(form, formEntity); JobSimpleTriggerEntity simpleTrigger = formEntity.getSimpleTrigger(); assertThat(simpleTrigger.getCalendarName(), is("Gregorian")); assertThat(simpleTrigger.getOccurrenceCount(), is(-1)); assertThat(simpleTrigger.getRecurrenceIntervalUnit(), is("DAY")); assertThat(simpleTrigger.getRecurrenceInterval(), is(10)); }
@Test public void should_map_simple_trigger_with_repeated_value_on_entity() throws Exception { IntervalRecurrence recurrence = new IntervalRecurrence.Builder() .withInterval(10) .withUnit(RecurrenceIntervalUnit.DAY) .build(); Trigger trigger = new Trigger.Builder() .withRecurrence(recurrence) .withEndDate(new RepeatedEndDate(100)) .build(); JobForm form = formFactory.givenJobFormBuilderWithValues() .withTrigger(trigger) .build(); mapperUnderTest.mapFormOnEntity(form, formEntity); JobSimpleTriggerEntity simpleTrigger = formEntity.getSimpleTrigger(); assertThat(simpleTrigger.getOccurrenceCount(), is(100)); assertThat(simpleTrigger.getRecurrenceIntervalUnit(), is("DAY")); assertThat(simpleTrigger.getRecurrenceInterval(), is(10)); }
@Test public void should_map_simple_trigger_with_until_date_value_on_entity() throws Exception { IntervalRecurrence recurrence = new IntervalRecurrence.Builder() .withInterval(10) .withUnit(RecurrenceIntervalUnit.DAY) .build(); Trigger trigger = new Trigger.Builder() .withRecurrence(recurrence) .withEndDate(new UntilEndDate(formFactory.provideEndDate())) .build(); JobForm form = formFactory.givenJobFormBuilderWithValues() .withTrigger(trigger) .build(); mapperUnderTest.mapFormOnEntity(form, formEntity); JobSimpleTriggerEntity simpleTrigger = formEntity.getSimpleTrigger(); assertThat(simpleTrigger.getEndDate(), is(formFactory.provideEndDateSrc())); assertThat(simpleTrigger.getOccurrenceCount(), is(-1)); assertThat(simpleTrigger.getRecurrenceIntervalUnit(), is("DAY")); assertThat(simpleTrigger.getRecurrenceInterval(), is(10)); }