Skip to content

Instantly share code, notes, and snippets.

@banterCZ
Last active February 11, 2016 16:14
Show Gist options
  • Save banterCZ/8822692 to your computer and use it in GitHub Desktop.
Save banterCZ/8822692 to your computer and use it in GitHub Desktop.
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import static org.junit.runners.Parameterized.Parameters
import static org.junit.Assert.assertEquals
/**
* @author banterCZ
*/
@RunWith(Parameterized)
class EmailValidatorTest {
@Parameters(name = "{0}")
static data() {
[
["[email protected]", true ],
["puto [email protected]", false],
["platini@avalonbiometrics", false],
["platiniatavalonbiometrics.com", false],
["[email protected]", 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 ]
]*.toArray()
}
String input
boolean expected
def config
EmailValidatorTest(String input, boolean expected) {
this.input = input
this.expected = expected
}
@Before
void setup() {
def properties = new Properties()
properties.load(
getClass().getClassLoader().getResourceAsStream("validation.properties")
)
config = new ConfigSlurper().parse(properties)
}
@Test
void test() {
//^(?=.{1,64}@)[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-\\+]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$
def pattern = ~/${config.Validator.Email}/
def result = pattern.matcher(input).matches()
assertEquals(expected, result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment