### Question:
SearchService { protected QueryBuilder prepareQueryBuilder(QuerySettings querySettings) { if (querySettings.getQuery() != null) { SimpleQueryStringBuilder qb = QueryBuilders.simpleQueryString(querySettings.getQuery()); Map<String, Object> fields = configService.get(ConfigService.CFGNAME_SEARCH_FULLTEXT_QUERY_FIELDS); if (fields != null) { for (String fieldName : fields.keySet()) { String value = (String) fields.get(fieldName); if (value != null && !value.trim().isEmpty()) { try { qb.field(fieldName, Float.parseFloat(value)); } catch (NumberFormatException e) { log.warning("Boost value has not valid float format for fulltext field " + fieldName + " in configuration document " + ConfigService.CFGNAME_SEARCH_FULLTEXT_QUERY_FIELDS); qb.field(fieldName); } } else { qb.field(fieldName); } } } return qb; } else { return QueryBuilders.matchAllQuery(); } }  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 handleFulltextSearchSettings() throws IOException, JSONException { ConfigService configService = Mockito.mock(ConfigService.class); SearchService tested = getTested(configService); try { tested.prepareQueryBuilder(null); Assert.fail("NullPointerException expected"); } catch (NullPointerException e) { } QuerySettings querySettings = new QuerySettings(); { querySettings.setQuery(null); QueryBuilder qbRes = tested.prepareQueryBuilder(querySettings); TestUtils.assertJsonContentFromClasspathFile("/search/query_match_all.json", qbRes.toString()); } { Mockito.reset(tested.configService); Mockito.when(tested.configService.get(ConfigService.CFGNAME_SEARCH_FULLTEXT_QUERY_FIELDS)).thenReturn(null); querySettings.setQuery("my query string"); QueryBuilder qbRes = tested.prepareQueryBuilder(querySettings); TestUtils.assertJsonContentFromClasspathFile("/search/query_fulltext.json", qbRes.toString()); Mockito.verify(tested.configService).get(ConfigService.CFGNAME_SEARCH_FULLTEXT_QUERY_FIELDS); Mockito.verifyNoMoreInteractions(tested.configService); } { Mockito.reset(tested.configService); Mockito.when(tested.configService.get(ConfigService.CFGNAME_SEARCH_FULLTEXT_QUERY_FIELDS)).thenReturn( TestUtils.loadJSONFromClasspathFile("/search/search_fulltext_query_fields.json")); querySettings.setQuery("my query string"); QueryBuilder qbRes = tested.prepareQueryBuilder(querySettings); TestUtils.assertJsonContentFromClasspathFile("/search/query_fulltext_fields.json", qbRes.toString()); Mockito.verify(tested.configService).get(ConfigService.CFGNAME_SEARCH_FULLTEXT_QUERY_FIELDS); Mockito.verifyNoMoreInteractions(tested.configService); } { querySettings.setQuery(null); Mockito.reset(tested.configService); Mockito.when(tested.configService.get(ConfigService.CFGNAME_SEARCH_FULLTEXT_QUERY_FIELDS)).thenReturn( TestUtils.loadJSONFromClasspathFile("/search/search_fulltext_query_fields.json")); QueryBuilder qbRes = tested.prepareQueryBuilder(querySettings); TestUtils.assertJsonContentFromClasspathFile("/search/query_match_all.json", qbRes.toString()); Mockito.verifyZeroInteractions(tested.configService); } }