@Test public void shouldGiveDuplicateRecordErrorIfDuplicateRGCodeAndProgramCodeFound() throws Exception { doThrow(new DuplicateKeyException("")).when(requisitionGroupProgramScheduleMapper).insert(requisitionGroupProgramSchedule); Program program = new Program(); program.setPush(false); Long programId = 1L; when(programRepository.getIdByCode(requisitionGroupProgramSchedule.getProgram().getCode())).thenReturn(programId); when(programRepository.getById(programId)).thenReturn(program); requisitionGroupProgramSchedule.setDirectDelivery(true); expectedEx.expect(dataExceptionMatcher("error.duplicate.requisition.group.program.combination")); repository.insert(requisitionGroupProgramSchedule); }
public void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule) { populateIdsForRequisitionProgramScheduleEntities(requisitionGroupProgramSchedule); validateRequisitionGroupSchedule(requisitionGroupProgramSchedule); validateProgramType(requisitionGroupProgramSchedule); try { mapper.insert(requisitionGroupProgramSchedule); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.requisition.group.program.combination"); } }
RequisitionGroupProgramScheduleRepository { public void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule) { populateIdsForRequisitionProgramScheduleEntities(requisitionGroupProgramSchedule); validateRequisitionGroupSchedule(requisitionGroupProgramSchedule); validateProgramType(requisitionGroupProgramSchedule); try { mapper.insert(requisitionGroupProgramSchedule); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.requisition.group.program.combination"); } } }
RequisitionGroupProgramScheduleRepository { public void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule) { populateIdsForRequisitionProgramScheduleEntities(requisitionGroupProgramSchedule); validateRequisitionGroupSchedule(requisitionGroupProgramSchedule); validateProgramType(requisitionGroupProgramSchedule); try { mapper.insert(requisitionGroupProgramSchedule); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.requisition.group.program.combination"); } } @Autowired  RequisitionGroupProgramScheduleRepository(
    RequisitionGroupProgramScheduleMapper requisitionGroupProgramScheduleMapper,
    RequisitionGroupMapper requisitionGroupMapper,
    ProgramRepository programRepository,
    ProcessingScheduleMapper processingScheduleMapper,
    FacilityMapper facilityMapper); }
RequisitionGroupProgramScheduleRepository { public void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule) { populateIdsForRequisitionProgramScheduleEntities(requisitionGroupProgramSchedule); validateRequisitionGroupSchedule(requisitionGroupProgramSchedule); validateProgramType(requisitionGroupProgramSchedule); try { mapper.insert(requisitionGroupProgramSchedule); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.requisition.group.program.combination"); } } @Autowired  RequisitionGroupProgramScheduleRepository(
    RequisitionGroupProgramScheduleMapper requisitionGroupProgramScheduleMapper,
    RequisitionGroupMapper requisitionGroupMapper,
    ProgramRepository programRepository,
    ProcessingScheduleMapper processingScheduleMapper,
    FacilityMapper facilityMapper); void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule); void update(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule); RequisitionGroupProgramSchedule getScheduleForRequisitionGroupAndProgram(Long requisitionGroupId, Long programId); List<Long> getProgramIDsForRequisitionGroup(Long requisitionGroupId); RequisitionGroupProgramSchedule getScheduleForRequisitionGroupCodeAndProgramCode(String requisitionGroupCode, String programCode); List<RequisitionGroupProgramSchedule> getByRequisitionGroupId(Long requisitionGroupId); void deleteRequisitionGroupProgramSchedulesFor(Long requisitionGroupId); }
RequisitionGroupProgramScheduleRepository { public void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule) { populateIdsForRequisitionProgramScheduleEntities(requisitionGroupProgramSchedule); validateRequisitionGroupSchedule(requisitionGroupProgramSchedule); validateProgramType(requisitionGroupProgramSchedule); try { mapper.insert(requisitionGroupProgramSchedule); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.requisition.group.program.combination"); } } @Autowired  RequisitionGroupProgramScheduleRepository(
    RequisitionGroupProgramScheduleMapper requisitionGroupProgramScheduleMapper,
    RequisitionGroupMapper requisitionGroupMapper,
    ProgramRepository programRepository,
    ProcessingScheduleMapper processingScheduleMapper,
    FacilityMapper facilityMapper); void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule); void update(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule); RequisitionGroupProgramSchedule getScheduleForRequisitionGroupAndProgram(Long requisitionGroupId, Long programId); List<Long> getProgramIDsForRequisitionGroup(Long requisitionGroupId); RequisitionGroupProgramSchedule getScheduleForRequisitionGroupCodeAndProgramCode(String requisitionGroupCode, String programCode); List<RequisitionGroupProgramSchedule> getByRequisitionGroupId(Long requisitionGroupId); void deleteRequisitionGroupProgramSchedulesFor(Long requisitionGroupId);  }