-
Notifications
You must be signed in to change notification settings - Fork 3
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
7 changed files
with
66 additions
and
0 deletions.
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
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
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
19 changes: 19 additions & 0 deletions
19
...java/uk/gov/justice/tools/eventsourcing/anonymization/generator/PhoneNumberGenerator.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,19 @@ | ||
package uk.gov.justice.tools.eventsourcing.anonymization.generator; | ||
|
||
|
||
import static java.lang.String.format; | ||
|
||
import com.mifmif.common.regex.Generex; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class PhoneNumberGenerator extends Generator<String> { | ||
|
||
@Override | ||
public String convert(final String fieldValue) { | ||
if (StringUtils.isBlank(fieldValue)) { | ||
return ""; | ||
} | ||
|
||
return new Generex(format("[0-9]{%s}", fieldValue.length())).random(); | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
.../uk/gov/justice/tools/eventsourcing/anonymization/generator/PhoneNumberGeneratorTest.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,30 @@ | ||
package uk.gov.justice.tools.eventsourcing.anonymization.generator; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
import static uk.gov.justice.tools.eventsourcing.anonymization.constants.StringPattern.PHONE_NUMBER_PATTERN; | ||
import static uk.gov.justice.tools.eventsourcing.anonymization.util.MatcherUtil.assertStringIsAnonymisedButOfSameLength; | ||
|
||
import org.junit.Test; | ||
|
||
public class PhoneNumberGeneratorTest { | ||
|
||
@Test | ||
public void shouldConvertPhoneNumber() { | ||
final String originalPhoneNumber = "232132"; | ||
final String convertedPhoneNumber = new PhoneNumberGenerator().convert(originalPhoneNumber); | ||
assertTrue(PHONE_NUMBER_PATTERN.matcher(convertedPhoneNumber).matches()); | ||
assertStringIsAnonymisedButOfSameLength(convertedPhoneNumber, originalPhoneNumber); | ||
} | ||
|
||
@Test | ||
public void shouldReturnEmptyStringWhenValueIsNull() { | ||
assertThat(new PhoneNumberGenerator().convert(null), is("")); | ||
} | ||
|
||
@Test | ||
public void shouldReturnEmptyStringWhenValueIsEmptyString() { | ||
assertThat(new PhoneNumberGenerator().convert(""), is("")); | ||
} | ||
} |
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