@Test public void shouldInsertOnSave() { GeographicLevel geoLevel = new GeographicLevel(); geoLevel.setCode("abc"); repo.save(geoLevel); verify(mapper).insert(geoLevel); }
public void save(GeographicLevel geographicLevel) { try { if(geographicLevel.hasId()) mapper.update(geographicLevel); else mapper.insert(geographicLevel); } catch(DuplicateKeyException dke) { throw new DataException("error.duplicate.geographic.level.code"); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length"); } }
GeographicLevelRepository { public void save(GeographicLevel geographicLevel) { try { if(geographicLevel.hasId()) mapper.update(geographicLevel); else mapper.insert(geographicLevel); } catch(DuplicateKeyException dke) { throw new DataException("error.duplicate.geographic.level.code"); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length"); } } }
GeographicLevelRepository { public void save(GeographicLevel geographicLevel) { try { if(geographicLevel.hasId()) mapper.update(geographicLevel); else mapper.insert(geographicLevel); } catch(DuplicateKeyException dke) { throw new DataException("error.duplicate.geographic.level.code"); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length"); } } @Autowired  GeographicLevelRepository(GeographicLevelMapper mapper); }
GeographicLevelRepository { public void save(GeographicLevel geographicLevel) { try { if(geographicLevel.hasId()) mapper.update(geographicLevel); else mapper.insert(geographicLevel); } catch(DuplicateKeyException dke) { throw new DataException("error.duplicate.geographic.level.code"); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length"); } } @Autowired  GeographicLevelRepository(GeographicLevelMapper mapper); int getLowestGeographicLevel(); GeographicLevel getGeographicLevelByCode(String code); List<GeographicLevel> getAll(); GeographicLevel getByCode(String code); void save(GeographicLevel geographicLevel); GeographicLevel getGeographicLevel(int geographicLevelID); }
GeographicLevelRepository { public void save(GeographicLevel geographicLevel) { try { if(geographicLevel.hasId()) mapper.update(geographicLevel); else mapper.insert(geographicLevel); } catch(DuplicateKeyException dke) { throw new DataException("error.duplicate.geographic.level.code"); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length"); } } @Autowired  GeographicLevelRepository(GeographicLevelMapper mapper); int getLowestGeographicLevel(); GeographicLevel getGeographicLevelByCode(String code); List<GeographicLevel> getAll(); GeographicLevel getByCode(String code); void save(GeographicLevel geographicLevel); GeographicLevel getGeographicLevel(int geographicLevelID);  }