HibernateSimpleQueryUtils { static int getIndexAfterFirstAppearanceOfAny(int startIndex, Set<Character> characters, String searchedString) { var queryCharCount = searchedString.length(); if(startIndex >= queryCharCount) { return -1; } for(var currentIndex = startIndex; currentIndex < queryCharCount; currentIndex++) { if(characters.contains(searchedString.charAt(currentIndex)) && (currentIndex + 1 ) != queryCharCount) { return currentIndex + 1; } } return -1; }  static String makeQueryPrefixAndFuzzy(@NonNull String simpleQuery); static String createLuceneQueryString(Collection<String> values, String operator,
                                                  Function<String, String> function); static String createLuceneQueryString(Collection<String> values, String operator);  }
@Test public void getIndexAfterFirstAppearanceOfAnyReturnsMinusOneWhenStartIndexGreaterThanInputLength() { var input = "test"; var characters = Set.of('t', 'e'); var expectedIndex = -1; var startIndex = 4; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterFirstAppearanceOfAny(startIndex, characters, input); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexAfterFirstAppearanceOfAnyReturnsMinusOneWhenNoCharacterPresent() { var input = "abcd"; var characters = Set.of('e', 'f'); var expectedIndex = -1; var startIndex = 0; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterFirstAppearanceOfAny(startIndex, characters, input); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexAfterFirstAppearanceOfAnyReturnsIndexAfterFirstAppearanceAfterStartIndexOfAnyCharacter() { var input = "xyz abcd"; var characters = Set.of('a', 'b'); var expectedIndex = 5; var startIndex = 3; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterFirstAppearanceOfAny(startIndex, characters, input); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexAfterFirstAppearanceOfAnyReturnsMinusOneWhenNoCharacterPresentAfterStartIndex() { var input = "abcd"; var characters = Set.of('a', 'b'); var expectedIndex = -1; var startIndex = 2; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterFirstAppearanceOfAny(startIndex, characters, input); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexAfterFirstAppearanceOfAnyReturnsMinusOneWhenCharacterIsLastCharacter() { var input = "abcd"; var characters = Set.of('d'); var expectedIndex = -1; var startIndex = 0; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterFirstAppearanceOfAny(startIndex, characters, input); assertThat(actualIndex).isEqualTo(expectedIndex); }