### Question:
SearchService { protected void setSearchRequestSort(QuerySettings querySettings, SearchRequestBuilder srb) { if (querySettings.getSortBy() != null) { if (querySettings.getSortBy().equals(SortByValue.NEW)) { srb.addSort(ContentObjectFields.SYS_LAST_ACTIVITY_DATE, SortOrder.DESC); } else if (querySettings.getSortBy().equals(SortByValue.OLD)) { srb.addSort(ContentObjectFields.SYS_LAST_ACTIVITY_DATE, SortOrder.ASC); } else if (querySettings.getSortBy().equals(SortByValue.NEW_CREATION)) { srb.addSort(ContentObjectFields.SYS_CREATED, SortOrder.DESC); } } }  SearchResponse performSearch(QuerySettings querySettings, String responseUuid, StatsRecordType statsRecordType); Map<String, String> getIntervalValuesForDateHistogramAggregations(QuerySettings querySettings); boolean writeSearchHitUsedStatisticsRecord(String uuid, String contentId, String sessionId); SearchResponse performSearchTemplate(final String templateName, final Map<String, Object> templateParams,
												final QuerySettings.Filters filters); static final String CFGNAME_FIELD_VISIBLE_FOR_ROLES; static final String CFGNAME_SOURCE_FILTERING_FOR_ROLES; static final int RESPONSE_MAX_SIZE; }### Answer:
@Test public void handleSortingSettings() { SearchService tested = getTested(Mockito.mock(ConfigService.class)); SearchRequestBuilder srbMock = Mockito.mock(SearchRequestBuilder.class); try { tested.setSearchRequestSort(null, srbMock); Assert.fail("NullPointerException expected"); } catch (NullPointerException e) { Mockito.verifyNoMoreInteractions(srbMock); } { Mockito.reset(srbMock); QuerySettings querySettings = new QuerySettings(); tested.setSearchRequestSort(querySettings, srbMock); Mockito.verifyNoMoreInteractions(srbMock); } { Mockito.reset(srbMock); QuerySettings querySettings = new QuerySettings(); querySettings.setSortBy(SortByValue.SCORE); tested.setSearchRequestSort(querySettings, srbMock); Mockito.verifyNoMoreInteractions(srbMock); } { Mockito.reset(srbMock); QuerySettings querySettings = new QuerySettings(); querySettings.setSortBy(SortByValue.NEW); tested.setSearchRequestSort(querySettings, srbMock); Mockito.verify(srbMock).addSort("sys_last_activity_date", SortOrder.DESC); Mockito.verifyNoMoreInteractions(srbMock); } { Mockito.reset(srbMock); QuerySettings querySettings = new QuerySettings(); querySettings.setSortBy(SortByValue.OLD); tested.setSearchRequestSort(querySettings, srbMock); Mockito.verify(srbMock).addSort("sys_last_activity_date", SortOrder.ASC); Mockito.verifyNoMoreInteractions(srbMock); } { Mockito.reset(srbMock); QuerySettings querySettings = new QuerySettings(); querySettings.setSortBy(SortByValue.NEW_CREATION); tested.setSearchRequestSort(querySettings, srbMock); Mockito.verify(srbMock).addSort("sys_created", SortOrder.DESC); Mockito.verifyNoMoreInteractions(srbMock); } }