-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
...box/l10n/mojito/service/assetintegritychecker/integritychecker/EmailIntegrityChecker.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.box.l10n.mojito.service.assetintegritychecker.integritychecker; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import java.util.regex.Matcher; | ||
|
||
public class EmailIntegrityChecker extends RegexIntegrityChecker { | ||
|
||
final static String EMAIL_REGEX = "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}"; | ||
|
||
@Override | ||
public String getRegex() { | ||
return EMAIL_REGEX; | ||
} | ||
|
||
@Override | ||
public void check(String content, String target) { | ||
try { | ||
super.check(content, target); | ||
} catch (RegexCheckerException ex) { | ||
throw new EmailIntegrityCheckerException("Emails are changed."); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...mojito/service/assetintegritychecker/integritychecker/EmailIntegrityCheckerException.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.box.l10n.mojito.service.assetintegritychecker.integritychecker; | ||
|
||
public class EmailIntegrityCheckerException extends IntegrityCheckException { | ||
public EmailIntegrityCheckerException(String message) { | ||
super(message); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...l10n/mojito/service/assetintegritychecker/integritychecker/EmailIntegrityCheckerTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.box.l10n.mojito.service.assetintegritychecker.integritychecker; | ||
|
||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
public class EmailIntegrityCheckerTest { | ||
|
||
EmailIntegrityChecker checker = new EmailIntegrityChecker(); | ||
|
||
@Test | ||
public void testNoEmail() { | ||
String source = "There is no email"; | ||
String target = "Il n'y a pas d'email"; | ||
checker.check(source, target); | ||
} | ||
|
||
@Test(expected = EmailIntegrityCheckerException.class) | ||
public void testMissingInTarget() { | ||
String source = "There is an [email protected]"; | ||
String target = "Il n'y a pas d'email"; | ||
checker.check(source, target); | ||
} | ||
|
||
@Test(expected = EmailIntegrityCheckerException.class) | ||
public void testAddedInTarget() { | ||
String source = "There is no email"; | ||
String target = "Il n'y a un email [email protected]"; | ||
checker.check(source, target); | ||
} | ||
|
||
@Ignore // not supported yet | ||
@Test(expected = EmailIntegrityCheckerException.class) | ||
public void testDuplicates() { | ||
String source = "There is an [email protected]"; | ||
String target = "Il n'y a un email [email protected] [email protected]"; | ||
checker.check(source, target); | ||
} | ||
|
||
} |