This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from patientsknowbest/feature/PHR-11742_no_in…
…vitation_letters_under_16 PHR-11742 Add new AgeUtilService
- Loading branch information
Showing
5 changed files
with
130 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>pkb-common</artifactId> | ||
<groupId>com.pkb.pkbcommon</groupId> | ||
<version>${revision}${changelist}</version> | ||
</parent> | ||
|
||
<artifactId>util</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.pkb.pkbcommon</groupId> | ||
<artifactId>date-time</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-core</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.karsaig</groupId> | ||
<artifactId>approvalcrest-junit-jupiter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-junit-jupiter</artifactId> | ||
<version>4.5.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
23 changes: 23 additions & 0 deletions
23
util/src/main/java/com/pkb/pkbcommon/ageutil/AgeUtilService.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,23 @@ | ||
package com.pkb.pkbcommon.ageutil; | ||
|
||
import com.pkb.common.datetime.DateTimeService; | ||
|
||
import java.time.LocalDate; | ||
import java.time.ZoneOffset; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public class AgeUtilService { | ||
|
||
private final DateTimeService dateTimeService; | ||
|
||
public AgeUtilService(DateTimeService dateTimeService) { | ||
this.dateTimeService = dateTimeService; | ||
} | ||
|
||
public boolean patientIsOlderThan(LocalDate dateOfBirth, int ageInYears) { | ||
return dateOfBirth.plus(ageInYears, ChronoUnit.YEARS) | ||
.atStartOfDay(ZoneOffset.UTC) | ||
.toInstant() | ||
.isBefore(dateTimeService.now()); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
util/src/test/java/com/pkb/pkbcommon/ageutil/AgeUtilServiceTest.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,40 @@ | ||
package com.pkb.pkbcommon.ageutil; | ||
|
||
import com.pkb.common.datetime.DateTimeService; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
|
||
import static com.github.karsaig.approvalcrest.jupiter.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class AgeUtilServiceTest { | ||
|
||
@Mock | ||
DateTimeService dateTimeService; | ||
@InjectMocks | ||
AgeUtilService underTest; | ||
|
||
@Test | ||
public void testUnderSixteen() { | ||
Instant currentTime = Instant.parse("2020-01-02T00:00:00Z"); | ||
when(dateTimeService.now()).thenReturn(currentTime); | ||
LocalDate dateOfBirth = LocalDate.of(2004,1,2); | ||
assertThat(underTest.patientIsOlderThan(dateOfBirth, 16), is(false)); | ||
} | ||
|
||
@Test | ||
public void testOverSixteenByOneSecond() { | ||
Instant currentTime = Instant.parse("2020-01-02T00:01:00Z"); | ||
when(dateTimeService.now()).thenReturn(currentTime); | ||
LocalDate dateOfBirth = LocalDate.of(2004,1,2); | ||
assertThat(underTest.patientIsOlderThan(dateOfBirth, 16), is(true)); | ||
} | ||
} |