@Test public void shouldValidateAndReturnNullIfFormCodeEmpty() throws Exception { assertThat(service.validateAndReturn(new ProductForm(null, 1)), is(nullValue())); }
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);  }