Skip to content

Instantly share code, notes, and snippets.

@elnur
Created December 17, 2017 00:57
Show Gist options
  • Save elnur/d4f688a60da31ffe55aa610fd16f6a3e to your computer and use it in GitHub Desktop.
Save elnur/d4f688a60da31ffe55aa610fd16f6a3e to your computer and use it in GitHub Desktop.
public class EmailAddressPartsExtractorTest {
private EmailAddressPartsExtractor extractor = new EmailAddressPartsExtractor();
@Test
public void extractUsername() {
assertThat(extractor.extractUsername("[email protected]"), is("elnur.blog"));
}
@Test
public void extractHost() {
assertThat(extractor.extractHostname("[email protected]"), is("example.com"));
}
@Test(expected = InvalidEmailAddressException.class)
public void failToExtractUsernameFromAddressWithoutAtCharacter() {
extractor.extractUsername("elnur.example.com");
}
@Test(expected = InvalidEmailAddressException.class)
public void failToExtractUsernameFromInvalidAddressWithMoreThanOneAtCharacter() {
extractor.extractUsername("elnur@example@com");
}
@Test(expected = InvalidEmailAddressException.class)
public void failToExtractHostnameFromAddressWithoutAtCharacter() {
extractor.extractHostname("elnur.example.com");
}
@Test(expected = InvalidEmailAddressException.class)
public void failToExtractHostnameFromInvalidAddressWithMoreThanOneAtCharacter() {
extractor.extractHostname("elnur@example@com");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment