Increase PetValidator coverage 75.6% to 100%

This commit is contained in:
oguzcagiran 2017-03-25 15:29:03 +03:00
parent fd1c742d4f
commit 7e7770376b

View file

@ -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());
}
}