Add tests for null precondition check in BulkRequest

Relates #18347

Checked with @javanna
This commit is contained in:
Daniel Mitterdorfer 2016-05-18 12:10:13 +02:00
parent 77c4970504
commit de3e7d161f
2 changed files with 8 additions and 0 deletions

View File

@ -169,6 +169,7 @@ public class BulkRequest extends ActionRequest<BulkRequest> implements Composite
}
public BulkRequest add(DeleteRequest request, @Nullable Object payload) {
Objects.requireNonNull(request, "'request' must not be null");
requests.add(request);
addPayload(payload);
sizeInBytes += REQUEST_OVERHEAD;

View File

@ -210,4 +210,11 @@ public class BulkRequestTests extends ESTestCase {
"script or doc is missing",
"source is missing"));
}
public void testCannotAddNullRequests() throws Exception {
BulkRequest bulkRequest = new BulkRequest();
expectThrows(NullPointerException.class, () -> bulkRequest.add((IndexRequest) null));
expectThrows(NullPointerException.class, () -> bulkRequest.add((UpdateRequest) null));
expectThrows(NullPointerException.class, () -> bulkRequest.add((DeleteRequest) null));
}
}