PTVProgramRepository { public PTVProgram save(final PTVProgram ptvProgram) throws LMISException, SQLException { ConnectionSource connectionSource = DbUtil.getConnectionSource(LmisSqliteOpenHelper.getInstance(context)); return TransactionManager.callInTransaction(connectionSource, () -> { genericDao.create(ptvProgram); patientDispensationRepository.save(new ArrayList<>(ptvProgram.getPatientDispensations())); ptvProgramStockInformationRepository.save(new ArrayList<>(ptvProgram.getPtvProgramStocksInformation())); for (PTVProgramStockInformation ptvProgramStockInformation : ptvProgram.getPtvProgramStocksInformation()) { serviceDispensationRepository.save(new ArrayList<>(ptvProgramStockInformation.getServiceDispensations())); } return ptvProgram; }); } @Inject  PTVProgramRepository(Context context); PTVProgram save(final PTVProgram ptvProgram); List<PTVProgram> getAll(); PTVProgram getByPeriod(final Period period); PTVProgram getFirstMovement();  }
@Test public void shouldSaveProgramRepository() throws LMISException, SQLException { PTVProgram expectedPtvProgram = ptvProgram; setPatientDispensationsToPTVProgram(expectedPtvProgram); PTVProgramStockInformation ptvProgramStockInformation = createValidPTVProgramStockInformation(expectedPtvProgram); setHealthFacilityAndPtvProgramStockInformationToServiceDispensation(ptvProgramStockInformation); expectedPtvProgram.setPtvProgramStocksInformation(newArrayList(ptvProgramStockInformation)); expectedPtvProgram.setStatus(ViaReportStatus.MISSING); PTVProgram ptvProgramSaved = ptvProgramRepository.save(expectedPtvProgram); assertThat(ptvProgramSaved, is(expectedPtvProgram)); }