Skip to content

Commit

Permalink
Ensure setRequest cannot be passed null
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Dec 15, 2023
1 parent bb8e602 commit 51facc5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public SearchTemplateRequest(SearchRequest searchRequest) {
}

public void setRequest(SearchRequest request) {
Objects.requireNonNull(request);
this.request = request;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.opensearch.search.RandomSearchRequestGenerator;
import org.opensearch.search.builder.SearchSourceBuilder;
import org.opensearch.test.AbstractWireSerializingTestCase;
import org.junit.Assert;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -113,8 +114,7 @@ public static SearchTemplateRequest createRandomRequest() {
}

public void testSimulatedSearchTemplateRequest() {
SearchTemplateRequest request = createRandomRequest();
request.setRequest(null);
SearchTemplateRequest request = new SearchTemplateRequest();
request.setSimulate(true);

assertEquals(0, request.indices().length);
Expand All @@ -127,4 +127,9 @@ public void testSimulatedSearchTemplateRequest() {

assertEquals(expectedIndicesLength, randomRequest.indices().length);
}

public void testSearchTemplateRequestSetRequestCannotBeNull() {
SearchTemplateRequest request = new SearchTemplateRequest();
Assert.assertThrows(NullPointerException.class, () -> request.setRequest(null));
}
}

0 comments on commit 51facc5

Please sign in to comment.