TransactionalEventService { public List<Event> getEventsBeforeDate(final Date date, final int pageSize) { final PageRequest pageRequest = PageRequest.of(0, pageSize, Sort.Direction.DESC, "id"); final Slice<Event> slice = this.eventRepository.findByDateTimeBefore(date, pageRequest); final List<Event> events = slice.getContent(); LOGGER.info("Found {} events with date time before {}.", events.size(), date); return events; }  List<Event> getEventsBeforeDate(final Date date, final int pageSize); void deleteEvents(final List<Event> events);  }
@Test public void serviceReturnsOneEvent() { final Slice<Event> mockSlice = this.mockSliceOfEvents(1); final PageRequest pageRequest = PageRequest.of(0, 10, Sort.Direction.DESC, "id"); Mockito.when(this.eventRepository.findByDateTimeBefore(this.now, pageRequest)).thenReturn(mockSlice); final List<Event> events = this.transactionalEventService.getEventsBeforeDate(this.now, 10); assertThat(events.size()).isEqualTo(1); }
@Test public void serviceReturnsTenEvents() { final Slice<Event> mockSlice = this.mockSliceOfEvents(10); final PageRequest pageRequest = PageRequest.of(0, 10, Sort.Direction.DESC, "id"); Mockito.when(this.eventRepository.findByDateTimeBefore(this.now, pageRequest)).thenReturn(mockSlice); final List<Event> events = this.transactionalEventService.getEventsBeforeDate(this.now, 10); assertThat(events.size()).isEqualTo(10); }