### Question:
MessageService { public List<Message> getMessagesMatchingFilter(MessageFilter filter) { Date calcFromDate = Optional.ofNullable(filter.getFromDate()).orElse(startOfDay()); Date calcToDate = Optional.ofNullable(filter.getFromDate()).orElse(endOfDay()); Integer calcPage = Optional.ofNullable(filter.getPageNumber()).orElse(0); Integer calcSize = Optional.ofNullable(filter.getPageSize()).orElse(25); boolean includeInbound = Optional.ofNullable(filter.getDirectionInbound()).orElse(true); boolean includeOutbound = Optional.ofNullable(filter.getDirectionOutbound()).orElse(true); Collection<Message.Direction> includeDirections = new TreeSet<>(); if (includeInbound) { includeDirections.add(Message.Direction.INBOUND); } if (includeOutbound) { includeDirections.add(Message.Direction.OUTBOUND); } Pageable pageable = new PageRequest(calcPage, calcSize, Sort.Direction.DESC, "date"); if (StringUtils.isNotEmpty(filter.getContainingText())) { return messageRepository.findByDateBetweenAndDirectionInAndPayloadContainingIgnoreCase(calcFromDate, calcToDate, includeDirections, filter.getContainingText(), pageable); } else { return messageRepository.findByDateBetweenAndDirectionIn(calcFromDate, calcToDate, includeDirections, pageable); } } @Autowired  MessageService(MessageRepository messageRepository); Message saveMessage(Message.Direction direction, String payload, String citrusMessageId, Map<String, Object> headers); Message getMessageById(Long id); List<Message> getMessagesMatchingFilter(MessageFilter filter); void clearMessages();  }### Answer:
@Test public void shouldGetMessagesUsingNoDefaults() throws Exception { Date dateFrom = new Date(); Date dateTo = new Date(); int pageNumber = 10; int pageSize = 1000; String text = "abc"; MessageFilter filter = new MessageFilter(); filter.setFromDate(dateFrom); filter.setToDate(dateTo); filter.setPageNumber(pageNumber); filter.setPageSize(pageSize); filter.setDirectionInbound(false); filter.setDirectionOutbound(false); filter.setContainingText(text); when(messageRepository.findByDateBetweenAndDirectionInAndPayloadContainingIgnoreCase( eq(dateFrom), eq(dateTo), directionsCaptor.capture(), eq(text), pageableCaptor.capture()) ).thenReturn(singleResult()); assertHasSingleResult(sut.getMessagesMatchingFilter(filter)); assertPagingMatches(pageNumber, pageSize); assertDirectionMatches(); }
@Test public void shouldGetMessagesUsingDefaults() throws Exception { MessageFilter filter = new MessageFilter(); when(messageRepository.findByDateBetweenAndDirectionIn( notNull(), notNull(), directionsCaptor.capture(), pageableCaptor.capture()) ).thenReturn(singleResult()); assertHasSingleResult(sut.getMessagesMatchingFilter(filter)); assertPagingMatches(0, 25); assertDirectionMatches(Message.Direction.INBOUND, Message.Direction.OUTBOUND); }