@Test public void shouldInsertARegimenIfIdIsSet() { final Regimen regimen = new Regimen(); final Regimen regimen2 = new Regimen(); regimen2.setName("regimen"); regimen.setId(1L); List<Regimen> regimens = new ArrayList<Regimen>() {{ add(regimen); add(regimen2); }}; repository.save(regimens, 1L); assertThat(regimen.getModifiedBy(), is(1L)); verify(mapper).update(regimen); verify(mapper).insert(regimen2); }
public void save(List<Regimen> regimens, Long userId) { for (Regimen regimen : regimens) { regimen.setModifiedBy(userId); if (regimen.getId() == null) { regimen.setCreatedBy(userId); mapper.insert(regimen); } mapper.update(regimen); } }
RegimenRepository { public void save(List<Regimen> regimens, Long userId) { for (Regimen regimen : regimens) { regimen.setModifiedBy(userId); if (regimen.getId() == null) { regimen.setCreatedBy(userId); mapper.insert(regimen); } mapper.update(regimen); } } }
RegimenRepository { public void save(List<Regimen> regimens, Long userId) { for (Regimen regimen : regimens) { regimen.setModifiedBy(userId); if (regimen.getId() == null) { regimen.setCreatedBy(userId); mapper.insert(regimen); } mapper.update(regimen); } }  }
RegimenRepository { public void save(List<Regimen> regimens, Long userId) { for (Regimen regimen : regimens) { regimen.setModifiedBy(userId); if (regimen.getId() == null) { regimen.setCreatedBy(userId); mapper.insert(regimen); } mapper.update(regimen); } }  List<Regimen> getByProgram(Long programId); Regimen getById(Long id); void save(List<Regimen> regimens, Long userId); List<Regimen> getAllRegimens(); List<DosageFrequency> getAllDosageFrequencies(); List<RegimenCombinationConstituent> getAllRegimenCombinationConstituents(); List<RegimenConstituentDosage> getAllRegimenConstituentsDosages(); List<RegimenProductCombination> getAllRegimenProductCombinations(); }
RegimenRepository { public void save(List<Regimen> regimens, Long userId) { for (Regimen regimen : regimens) { regimen.setModifiedBy(userId); if (regimen.getId() == null) { regimen.setCreatedBy(userId); mapper.insert(regimen); } mapper.update(regimen); } }  List<Regimen> getByProgram(Long programId); Regimen getById(Long id); void save(List<Regimen> regimens, Long userId); List<Regimen> getAllRegimens(); List<DosageFrequency> getAllDosageFrequencies(); List<RegimenCombinationConstituent> getAllRegimenCombinationConstituents(); List<RegimenConstituentDosage> getAllRegimenConstituentsDosages(); List<RegimenProductCombination> getAllRegimenProductCombinations();  }