Created
October 17, 2016 09:27
-
-
Save FranckSilvestre/18434a296668b085885693ed13d65f5c to your computer and use it in GitHub Desktop.
Fichier UtilisateurTest.groovy pour le projet FriendsOfMine : Spock inside !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package friendsofmine | |
| import spock.lang.Specification | |
| import spock.lang.Unroll | |
| import javax.validation.Validation | |
| import javax.validation.Validator | |
| import javax.validation.ValidatorFactory | |
| class UtilisateurTest extends Specification { | |
| Validator validator | |
| void setup() { | |
| ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); | |
| validator = factory.getValidator(); | |
| } | |
| @Unroll | |
| void "test la validite d'un utilisateur valide"(String unNom, String unPrenom, String unEmail, String unSexe, Date uneDateNaissance) { | |
| given: "un utilisateur initialise correctement" | |
| Utilisateur utilisateur = new Utilisateur(nom: unNom, prenom: unPrenom, email: unEmail, sexe: unSexe, dateNaissance: uneDateNaissance) | |
| expect: "l'utilisateur est valide" | |
| validator.validate(utilisateur).empty | |
| where: | |
| unNom | unPrenom | unEmail | unSexe | uneDateNaissance | |
| "Dupont" | "Jeanne" | "[email protected]" | "F" | new Date(1972, 6, 17) | |
| "Durand" | "Jacques" | "[email protected]" | "M" | new Date(1972, 6, 17) | |
| "Durand" | "Jacques" | "[email protected]" | "M" | null | |
| } | |
| @Unroll | |
| void "test l'invalidite d'un utilisateur non valide"(String unNom, String unPrenom, String unEmail, String unSexe) { | |
| given: "un utilisateur initialise de maniere non valide" | |
| Utilisateur utilisateur = new Utilisateur(nom: unNom, prenom: unPrenom, email: unEmail, sexe: unSexe) | |
| expect: "l'utilisateur est invalide" | |
| !validator.validate(utilisateur).empty | |
| where: | |
| unNom | unPrenom | unEmail | unSexe | |
| null | "Jeanne" | "[email protected]" | "F" | |
| '' | "Jeanne" | "[email protected]" | "F" | |
| "Dupont" | null | "[email protected]" | "F" | |
| "Durand" | "" | "[email protected]" | "M" | |
| "Durand" | "Jacques" | "jdjd.com" | "M" | |
| "Durand" | "Jacques" | null | "M" | |
| "Durand" | "Jacques" | "[email protected]" | "Z" | |
| "Durand" | "Jacques" | "[email protected]" | null | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment