Skip to content

Instantly share code, notes, and snippets.

@holograph
Created December 11, 2013 15:33
Show Gist options
  • Save holograph/7912483 to your computer and use it in GitHub Desktop.
Save holograph/7912483 to your computer and use it in GitHub Desktop.
A sample Accord validator execution (https://github.com/wix/accord).
scala> val validPerson = Person( "Wernher", "von Braun" )
validPerson: Person = Person(Wernher,von Braun)
scala> validate( validPerson )
res0: com.wix.accord.Result = Success
scala> val invalidPerson = Person( "", "No First Name" )
invalidPerson: Person = Person(,No First Name)
scala> validate( invalidPerson )
res1: com.wix.accord.Result = Failure(List(RuleViolation(,must not be empty,firstName)))
scala> val explicitDescription = Person( "No Last Name", "" )
explicitDescription: Person = Person(No Last Name,)
scala> validate( explicitDescription )
res2: com.wix.accord.Result = Failure(List(RuleViolation(,must not be empty,last name)))
scala> val invalidClassroom = Classroom( Person( "Alfred", "Aho" ), Seq.empty )
invalidClassroom: Classroom = Classroom(Person(Alfred,Aho),List())
scala> validate( invalidClassroom )
res3: com.wix.accord.Result = Failure(List(RuleViolation(List(),has size 0, expected more than 0,students)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment