Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #101 from patientsknowbest/feature/PHR-11742_no_in…
Browse files Browse the repository at this point in the history
…vitation_letters_under_16

PHR-11742 Add new AgeUtilService
  • Loading branch information
idasbiste authored Sep 6, 2023
2 parents b37854a + 8601bd8 commit e846102
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 1 deletion.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<module>spring-boot-infrastructure</module>
<module>spring-boot-kotlin-infrastructure</module>
<module>pubsub</module>
<module>util</module>
</modules>

<dependencyManagement>
Expand Down
11 changes: 10 additions & 1 deletion suppression.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,14 @@
<cve>CVE-2020-8908</cve>
<cve>CVE-2023-2976</cve>
</suppress>

<suppress until="2023-11-01">
<notes><![CDATA[
file name: netty-handler-4.1.94.Final.jar
]]></notes>
<packageUrl regex="true">^pkg:maven/io\.netty/netty\-handler@.*$</packageUrl>
<!-- This is not a vulnerability, just the fact that it's possible to misconfigure and disable hostname verification -->
<!-- see https://github.com/netty/netty/issues/8537 and https://github.com/netty/netty/issues/9930 -->
<!-- It's very possible that this won't ever go away, just increase the suppression then -->
<vulnerabilityName>CVE-2023-4586</vulnerabilityName>
</suppress>
</suppressions>
56 changes: 56 additions & 0 deletions util/pom.xml
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 util/src/main/java/com/pkb/pkbcommon/ageutil/AgeUtilService.java
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());
}
}
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));
}
}

0 comments on commit e846102

Please sign in to comment.