@@ -250,8 +250,8 @@ public void testTokenFiltersBypassSynonymAnalysis() throws IOException {
250
250
251
251
public void testPreconfiguredTokenFilters () throws IOException {
252
252
Set <String > disallowedFilters = new HashSet <>(Arrays .asList (
253
- "common_grams" , "edge_ngram" , "edgeNGram" , " keyword_repeat" , "ngram" , "nGram " ,
254
- "shingle" , " word_delimiter" , "word_delimiter_graph"
253
+ "common_grams" , "edge_ngram" , "keyword_repeat" , "ngram" , "shingle " ,
254
+ "word_delimiter" , "word_delimiter_graph"
255
255
));
256
256
257
257
Settings settings = Settings .builder ()
@@ -260,23 +260,23 @@ public void testPreconfiguredTokenFilters() throws IOException {
260
260
.put ("path.home" , createTempDir ().toString ())
261
261
.build ();
262
262
IndexSettings idxSettings = IndexSettingsModule .newIndexSettings ("index" , settings );
263
-
264
- CommonAnalysisPlugin plugin = new CommonAnalysisPlugin ();
265
-
266
- for (PreConfiguredTokenFilter tf : plugin .getPreConfiguredTokenFilters ()) {
267
- if (disallowedFilters .contains (tf .getName ())) {
268
- IllegalArgumentException e = expectThrows (IllegalArgumentException .class ,
269
- "Expected exception for factory " + tf .getName (), () -> {
270
- tf .get (idxSettings , null , tf .getName (), settings ).getSynonymFilter ();
271
- });
272
- assertEquals (tf .getName (), "Token filter [" + tf .getName ()
273
- + "] cannot be used to parse synonyms" ,
274
- e .getMessage ());
275
- }
276
- else {
277
- tf .get (idxSettings , null , tf .getName (), settings ).getSynonymFilter ();
263
+ Set <String > disallowedFiltersTested = new HashSet <String >();
264
+
265
+ try (CommonAnalysisPlugin plugin = new CommonAnalysisPlugin ()) {
266
+ for (PreConfiguredTokenFilter tf : plugin .getPreConfiguredTokenFilters ()) {
267
+ if (disallowedFilters .contains (tf .getName ())) {
268
+ IllegalArgumentException e = expectThrows (IllegalArgumentException .class ,
269
+ "Expected exception for factory " + tf .getName (), () -> {
270
+ tf .get (idxSettings , null , tf .getName (), settings ).getSynonymFilter ();
271
+ });
272
+ assertEquals (tf .getName (), "Token filter [" + tf .getName () + "] cannot be used to parse synonyms" , e .getMessage ());
273
+ disallowedFiltersTested .add (tf .getName ());
274
+ } else {
275
+ tf .get (idxSettings , null , tf .getName (), settings ).getSynonymFilter ();
276
+ }
278
277
}
279
278
}
279
+ assertEquals ("Set of dissallowed filters contains more filters than tested" , disallowedFiltersTested , disallowedFilters );
280
280
}
281
281
282
282
public void testDisallowedTokenFilters () throws IOException {
0 commit comments