Skip to content

Commit

Permalink
Adding semantic check for missing arguments in function and unit test.
Browse files Browse the repository at this point in the history
Signed-off-by: forestmvey <[email protected]>
  • Loading branch information
forestmvey committed Jun 27, 2023
1 parent 84fab78 commit de77277
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public SortBuilder<?> build(Expression expression, Sort.SortOption option) {
* @param nestedFunc Nested function expression.
*/
private void validateNestedArgs(FunctionExpression nestedFunc) {
if (nestedFunc.getArguments().size() > 2) {
if (nestedFunc.getArguments().size() < 1 || nestedFunc.getArguments().size() > 2) {
throw new IllegalArgumentException(
"nested function supports 2 parameters (field, path) or 1 parameter (field)"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ void nested_with_too_many_args_throws_exception() {
);
}

@Test
void nested_with_too_few_args_throws_exception() {
assertThrows(
IllegalArgumentException.class,
() -> sortQueryBuilder.build(
DSL.nested(),
Sort.SortOption.DEFAULT_ASC
)
);
}

@Test
void nested_with_invalid_arg_type_throws_exception() {
assertThrows(
Expand Down

0 comments on commit de77277

Please sign in to comment.