Skip to content

Instantly share code, notes, and snippets.

@musketyr
Created February 7, 2014 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save musketyr/8863308 to your computer and use it in GitHub Desktop.
Save musketyr/8863308 to your computer and use it in GitHub Desktop.
Rewritten parametrized JUnit test to Spock
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll
import java.util.regex.Pattern
/**
* @author musketyr
*/
class EmailValidatorSpec extends Specification {
@Shared Pattern pattern
void setup() {
// def properties = new Properties()
// properties.load(
// getClass().getClassLoader().getResourceAsStream("validation.properties")
// )
//
// config = new ConfigSlurper().parse(properties)
// pattern = ~/${config.Validator.Email}/
pattern = ~/^(?=.{1,64}@)[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-\\+]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$/
}
@Unroll def "Regexp for #email will evaluated to #expected"() {
expect:
pattern.matcher(email).matches() == expected
where:
email | expected
"puto.platini@avalonbiometrics.com" | true
"puto platini@avalonbiometrics.com" | false
"platini@avalonbiometrics" | false
"platiniatavalonbiometrics.com" | false
"disposable.style.email.with+symbol@example.com" | true
"platini@avalonbiometrics@com" | false
"local.part.cannot.be.longer.than.sixty-four.characters.email.abcd@ab.com" | false
"total.can.be.longer.than.sixty-four.charecters.email@xxxxxxxxxxxxxx.com" | true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment