Skip to content

Commit

Permalink
Add integrity checker for emails
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-openai committed Aug 26, 2024
1 parent 450d8b1 commit 409889a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public enum IntegrityCheckerType {
BACKQUOTE,
EMPTY_TARGET_NOT_EMPTY_SOURCE,
MARKDOWN_LINKS,
PYTHON_FPRINT;
PYTHON_FPRINT,
EMAIL;
}
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.");
}
}
}
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);
}
}
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);
}

}

0 comments on commit 409889a

Please sign in to comment.