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