@Test public void shouldThrowExceptionIfInsertingInValid() { ProductForm pf = new ProductForm(); expectedException.expect(DataException.class); expectedException.expectMessage("error.reference.data.missing"); pfRep.insert(pf); }
public void insert(ProductForm pf) { pf.isValid(); if(getByCode(pf.getCode()) != null) throw new DataException("error.duplicate.dosage.unit.code"); try { pfMapper.insert(pf); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } }
ProductFormRepository { public void insert(ProductForm pf) { pf.isValid(); if(getByCode(pf.getCode()) != null) throw new DataException("error.duplicate.dosage.unit.code"); try { pfMapper.insert(pf); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } } }
ProductFormRepository { public void insert(ProductForm pf) { pf.isValid(); if(getByCode(pf.getCode()) != null) throw new DataException("error.duplicate.dosage.unit.code"); try { pfMapper.insert(pf); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } } ProductFormRepository(ProductFormMapper productFormMapper); }
ProductFormRepository { public void insert(ProductForm pf) { pf.isValid(); if(getByCode(pf.getCode()) != null) throw new DataException("error.duplicate.dosage.unit.code"); try { pfMapper.insert(pf); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } } ProductFormRepository(ProductFormMapper productFormMapper); ProductForm getByCode(String code); void insert(ProductForm pf); List<ProductForm> getAll(); void update(ProductForm pf); }
ProductFormRepository { public void insert(ProductForm pf) { pf.isValid(); if(getByCode(pf.getCode()) != null) throw new DataException("error.duplicate.dosage.unit.code"); try { pfMapper.insert(pf); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } } ProductFormRepository(ProductFormMapper productFormMapper); ProductForm getByCode(String code); void insert(ProductForm pf); List<ProductForm> getAll(); void update(ProductForm pf);  }