Last active
August 29, 2015 13:56
-
-
Save DominikMostek/8839369 to your computer and use it in GitHub Desktop.
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
@RunWith(Theories.class) | |
class EmailValidatorTest extends AbstractTestCase { | |
EmailValidator validator | |
@Before | |
void setUp() { | |
validator = new EmailValidator() | |
def msgService = EasyMock.createMock(MessageService) | |
expect(msgService.getMessage("validator.error.email")).andReturn("error message") | |
replay(msgService) | |
validator.messageService = msgService | |
} | |
@Theory | |
void testValidEmailAddresses(@ParametersSuppliedBy(ValidEmailSupplier) String email) { | |
try { | |
validator.validate(null, null, email) // Should not throw any exception | |
} catch (ValidatorException e) { | |
fail(email + " is valid email address but validation failed") | |
} | |
} | |
@Theory | |
void testInvalidEmailAddress(@ParametersSuppliedBy(InvalidEmailSupplier) String email) { | |
try { | |
validator.validate(null, null, email) // Should throw exception | |
fail(email + " is invalid email address but validation passed") | |
} catch (ValidatorException e) { | |
// NO CODE | |
} | |
} | |
} |
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
public class InvalidEmailSupplier extends ParameterSupplier { | |
@Override | |
public List<PotentialAssignment> getValueSources(ParameterSignature sig) { | |
['plainaddress', | |
'#@%^%#$@#$@#.com', | |
'あいうえお@example.com', | |
'@example.com', | |
'email.example.com', | |
'email@example@example.com', | |
'.email@example.com', | |
'email.@example.com', | |
'email@example.com (Joe Smith)', | |
'email@example', | |
'email@-example.com', | |
'email@example..com', | |
'Abc..123@example.com'].collect { PotentialAssignment.forValue(it, it) } | |
} | |
} |
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
public class ValidEmailSupplier extends ParameterSupplier { | |
@Override | |
List<PotentialAssignment> getValueSources(ParameterSignature sig) { | |
[ 'email@example.com', | |
'firstname.lastname@example.com', | |
'email@subdomain.example.com', | |
'firstname+lastname@example.com', | |
'email@123.123.123.123', | |
'1234567890@example.com', | |
'email@example-one.com', | |
'_______@example.com', | |
'email@example.name', | |
'email@example.museum', | |
'email@example.co.jp', | |
'Andoitz.Brit@DHL.COM', | |
'firstname-lastname@example.com'].collect { PotentialAssignment.forValue(it, it) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment