LocalDateTimeService { public LocalDateTime now() { return LocalDateTime.now(); } } public class JobInteractor { private JobRepository jobRepository; private LocalDateTimeService localDateTimeService; public JobInteractor( JobRepository jobRepository, LocalDateTimeService localDateTimeService) { this.jobRepository = jobRepository; this.localDateTimeService = localDateTimeService; } public boolean isPublic(String id) { Job job = jobRepository.find(id).get(); // 公開終了日時 > 現在日時 return job.getPublicationEndDate().isAfter( localDateTimeService.now()); } } @Test @DisplayName("公開終了日時 > 現在日時 のときtrue") void 公開終了日時の前ならtrueを返す() { String id = "123"; Job job = new Job(); job.setPublicationEndDate( LocalDateTime.of(2023, 6, 4, 16, 00, 01)); given(jobRepository.find(id)).willReturn(job); given(localDateTimeService.now()) .willReturn(LocalDateTime.of(2023, 6, 4, 16, 00, 00)); boolean actual = jobInteractor.isPublic(id); assertTrue(actual); } テスト対象コード テストコード LocalDateTimeのBean