mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:15:50 +00:00
Increase PetValidator coverage 75.6% to 100%
This commit is contained in:
parent
fd1c742d4f
commit
7e7770376b
1 changed files with 43 additions and 0 deletions
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue