Repository: searchbox-io/Jest
Pull request #650 (2019-07-02 22:51:40)

Fix Jest <-> native comparison link in root readme
This link is currently copied and pasted from `jest/README.md`. However, the link doesn't work in the root readme because that section doesn't exist. This updates the link to go to `jest/README.md` instead.


Patch:
diff --git a/README.md b/README.md
index 1ca59b03..332e63ee 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ Jest is a Java HTTP Rest client for [ElasticSearch][es].
 
 ElasticSearch is an Open Source (Apache 2), Distributed, RESTful, Search Engine built on top of Apache Lucene.
 
-ElasticSearch already has a Java API which is also used by ElasticSearch internally, [but Jest fills a gap, it is the missing client for ElasticSearch Http Rest interface](#comparison-to-native-api).
+ElasticSearch already has a Java API which is also used by ElasticSearch internally, [but Jest fills a gap, it is the missing client for ElasticSearch Http Rest interface](jest/README.md#comparison-to-native-api).
 
 >Read great [introduction][ibm] to ElasticSearch and Jest from IBM Developer works.
 
diff --git a/jest-common/src/main/java/io/searchbox/core/Bulk.java b/jest-common/src/main/java/io/searchbox/core/Bulk.java
index ee6b2498..cb28f704 100644
--- a/jest-common/src/main/java/io/searchbox/core/Bulk.java
+++ b/jest-common/src/main/java/io/searchbox/core/Bulk.java
@@ -155,6 +155,16 @@ public class Bulk extends AbstractAction<BulkResult> {
         return result;
     }
 
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj) && Objects.equals(bulkableActions, ((Bulk) obj).bulkableActions);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(super.hashCode(), this.bulkableActions);
+    }
+
     public static class Builder extends GenericResultAbstractAction.Builder<Bulk, Builder> {
         private List<BulkableAction> actions = new LinkedList<BulkableAction>();
         private String defaultIndex;


Test patch:
diff --git a/jest-common/src/test/java/io/searchbox/core/BulkTest.java b/jest-common/src/test/java/io/searchbox/core/BulkTest.java
index c4a8f98a..e64ce365 100644
--- a/jest-common/src/test/java/io/searchbox/core/BulkTest.java
+++ b/jest-common/src/test/java/io/searchbox/core/BulkTest.java
@@ -1,7 +1,9 @@
 package io.searchbox.core;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -109,6 +111,42 @@ public class BulkTest {
         assertEquals("twitter/tweet/_bulk", bulkWitIndexAndType.getURI(ElasticsearchVersion.UNKNOWN));
     }
 
+    @Test
+    public void testEqualsWithUnequalActions() {
+        final String index = "twitter";
+        final String type = "tweet";
+
+        final Object leftPayload = Collections.singletonMap("field", "value");
+        final Update leftAction = new Update.Builder(leftPayload).build();
+        final Bulk left = new Bulk.Builder()
+                .addAction(leftAction).defaultIndex(index).defaultType(type)
+                .build();
+
+        final Bulk right = new Bulk.Builder()
+                .defaultIndex(index).defaultType(type)
+                .build();
+
+        assertNotEquals(left, right);
+    }
+
+    @Test
+    public void testHashCodeWithUnequalActions() {
+        final String index = "twitter";
+        final String type = "tweet";
+
+        final Object leftPayload = Collections.singletonMap("field", "value");
+        final Update leftAction = new Update.Builder(leftPayload).build();
+        final Bulk left = new Bulk.Builder()
+                .addAction(leftAction).defaultIndex(index).defaultType(type)
+                .build();
+
+        final Bulk right = new Bulk.Builder()
+                .defaultIndex(index).defaultType(type)
+                .build();
+
+        assertNotEquals(left.hashCode(), right.hashCode());
+    }
+
     private void executeAsserts(Bulk bulk) {
         assertEquals("POST", bulk.getRestMethodName());
         assertEquals("/_bulk", bulk.getURI(ElasticsearchVersion.UNKNOWN));