HibernateSimpleQueryUtils { static int getIndexAfterFirstAppearanceOf(int startIndex, char character, String searchedString) { var queryCharCount = searchedString.length(); if(startIndex >= queryCharCount) { return -1; } var indexAfterFirstAppearance = searchedString.substring(startIndex).indexOf(character) + startIndex + 1; if(indexAfterFirstAppearance > 0 && indexAfterFirstAppearance < queryCharCount) { return indexAfterFirstAppearance; } 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 getIndexAfterFirstAppearanceOfReturnsMinusOneWhenCharacterNotPresentAfterStartIndex() { var input = "test"; var character = 'd'; var expectedIndex = -1; var startIndex = 0; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterFirstAppearanceOf(startIndex, character, input); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexAfterFirstAppearanceOfReturnsMinusOneWhenCharacterNotPresent() { var input = "abc"; var character = 'e'; var expectedIndex = -1; var startIndex = 0; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterFirstAppearanceOf(startIndex, character, input); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexAfterFirstAppearanceOfReturnsMinusOneWhenStartIndexGreaterThanInputLength() { var input = "test"; var character = '"'; var expectedIndex = -1; var startIndex = input.length(); var actualIndex = HibernateSimpleQueryUtils.getIndexAfterFirstAppearanceOf(startIndex, character, input); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexAfterFirstAppearanceOfReturnsMinusOneIfCharacterIsLastCharacter() { var input = "abcd"; var character = 'd'; var expectedIndex = -1; var startIndex = 0; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterFirstAppearanceOf(startIndex, character, input); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexAfterFirstAppearanceOfReturnsIndexAfterFirstAppearanceAfterStartIndexWhenCharacterPresent() { var input = "abc test"; var character = 't'; var expectedIndex = 5; var startIndex = 3; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterFirstAppearanceOf(startIndex, character, input); assertThat(actualIndex).isEqualTo(expectedIndex); }