@Test public void shouldInsertSupplyLineIfDoesNotExist() throws Exception { when(programRepository.getIdByCode(supplyLine.getProgram().getCode())).thenReturn(1L); when(facilityRepository.getIdForCode(supplyLine.getSupplyingFacility().getCode())).thenReturn(1L); when(supervisoryNodeRepository.getIdForCode(supplyLine.getSupervisoryNode().getCode())).thenReturn(1L); supplyLine.getSupervisoryNode().setId(1L); when(supervisoryNodeRepository.getSupervisoryNodeParentId(1L)).thenReturn(null); supplyLine.setId(null); service.save(supplyLine); verify(repository).insert(supplyLine); }
public void save(SupplyLine supplyLine) { validateIfSupervisoryNodeIsTopmostNode(supplyLine); if (supplyLine.getId() == null) { repository.insert(supplyLine); return; } repository.update(supplyLine); }
SupplyLineService { public void save(SupplyLine supplyLine) { validateIfSupervisoryNodeIsTopmostNode(supplyLine); if (supplyLine.getId() == null) { repository.insert(supplyLine); return; } repository.update(supplyLine); } }
SupplyLineService { public void save(SupplyLine supplyLine) { validateIfSupervisoryNodeIsTopmostNode(supplyLine); if (supplyLine.getId() == null) { repository.insert(supplyLine); return; } repository.update(supplyLine); }  }
SupplyLineService { public void save(SupplyLine supplyLine) { validateIfSupervisoryNodeIsTopmostNode(supplyLine); if (supplyLine.getId() == null) { repository.insert(supplyLine); return; } repository.update(supplyLine); }  SupplyLine getSupplyLineBy(SupervisoryNode supervisoryNode, Program program); void save(SupplyLine supplyLine); SupplyLine getExisting(SupplyLine supplyLine); List<Facility> getSupplyingFacilities(Long userId); SupplyLine getById(Long id); List<SupplyLine> search(String searchParam, String column, Pagination pagination); Integer getTotalSearchResultCount(String searchParam, String column); SupplyLine getByFacilityProgram(Long facilityId, Long programId); }
SupplyLineService { public void save(SupplyLine supplyLine) { validateIfSupervisoryNodeIsTopmostNode(supplyLine); if (supplyLine.getId() == null) { repository.insert(supplyLine); return; } repository.update(supplyLine); }  SupplyLine getSupplyLineBy(SupervisoryNode supervisoryNode, Program program); void save(SupplyLine supplyLine); SupplyLine getExisting(SupplyLine supplyLine); List<Facility> getSupplyingFacilities(Long userId); SupplyLine getById(Long id); List<SupplyLine> search(String searchParam, String column, Pagination pagination); Integer getTotalSearchResultCount(String searchParam, String column); SupplyLine getByFacilityProgram(Long facilityId, Long programId);  }