@Test public void shouldRaiseInvalidReferenceDataProductFormError() throws Exception { ProductForm form = new ProductForm("invalid product form code", 1); when(repository.getByCode("invalid product form code")).thenReturn(null); expectedEx.expect(dataExceptionMatcher("error.reference.data.invalid.product.form")); service.validateAndReturn(form); }
public ProductForm validateAndReturn(ProductForm form) { if (form == null) return null; String productFormCode = form.getCode(); if (productFormCode == null || productFormCode.isEmpty()) return null; form = repository.getByCode(productFormCode); if (form == null) throw new DataException("error.reference.data.invalid.product.form"); return form; }
ProductFormService { public ProductForm validateAndReturn(ProductForm form) { if (form == null) return null; String productFormCode = form.getCode(); if (productFormCode == null || productFormCode.isEmpty()) return null; form = repository.getByCode(productFormCode); if (form == null) throw new DataException("error.reference.data.invalid.product.form"); return form; } }
ProductFormService { public ProductForm validateAndReturn(ProductForm form) { if (form == null) return null; String productFormCode = form.getCode(); if (productFormCode == null || productFormCode.isEmpty()) return null; form = repository.getByCode(productFormCode); if (form == null) throw new DataException("error.reference.data.invalid.product.form"); return form; } @Autowired  ProductFormService(ProductFormRepository productFormRepository); }
ProductFormService { public ProductForm validateAndReturn(ProductForm form) { if (form == null) return null; String productFormCode = form.getCode(); if (productFormCode == null || productFormCode.isEmpty()) return null; form = repository.getByCode(productFormCode); if (form == null) throw new DataException("error.reference.data.invalid.product.form"); return form; } @Autowired  ProductFormService(ProductFormRepository productFormRepository); List<ProductForm> getAll(); ProductForm getExisting(ProductForm pf); ProductForm validateAndReturn(ProductForm form); void save(ProductForm pf); }
ProductFormService { public ProductForm validateAndReturn(ProductForm form) { if (form == null) return null; String productFormCode = form.getCode(); if (productFormCode == null || productFormCode.isEmpty()) return null; form = repository.getByCode(productFormCode); if (form == null) throw new DataException("error.reference.data.invalid.product.form"); return form; } @Autowired  ProductFormService(ProductFormRepository productFormRepository); List<ProductForm> getAll(); ProductForm getExisting(ProductForm pf); ProductForm validateAndReturn(ProductForm form); void save(ProductForm pf);  }