### Question:
SearchService { protected QueryBuilder applyContentLevelSecurityFilter(QueryBuilder qb) { FilterBuilder securityFilter = getContentLevelSecurityFilterInternal(); if (securityFilter == null) { return qb; } else { return new FilteredQueryBuilder(qb, securityFilter); } }  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 applyContentLevelSecurityFilter() throws IOException, JSONException { ConfigService configService = mockConfigurationService(); SearchService tested = getTested(configService); QueryBuilder qb = QueryBuilders.matchAllQuery(); { Mockito.when(tested.authenticationUtilService.isAuthenticatedUser()).thenReturn(false); QueryBuilder retqb = tested.applyContentLevelSecurityFilter(qb); TestUtils.assertJsonContentFromClasspathFile("/search/query_dlsecurity_filter_anonym.json", retqb.toString()); } { Mockito.reset(tested.authenticationUtilService); Mockito.when(tested.authenticationUtilService.isUserInRole(Role.ADMIN)).thenReturn(true); Mockito.when(tested.authenticationUtilService.isAuthenticatedUser()).thenReturn(true); QueryBuilder retqb = tested.applyContentLevelSecurityFilter(qb); TestUtils.assertJsonContentFromClasspathFile("/search/query_dlsecurity_filter_admin.json", retqb.toString()); Mockito.verify(tested.authenticationUtilService).isUserInRole(Role.ADMIN); Mockito.verifyNoMoreInteractions(tested.authenticationUtilService); } { Mockito.reset(tested.authenticationUtilService); Mockito.when(tested.authenticationUtilService.isUserInRole(Role.ADMIN)).thenReturn(false); Mockito.when(tested.authenticationUtilService.getUserRoles()).thenReturn( TestUtils.createSetOfStrings("role1", "role2")); Mockito.when(tested.authenticationUtilService.isAuthenticatedUser()).thenReturn(true); QueryBuilder retqb = tested.applyContentLevelSecurityFilter(qb); TestUtils.assertJsonContentFromClasspathFile("/search/query_dlsecurity_filter_userwithroles.json", retqb.toString()); Mockito.verify(tested.authenticationUtilService).isUserInRole(Role.ADMIN); Mockito.verify(tested.authenticationUtilService).isAuthenticatedUser(); Mockito.verify(tested.authenticationUtilService).getUserRoles(); Mockito.verifyNoMoreInteractions(tested.authenticationUtilService); } }