Skip to content

Commit

Permalink
Change approach for unit test to make check stricker
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Gaievski <[email protected]>
  • Loading branch information
martin-gaievski committed Jul 25, 2024
1 parent b3ff25b commit 8acdc61
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1319,9 +1319,23 @@ public void testDoRewrite_whenNoFilter_thenSuccessful() {

@SneakyThrows
public void testDoRewrite_whenFilterSet_thenSuccessful() {
QueryBuilder filter = QueryBuilders.termQuery(TEXT_FIELD_NAME, TEXT_VALUE);
KNNQueryBuilder knnQueryBuilder = new KNNQueryBuilder(FIELD_NAME, QUERY_VECTOR, K, filter);
QueryBuilder rewritten = knnQueryBuilder.rewrite(mock(QueryRewriteContext.class));
assertEquals(knnQueryBuilder, rewritten);
// Given
QueryBuilder filter = mock(QueryBuilder.class);
QueryBuilder rewrittenFilter = mock(QueryBuilder.class);
QueryRewriteContext context = mock(QueryRewriteContext.class);
when(filter.rewrite(context)).thenReturn(rewrittenFilter);
KNNQueryBuilder expected = KNNQueryBuilder.builder()
.fieldName(FIELD_NAME)
.vector(QUERY_VECTOR)
.filter(rewrittenFilter)
.k(K)
.build();
// When
KNNQueryBuilder knnQueryBuilder = KNNQueryBuilder.builder().fieldName(FIELD_NAME).vector(QUERY_VECTOR).filter(filter).k(K).build();

QueryBuilder actual = knnQueryBuilder.rewrite(context);

// Then
assertEquals(expected, actual);
}
}

0 comments on commit 8acdc61

Please sign in to comment.