PatientDataService { public Optional<MalariaProgram> save(MalariaProgram malariaProgram) throws LMISException { return malariaProgramRepository.save(malariaProgram); }  List<Period> calculatePeriods(VIAReportType VIAReportType); List<StockCard> getMalariaProductsStockCards(); List<Long> getMalariaProductsStockHand(); Optional<MalariaProgram> save(MalariaProgram malariaProgram); MalariaProgram findForPeriod(DateTime beginDate, DateTime endDate); List<Product> getMalariaProducts();  }
@Test public void shouldSavePatientDataReportSuccessfully() throws LMISException { when(malariaProgramRepository.save(malariaProgram)).thenReturn(Optional.of(malariaProgram)); Optional<MalariaProgram> savedMalariaProgram = patientDataService.save(malariaProgram); assertThat(savedMalariaProgram.get(), is(malariaProgram)); }
@Test(expected = LMISException.class) public void shouldReturnFalseWhenSavingMalariaProgramWasFaulty() throws LMISException { doThrow(LMISException.class).when(malariaProgramRepository).save(malariaProgram); patientDataService.save(malariaProgram); }