From 7e7770376bdf192b610d1ad5f23510a521d01edd Mon Sep 17 00:00:00 2001 From: oguzcagiran Date: Sat, 25 Mar 2017 15:29:03 +0300 Subject: [PATCH] Increase PetValidator coverage 75.6% to 100% --- .../petclinic/model/PetValidatorTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/test/java/org/springframework/samples/petclinic/model/PetValidatorTest.java diff --git a/src/test/java/org/springframework/samples/petclinic/model/PetValidatorTest.java b/src/test/java/org/springframework/samples/petclinic/model/PetValidatorTest.java new file mode 100644 index 000000000..e85c6fbea --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/model/PetValidatorTest.java @@ -0,0 +1,43 @@ +package org.springframework.samples.petclinic.model; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.samples.petclinic.owner.Pet; +import org.springframework.samples.petclinic.owner.PetValidator; +import org.springframework.validation.BeanPropertyBindingResult; +import org.springframework.validation.Errors; +import org.springframework.validation.Validator; + +/** + * @author Oğuz Çağıran + */ +public class PetValidatorTest { + + private Validator validator; + + @Before + public void setup() { + validator = new PetValidator(); + } + + @Test + public void shouldNotValidateWhenPetNameEmpty() { + Pet pet = new Pet(); + pet.setName(""); + Errors errors = new BeanPropertyBindingResult(pet, "name"); + validator.validate(pet, errors); + assertTrue(errors.hasErrors()); + } + + @Test + public void shouldNotValideWhenBirthDateEmpty() { + Pet pet = new Pet(); + pet.setName("pet"); + pet.setBirthDate(null); + Errors errors = new BeanPropertyBindingResult(pet, "birthDate"); + validator.validate(pet, errors); + assertTrue(errors.hasErrors()); + } +}