Skip to content

Commit

Permalink
[Fix] Fix SearchDaoTest stability issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Jul 17, 2024
1 parent 0f5bf5d commit db621dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/test/java/cz/cvut/kbss/termit/environment/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ public static <T> T randomItem(T[] arr) {
return arr[randomIndex(arr)];
}

/**
* Returns a (pseudo)random element from the specified list.
* @param lst List to select random element from
* @return Element from the list
* @param <T> Element type
*/
public static <T> T randomElement(List<T> lst) {
return lst.get(randomIndex(lst));
}

/**
* Generators a (pseudo) random boolean.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,13 @@ void facetedTermSearchReturnsTermsMatchingExactMatchSearchParamWithSpecifiedValu

@Test
void facetedTermSearchReturnsTermsMatchingSubstringSearchParamWithSpecifiedValue() {
final Term sample = Generator.randomElement(terms);
final String sampleValue = sample.getExamples().iterator().next().get().substring(0, 4);
final SearchParam param = new SearchParam(URI.create(SKOS.EXAMPLE),
Set.of("matching"),
Set.of(sampleValue),
MatchType.SUBSTRING);
final List<Term> matchingTerms = terms.stream().filter(t -> t.getExamples().iterator().next().get()
.startsWith("Matching"))
.startsWith(sampleValue))
.collect(Collectors.toList());
final List<FacetedSearchResult> result = sut.facetedTermSearch(Set.of(param), Constants.DEFAULT_PAGE_SPEC);
assertFalse(result.isEmpty());
Expand Down

0 comments on commit db621dc

Please sign in to comment.