Skip to content

Commit

Permalink
Merge d36b9eb into 2506209
Browse files Browse the repository at this point in the history
  • Loading branch information
yashdeepScrumconnect committed Feb 25, 2020
2 parents 2506209 + d36b9eb commit e98051b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to
[Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Make Day and Month as 01 while anonymising date

## [6.4.0] - 2019-11-13
### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package uk.gov.justice.tools.eventsourcing.anonymization.generator;


import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class DateGenerator extends Generator<String> {

@Override
public String convert(final String fieldValue) {
return fieldValue;
final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
final LocalDate date = LocalDate.parse(fieldValue, dateTimeFormatter);
return date.withMonth(1).withDayOfMonth(1).toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package uk.gov.justice.tools.eventsourcing.anonymization.generator;

import org.apache.commons.validator.routines.DateValidator;
import org.junit.Test;

import static org.junit.Assert.assertTrue;

public class DateGeneratorTest {

@Test
public void shouldGenerateDateWithDayAndMonthAsOne() {
final DateGenerator dateGenerator = new DateGenerator();
final String dateValue = "2017-05-19";
final String anonymisedDateValue = dateGenerator.convert(dateValue);

assertTrue(DateValidator.getInstance().isValid(anonymisedDateValue,"yyyy-01-01"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public void shouldAnonymiseJsonObjectPayload() {
assertThat(exampleObject.getString("attributeString"), is("Warwick Justice Centre")); // should not anonymise
assertStringIsAnonymisedButOfLength(exampleObject.getString("attributeStringEmail"), "test123@mail.com", 14, of(EMAIL_PATTERN));
assertStringIsAnonymisedButOfSameLength(exampleObject.getString("attributeStringNiNumber"), "SC208978A", of(NI_NUMBER_PATTERN));
assertThat(exampleObject.getString("attributeDate"), is("2017-05-19"));
assertThat(exampleObject.getString("attributeDate"), is("2017-01-01"));
assertThat(exampleObject.getJsonArray("attributeArraySimple").getJsonObject(0).getString("arrayAttributeUUID"), is("1905c665-a146-4efc-a01b-d7f035820656"));
assertThat(exampleObject.getJsonArray("attributeArraySimple").getJsonObject(0).getString("arrayAttributeIntAsString"), is("001"));

final JsonArray complexArray = exampleObject.getJsonArray("attributeArrayComplex");
assertStringIsAnonymisedButOfSameLength(complexArray.getString(0), "abc");
assertThat(complexArray.getInt(1), is(1));
Expand All @@ -57,7 +58,6 @@ public void shouldNotAnonymiseJsonObjectPayload() {
assertThat(exampleObject.getString("attributeString"), is("Warwick Justice Centre"));
assertThat(exampleObject.getString("attributeStringEmail"), is("test123@mail.com"));
assertThat(exampleObject.getString("attributeStringNiNumber"), is("SC208978A"));
assertThat(exampleObject.getString("attributeDate"), is("2017-05-19"));
assertThat(exampleObject.getJsonArray("attributeArraySimple").getJsonObject(0).getString("arrayAttributeUUID"), is("1905c665-a146-4efc-a01b-d7f035820656"));
final JsonArray complexArray = exampleObject.getJsonArray("attributeArrayComplex");
assertThat(complexArray.getString(0), is("abc"));
Expand All @@ -82,6 +82,7 @@ public void shouldAnonymiseJsonArrayPayload() {
assertThat(anonymisedJsonArray.getJsonArray(4), is(createArrayBuilder().add(1).add(2).add(3).build()));
assertStringIsAnonymisedButOfLength(anonymisedJsonArray.getString(5), "test2345@mail.com", 14, of(EMAIL_PATTERN));
assertStringIsAnonymisedButOfSameLength(anonymisedJsonArray.getString(6), "SC208979B", of(NI_NUMBER_PATTERN));
assertThat(anonymisedJsonArray.getString(7), is("2017-01-01"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
3
],
"test2345@mail.com",
"SC208979B"
"SC208979B",
"2017-05-19"
]

0 comments on commit e98051b

Please sign in to comment.