IncidentRegisterPresenter extends RecordRegisterPresenter { @Override protected List<Field> getFields() { List<Field> fields = new ArrayList<>(); RecordForm form = incidentFormService.getGBVTemplate(); List<Section> sections = form.getSections(); for (Section section : sections) { for (Field field : section.getFields()) { field.setSectionName(section.getName()); if (field.isShowOnMiniForm()) { if (field.isPhotoUploadBox()) { fields.add(0, field); } else { fields.add(field); } } } } return fields; } @Inject  IncidentRegisterPresenter(IncidentService incidentService, IncidentFormService
            incidentFormService); @Override void saveRecord(ItemValuesMap itemValuesMap, List<String> photoPaths,
                           RecordRegisterView.SaveRecordCallback callback); @Override List<Field> getFields(int position); @Override RecordForm getTemplateForm();  }
@Test public void should_return_get_fields_from_incident_form_sections() { Field miniFormField = mock(Field.class); Field otherFormField = mock(Field.class); Section section = mock(Section.class); IncidentTemplateForm incidentTemplateForm = mock(IncidentTemplateForm.class); List<Field> fields = Arrays.asList(new Field[]{miniFormField, otherFormField}); List<Section> sections = Arrays.asList(new Section[]{section}); when(miniFormField.isShowOnMiniForm()).thenReturn(true); when(miniFormField.isPhotoUploadBox()).thenReturn(false); when(otherFormField.isShowOnMiniForm()).thenReturn(false); when(section.getFields()).thenReturn(fields); when(incidentTemplateForm.getSections()).thenReturn(sections); when(incidentFormService.getGBVTemplate()).thenReturn(incidentTemplateForm); List<Field> actual = incidentRegisterPresenter.getFields(); assertThat("Should contain mini form field", actual.contains(miniFormField), is(true)); assertThat("Should not contain full form field", actual.contains(otherFormField), is (false)); verify(incidentFormService, times(1)).getGBVTemplate(); }
@Test public void should_return_get_fields_when_position_is_known_and_form_is_not_null(){ IncidentTemplateForm form = new IncidentTemplateForm(); when(incidentFormService.getGBVTemplate()).thenReturn(form); Section section = new Section(); Field miniFormField = new Field(); Field otherFormField = new Field(); List<Field> fields = Arrays.asList(new Field[]{miniFormField, otherFormField}); List<Section> sections = Arrays.asList(new Section[]{section}); section.setFields(fields); form.setSections(sections); int position = 0; assertThat(incidentRegisterPresenter.getFields(position).contains(miniFormField),is(true)); assertThat(incidentRegisterPresenter.getFields(position).contains(otherFormField),is(true)); }
@Test public void should_return_null_when_position_is_known_and_form_is_null(){ when(incidentFormService.getGBVTemplate()).thenReturn(null); List<Field> fieldList = incidentRegisterPresenter.getFields(0); assertEquals(fieldList,null); }