Skip to content

Commit

Permalink
Updated code to use currentTimeHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Edwards-cgi committed Jan 31, 2025
1 parent 3dfb8c8 commit 9feaa75
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.time.Clock;
import java.time.LocalDate;
import java.time.OffsetDateTime;

Expand All @@ -14,12 +15,14 @@
@RequiredArgsConstructor
public class CurrentTimeHelper {

private final Clock clock;

public OffsetDateTime currentOffsetDateTime() {
return OffsetDateTime.now();
return OffsetDateTime.now(clock);
}

public LocalDate currentLocalDate() {
return LocalDate.now();
return LocalDate.now(clock);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.darts.audio.model.AddAudioMetadataRequest;
import uk.gov.hmcts.darts.common.helper.CurrentTimeHelper;
import uk.gov.hmcts.darts.log.service.AudioLoggerService;
import uk.gov.hmcts.darts.util.DataUtil;

import java.time.Clock;
import java.time.OffsetDateTime;

import static uk.gov.hmcts.darts.util.DateTimeHelper.getDateTimeIsoFormatted;

@Service
@Slf4j
@AllArgsConstructor
public class AudioLoggerServiceImpl implements AudioLoggerService {

private final Clock clock;
private final CurrentTimeHelper currentTimeHelper;

@Override
public void audioUploaded(AddAudioMetadataRequest request) {
Expand All @@ -33,6 +31,6 @@ public void missingCourthouse(String courthouse, String courtroom) {
log.warn("Courthouse not found: courthouse={}, courtroom={}, timestamp={}",
DataUtil.toUpperCase(courthouse),
DataUtil.toUpperCase(courtroom),
getDateTimeIsoFormatted(OffsetDateTime.now(clock)));
getDateTimeIsoFormatted(currentTimeHelper.currentOffsetDateTime()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import uk.gov.hmcts.darts.audio.model.AddAudioMetadataRequest;
import uk.gov.hmcts.darts.common.helper.CurrentTimeHelper;
import uk.gov.hmcts.darts.log.service.AudioLoggerService;
import uk.gov.hmcts.darts.util.TestClock;

Expand Down Expand Up @@ -45,7 +46,7 @@ public static void tearDown() {

@BeforeEach
void setUp() {
audioLoggerService = new AudioLoggerServiceImpl(new TestClock(STARTED_AT));
audioLoggerService = new AudioLoggerServiceImpl(new CurrentTimeHelper(new TestClock(STARTED_AT)));
}

@Test
Expand Down

0 comments on commit 9feaa75

Please sign in to comment.