@Test public void shouldThrowExceptionIfInsertingInvalidObject() { DosageUnit badDu = new DosageUnit(); badDu.setCode("blah"); expectedException.expect(DataException.class); expectedException.expectMessage("error.reference.data.missing"); duRep.insert(badDu); }
public void insert(DosageUnit du) { du.isValid(); if(getByCode(du.getCode()) != null) throw new DataException("error.duplicate.dosage.unit.code"); try { duMapper.insert(du); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } }
DosageUnitRepository { public void insert(DosageUnit du) { du.isValid(); if(getByCode(du.getCode()) != null) throw new DataException("error.duplicate.dosage.unit.code"); try { duMapper.insert(du); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } } }
DosageUnitRepository { public void insert(DosageUnit du) { du.isValid(); if(getByCode(du.getCode()) != null) throw new DataException("error.duplicate.dosage.unit.code"); try { duMapper.insert(du); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } } @Autowired  DosageUnitRepository(DosageUnitMapper dosageUnitMapper); }
DosageUnitRepository { public void insert(DosageUnit du) { du.isValid(); if(getByCode(du.getCode()) != null) throw new DataException("error.duplicate.dosage.unit.code"); try { duMapper.insert(du); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } } @Autowired  DosageUnitRepository(DosageUnitMapper dosageUnitMapper); DosageUnit getByCode(String code); DosageUnit getExisting(DosageUnit du); void insert(DosageUnit du); void update(DosageUnit du); }
DosageUnitRepository { public void insert(DosageUnit du) { du.isValid(); if(getByCode(du.getCode()) != null) throw new DataException("error.duplicate.dosage.unit.code"); try { duMapper.insert(du); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } } @Autowired  DosageUnitRepository(DosageUnitMapper dosageUnitMapper); DosageUnit getByCode(String code); DosageUnit getExisting(DosageUnit du); void insert(DosageUnit du); void update(DosageUnit du);  }