### Question:
BatchRequest implements Request { IndexRequest uniformAction(Collection<IndexRequest> indexRequests) { IndexRequest current = null; for (IndexRequest indexRequest : indexRequests) { if (current == null) { current = indexRequest; continue; } if (!current.index.equals(indexRequest.index) || !current.type.equals(indexRequest.type)) { return null; } } return current; } protected  BatchRequest(Builder builder); ItemSource serialize(); void completed(); Collection<IndexRequest> getIndexRequests(); @Override String getURI(); @Override String getHttpMethodName(); static final String HTTP_METHOD_NAME; static final char LINE_SEPARATOR; }### Answer:
@Test public void itemsAreIdenticalIfIndicesAndTypeAreTheSame() { String index1 = UUID.randomUUID().toString(); String type1 = UUID.randomUUID().toString(); IndexRequest item1 = IndexRequestTest.createIndexRequestBuilder() .type(type1) .index(index1) .build(); IndexRequest item2 = IndexRequestTest.createIndexRequestBuilder() .type(type1) .index(index1) .build(); Collection<IndexRequest> items = new ArrayList<>(); items.add(item1); items.add(item2); BatchRequest batchRequest = createDefaultTestObjectBuilder().build(); IndexRequest result = batchRequest.uniformAction(items); assertEquals(result, item1); }
@Test public void itemsAreNotIdenticalIfIndicesAreDifferent() { String type1 = UUID.randomUUID().toString(); IndexRequest item1 = IndexRequestTest.createIndexRequestBuilder() .type(type1) .index(UUID.randomUUID().toString()) .build(); IndexRequest item2 = IndexRequestTest.createIndexRequestBuilder() .type(type1) .index(UUID.randomUUID().toString()) .build(); Collection<IndexRequest> items = new ArrayList<>(); items.add(item1); items.add(item2); BatchRequest batchRequest = createDefaultTestObjectBuilder().build(); IndexRequest result = batchRequest.uniformAction(items); assertNull(result); }
@Test public void itemsAreNotIdenticalIfTypesAreDifferent() { String index = UUID.randomUUID().toString(); IndexRequest item1 = IndexRequestTest.createIndexRequestBuilder() .type(UUID.randomUUID().toString()) .index(index) .build(); IndexRequest item2 = IndexRequestTest.createIndexRequestBuilder() .type(UUID.randomUUID().toString()) .index(index) .build(); Collection<IndexRequest> items = new ArrayList<>(); items.add(item1); items.add(item2); BatchRequest batchRequest = createDefaultTestObjectBuilder().build(); IndexRequest result = batchRequest.uniformAction(items); assertNull(result); }
@Test public void itemsAreNotIdenticalIfBothIndicesAndTypesAreDifferent() { IndexRequest item1 = IndexRequestTest.createIndexRequestBuilder() .type(UUID.randomUUID().toString()) .index(UUID.randomUUID().toString()) .build(); IndexRequest item2 = IndexRequestTest.createIndexRequestBuilder() .type(UUID.randomUUID().toString()) .index(UUID.randomUUID().toString()) .build(); Collection<IndexRequest> items = new ArrayList<>(); items.add(item1); items.add(item2); BatchRequest batchRequest = createDefaultTestObjectBuilder().build(); IndexRequest result = batchRequest.uniformAction(items); assertNull(result); }