@Test public void shouldThrowDataExceptionIfReportWithSameNameAlreadyExists() throws Exception { Template template = new Template(); doThrow(DataIntegrityViolationException.class).when(templateMapper).insert(template); expectedException.expect(DataException.class); expectedException.expectMessage("unexpected.exception"); templateRepository.insertWithParameters(template); }
public void insertWithParameters(Template template) { try { mapper.insert(template); for(TemplateParameter parameter : template.getParameters()){ parameter.setTemplateId(template.getId()); mapper.insertParameter(parameter); } } catch (DataIntegrityViolationException integrityViolationException) { throw new DataException("unexpected.exception"); } }
TemplateRepository { public void insertWithParameters(Template template) { try { mapper.insert(template); for(TemplateParameter parameter : template.getParameters()){ parameter.setTemplateId(template.getId()); mapper.insertParameter(parameter); } } catch (DataIntegrityViolationException integrityViolationException) { throw new DataException("unexpected.exception"); } } }
TemplateRepository { public void insertWithParameters(Template template) { try { mapper.insert(template); for(TemplateParameter parameter : template.getParameters()){ parameter.setTemplateId(template.getId()); mapper.insertParameter(parameter); } } catch (DataIntegrityViolationException integrityViolationException) { throw new DataException("unexpected.exception"); } }  }
TemplateRepository { public void insertWithParameters(Template template) { try { mapper.insert(template); for(TemplateParameter parameter : template.getParameters()){ parameter.setTemplateId(template.getId()); mapper.insertParameter(parameter); } } catch (DataIntegrityViolationException integrityViolationException) { throw new DataException("unexpected.exception"); } }  void insertWithParameters(Template template); List<Template> getAllTemplatesForUser(Long userId); Template getByName(String name); Template getById(Long id); Template getLWById(Long id); }
TemplateRepository { public void insertWithParameters(Template template) { try { mapper.insert(template); for(TemplateParameter parameter : template.getParameters()){ parameter.setTemplateId(template.getId()); mapper.insertParameter(parameter); } } catch (DataIntegrityViolationException integrityViolationException) { throw new DataException("unexpected.exception"); } }  void insertWithParameters(Template template); List<Template> getAllTemplatesForUser(Long userId); Template getByName(String name); Template getById(Long id); Template getLWById(Long id);  }