@Test public void shouldThrowErrorIfDuplicateZoneInsert() throws Exception { expectedEx.expect(dataExceptionMatcher("error.duplicate.geographic.zone.code")); doThrow(new DuplicateKeyException("duplicate key")).when(mapper).insert(geographicZone); repository.save(geographicZone); }
public void save(GeographicZone zone) { try { if (zone.getId() == null) { mapper.insert(zone); return; } mapper.update(zone); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.geographic.zone.code"); } catch (DataIntegrityViolationException e) { throw new DataException("error.incorrect.length"); } }
GeographicZoneRepository { public void save(GeographicZone zone) { try { if (zone.getId() == null) { mapper.insert(zone); return; } mapper.update(zone); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.geographic.zone.code"); } catch (DataIntegrityViolationException e) { throw new DataException("error.incorrect.length"); } } }
GeographicZoneRepository { public void save(GeographicZone zone) { try { if (zone.getId() == null) { mapper.insert(zone); return; } mapper.update(zone); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.geographic.zone.code"); } catch (DataIntegrityViolationException e) { throw new DataException("error.incorrect.length"); } } @Autowired  GeographicZoneRepository(GeographicZoneMapper mapper, GeographicLevelRepository geographicLevelRepository); }
GeographicZoneRepository { public void save(GeographicZone zone) { try { if (zone.getId() == null) { mapper.insert(zone); return; } mapper.update(zone); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.geographic.zone.code"); } catch (DataIntegrityViolationException e) { throw new DataException("error.incorrect.length"); } } @Autowired  GeographicZoneRepository(GeographicZoneMapper mapper, GeographicLevelRepository geographicLevelRepository); GeographicZone getByCode(String code); Integer getLowestGeographicLevel(); List<GeographicZone> getAllGeographicZones(); void save(GeographicZone zone); GeographicZone getById(Long id); List<GeographicZone> searchByParentName(String searchParam, Pagination pagination); List<GeographicZone> searchByName(String searchParam, Pagination pagination); List<GeographicLevel> getAllGeographicLevels(); List<GeographicZone> getAllGeographicZonesAbove(GeographicLevel geographicLevel); Integer getTotalParentSearchResultCount(String param); Integer getTotalSearchResultCount(String param); List<GeographicZone> getGeographicZonesByCodeOrName(String searchParam); Integer getGeographicZonesCountBy(String searchParam); }
GeographicZoneRepository { public void save(GeographicZone zone) { try { if (zone.getId() == null) { mapper.insert(zone); return; } mapper.update(zone); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.geographic.zone.code"); } catch (DataIntegrityViolationException e) { throw new DataException("error.incorrect.length"); } } @Autowired  GeographicZoneRepository(GeographicZoneMapper mapper, GeographicLevelRepository geographicLevelRepository); GeographicZone getByCode(String code); Integer getLowestGeographicLevel(); List<GeographicZone> getAllGeographicZones(); void save(GeographicZone zone); GeographicZone getById(Long id); List<GeographicZone> searchByParentName(String searchParam, Pagination pagination); List<GeographicZone> searchByName(String searchParam, Pagination pagination); List<GeographicLevel> getAllGeographicLevels(); List<GeographicZone> getAllGeographicZonesAbove(GeographicLevel geographicLevel); Integer getTotalParentSearchResultCount(String param); Integer getTotalSearchResultCount(String param); List<GeographicZone> getGeographicZonesByCodeOrName(String searchParam); Integer getGeographicZonesCountBy(String searchParam);  }