Created
February 7, 2014 14:12
-
-
Save musketyr/8863308 to your computer and use it in GitHub Desktop.
Rewritten parametrized JUnit test to Spock
This file contains 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
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