コード例 #1
0
  public void testIllegalSuggestionName() {
    try {
      new SuggestBuilder()
          .addSuggestion(null, PhraseSuggestionBuilderTests.randomPhraseSuggestionBuilder());
      fail("exception expected");
    } catch (NullPointerException e) {
      assertEquals("every suggestion needs a name", e.getMessage());
    }

    try {
      new SuggestBuilder()
          .addSuggestion("my-suggest", PhraseSuggestionBuilderTests.randomPhraseSuggestionBuilder())
          .addSuggestion(
              "my-suggest", PhraseSuggestionBuilderTests.randomPhraseSuggestionBuilder());
      fail("exception expected");
    } catch (IllegalArgumentException e) {
      assertEquals("already added another suggestion with name [my-suggest]", e.getMessage());
    }
  }
コード例 #2
0
 private static SuggestionBuilder<?> randomSuggestionBuilder() {
   switch (randomIntBetween(0, 2)) {
     case 0:
       return TermSuggestionBuilderTests.randomTermSuggestionBuilder();
     case 1:
       return PhraseSuggestionBuilderTests.randomPhraseSuggestionBuilder();
     case 2:
       return CompletionSuggesterBuilderTests.randomCompletionSuggestionBuilder();
     default:
       return TermSuggestionBuilderTests.randomTermSuggestionBuilder();
   }
 }
コード例 #3
0
 @Override
 protected SuggestBuilder createMutation(SuggestBuilder original) throws IOException {
   SuggestBuilder mutation = new SuggestBuilder().setGlobalText(original.getGlobalText());
   for (Entry<String, SuggestionBuilder<?>> suggestionBuilder :
       original.getSuggestions().entrySet()) {
     mutation.addSuggestion(suggestionBuilder.getKey(), suggestionBuilder.getValue());
   }
   if (randomBoolean()) {
     mutation.setGlobalText(randomAsciiOfLengthBetween(5, 60));
   } else {
     mutation.addSuggestion(
         randomAsciiOfLength(10), PhraseSuggestionBuilderTests.randomPhraseSuggestionBuilder());
   }
   return mutation;
 }