Skip to content

Commit b8088ad

Browse files
committed
Use Instant.now() instead of new Date().toInstant().
Replaced `new Date().toInstant()` with `Instant.now()` for clearer and more concise timestamp generation. This simplifies the code and eliminates unnecessary intermediate objects while maintaining the same functionality. Updated corresponding test cases to reflect the changes.
1 parent 347a5a5 commit b8088ad

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/service/impl/RASPassPortService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.springframework.util.LinkedMultiValueMap;
2121
import org.springframework.util.MultiValueMap;
2222

23+
import java.time.Instant;
2324
import java.util.*;
2425
import java.util.stream.Collectors;
2526

@@ -165,7 +166,7 @@ public Set<RasDbgapPermission> ga4gpPassportToRasDbgapPermissions(Set<Optional<G
165166

166167
logger.debug("Converting ga4ghPassports to RasDbgapPermissions");
167168
HashSet<RasDbgapPermission> rasDbgapPermissions = new HashSet<>();
168-
long date = new Date().toInstant().toEpochMilli();
169+
long date = Instant.now().toEpochMilli();
169170
ga4ghPassports.forEach(ga4ghPassport -> {
170171
if (ga4ghPassport.isPresent()) {
171172
Ga4ghPassportV1 ga4ghPassportV1 = ga4ghPassport.get();

pic-sure-auth-services/src/test/java/edu/harvard/hms/dbmi/avillach/auth/service/impl/RASPassPortServiceTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.springframework.http.ResponseEntity;
1515
import org.springframework.test.context.ContextConfiguration;
1616

17+
import java.time.Instant;
1718
import java.util.*;
1819
import java.util.concurrent.atomic.AtomicInteger;
1920
import java.util.stream.Collectors;
@@ -67,7 +68,7 @@ public void testGa4gpPassportStudies_IsNotNull_And_ExpiredPermissionsExcluded()
6768
@Test
6869
public void testGa4gpPassportStudies_HasCorrectStudies() {
6970
Optional<Passport> passport = JWTUtil.parsePassportJWTV11(exampleRasPassport);
70-
long futureDate = new Date().toInstant().toEpochMilli() + 100000;
71+
long futureDate = Instant.now().toEpochMilli() + 100000;
7172

7273
// Update the expiry date of each permission in our test passport. All permissions in the example passport
7374
// expired in 2022.
@@ -93,8 +94,8 @@ public void testGa4gpPassportStudies_HasCorrectStudies() {
9394
@Test
9495
public void testGa4gpPassportStudies_HalfAreExpired() {
9596
Optional<Passport> passport = JWTUtil.parsePassportJWTV11(exampleRasPassport);
96-
long futureDate = new Date().toInstant().toEpochMilli() + 100000;
97-
long pastDate = new Date().toInstant().toEpochMilli() - 100000;
97+
long futureDate = Instant.now().toEpochMilli() + 100000;
98+
long pastDate = Instant.now().toEpochMilli() - 100000;
9899

99100
List<String> expiredPHS = new ArrayList<>();
100101
List<String> validPHS = new ArrayList<>();

0 commit comments

Comments
 (0)