ReportDefinition { public List<ReportIndicator> getIndicatorsByFormName(String formName) { try { FormIndicator formIndicator = selectUnique(formIndicators, having(on(FormIndicator.class).form(), equalTo(formName))); return formIndicator == null ? new ArrayList<ReportIndicator>() : formIndicator.indicators(); } catch (NotUniqueItemException e) { logger.error("There are more than one form indicator definition for the form: " + formName); throw e; } } ReportDefinition(List<FormIndicator> formIndicators); List<ReportIndicator> getIndicatorsByFormName(String formName); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test(expected = NotUniqueItemException.class) public void shouldThrowNotUniqueExceptionWhenMoreThanOneFormIndicatorDefinitionExistsForAForm() throws Exception { ReportDefinition reportDefinition = new ReportDefinition(asList( new FormIndicator("form 1", Collections.<ReportIndicator>emptyList()), new FormIndicator("form 1", Collections.<ReportIndicator>emptyList()))); reportDefinition.getIndicatorsByFormName("form 1"); }
@Test public void shouldGetFormIndicatorForGivenForm() throws Exception { ReportDefinition reportDefinition = new ReportDefinition( asList( new FormIndicator("form 1", asList(new ReportIndicator("form1Indicator"))), new FormIndicator("form 2", asList(new ReportIndicator("form2Indicator"))))); List<ReportIndicator> indicators = reportDefinition.getIndicatorsByFormName("form 1"); assertEquals(asList(new ReportIndicator("form1Indicator")), indicators); }
@Test public void shouldReturnEmptyFormIndicatorListWhenThereIsNoDefinitionForGivenForm() throws Exception { ReportDefinition reportDefinition = new ReportDefinition( asList(new FormIndicator("form 1", asList(new ReportIndicator("form1Indicator"))))); List<ReportIndicator> indicators = reportDefinition.getIndicatorsByFormName("form without definition"); assertTrue(indicators.isEmpty()); }