@Test public void shouldValidateAndSetProductForm() throws Exception { ProductForm form1 = new ProductForm("code1", 1); ProductForm form2 = new ProductForm("code1", 2); when(repository.getByCode("code1")).thenReturn(form2); ProductForm response = service.validateAndReturn(form1); assertThat(response, is(form2)); }
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);  }