Skip to content

Instantly share code, notes, and snippets.

@FranckSilvestre
Created October 18, 2016 13:36
Show Gist options
  • Select an option

  • Save FranckSilvestre/4a0a36d2b750b795f84c06a4b39bc1ed to your computer and use it in GitHub Desktop.

Select an option

Save FranckSilvestre/4a0a36d2b750b795f84c06a4b39bc1ed to your computer and use it in GitHub Desktop.
FriendsOfMine : classe de tests d'intégration pour la classe UtilisateurService
package friendsofmine
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification
import javax.validation.ConstraintViolationException
/**
* Created by franck on 18/10/2016.
*/
@ContextConfiguration
@SpringBootTest
class UtilisateurServiceITest extends Specification {
@Autowired UtilisateurService utilisateurService
def "test save a valid utilisateur"() {
given: "a valid utilisateur"
Utilisateur bob = new Utilisateur(nom: "Deniro", prenom: "bob", email: "[email protected]",sexe: "M")
when: "the utilisateur is saved"
utilisateurService.saveUtilisateur(bob);
then: "the utilisateur has an id"
bob.id != null
}
def "test save a non valid utilisateur"() {
given: "a non valid utilisateur"
Utilisateur bob = new Utilisateur(prenom: "bob", email: "[email protected]",sexe: "M")
when: "the utilisateur is saved"
utilisateurService.saveUtilisateur(bob);
then: "A validation exception is thrown"
thrown ConstraintViolationException
and: "bob has still null id"
bob.id == null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment