Skip to content

Commit e4da160

Browse files
committed
Merge pull request #287 from mziccard/fix-batch-response-equals
Add getResult comparison to BatchResponse.equals
2 parents 10e1cb4 + 4db34b7 commit e4da160

File tree

3 files changed

+83
-3
lines changed

3 files changed

+83
-3
lines changed

gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public boolean equals(Object obj) {
133133
BatchResponse other = (BatchResponse) obj;
134134
return Objects.equals(deleteResult, other.deleteResult)
135135
&& Objects.equals(updateResult, other.updateResult)
136-
&& Objects.equals(updateResult, other.updateResult);
136+
&& Objects.equals(getResult, other.getResult);
137137
}
138138

139139
/**

gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchRequestTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.gcloud.storage.Storage.PredefinedAcl.PUBLIC_READ;
2020
import static org.junit.Assert.assertEquals;
2121
import static org.junit.Assert.assertFalse;
22+
import static org.junit.Assert.assertNotEquals;
2223
import static org.junit.Assert.assertTrue;
2324

2425
import com.google.common.collect.Iterables;
@@ -82,4 +83,56 @@ public void testBatchRequest() {
8283
assertTrue(Iterables.isEmpty(get.getValue()));
8384
assertFalse(gets.hasNext());
8485
}
86+
87+
@Test
88+
public void testEquals() {
89+
BatchRequest request = BatchRequest.builder()
90+
.delete("b1", "o1")
91+
.delete("b1", "o2")
92+
.update(BlobInfo.builder("b2", "o1").build())
93+
.update(BlobInfo.builder("b2", "o2").build())
94+
.get("b3", "o1")
95+
.get("b3", "o2")
96+
.build();
97+
BatchRequest requestEquals = BatchRequest.builder()
98+
.delete("b1", "o1")
99+
.delete("b1", "o2")
100+
.update(BlobInfo.builder("b2", "o1").build())
101+
.update(BlobInfo.builder("b2", "o2").build())
102+
.get("b3", "o1")
103+
.get("b3", "o2")
104+
.build();
105+
BatchRequest requestNotEquals1 = BatchRequest.builder()
106+
.delete("b1", "o1")
107+
.delete("b1", "o3")
108+
.update(BlobInfo.builder("b2", "o1").build())
109+
.update(BlobInfo.builder("b2", "o2").build())
110+
.get("b3", "o1")
111+
.get("b3", "o2")
112+
.build();
113+
BatchRequest requestNotEquals2 = BatchRequest.builder()
114+
.delete("b1", "o1")
115+
.delete("b1", "o2")
116+
.update(BlobInfo.builder("b2", "o1").build())
117+
.update(BlobInfo.builder("b2", "o3").build())
118+
.get("b3", "o1")
119+
.get("b3", "o2")
120+
.build();
121+
BatchRequest requestNotEquals3 = BatchRequest.builder()
122+
.delete("b1", "o1")
123+
.delete("b1", "o2")
124+
.update(BlobInfo.builder("b2", "o1").build())
125+
.update(BlobInfo.builder("b2", "o2").build())
126+
.get("b3", "o1")
127+
.get("b3", "o3")
128+
.build();
129+
assertEquals(request, requestEquals);
130+
assertEquals(request.hashCode(), requestEquals.hashCode());
131+
assertNotEquals(request, requestNotEquals1);
132+
assertNotEquals(request.hashCode(), requestNotEquals1.hashCode());
133+
assertNotEquals(request, requestNotEquals2);
134+
assertNotEquals(request.hashCode(), requestNotEquals2.hashCode());
135+
assertNotEquals(request, requestNotEquals3);
136+
assertNotEquals(request.hashCode(), requestNotEquals3.hashCode());
137+
}
85138
}

gcloud-java-storage/src/test/java/com/google/gcloud/storage/BatchResponseTest.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.gcloud.storage;
1818

1919
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotEquals;
2021

2122
import com.google.common.collect.ImmutableList;
2223
import com.google.gcloud.storage.BatchResponse.Result;
@@ -34,12 +35,38 @@ public class BatchResponseTest {
3435
@Test
3536
public void testBatchResponse() {
3637
List<Result<Boolean>> deletes = ImmutableList.of(Result.of(true), Result.of(false));
37-
List<Result<BlobInfo>> updates = ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2));
38+
List<Result<BlobInfo>> updates =
39+
ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2));
3840
List<Result<BlobInfo>> gets = ImmutableList.of(Result.of(BLOB_INFO_2), Result.of(BLOB_INFO_3));
3941
BatchResponse response = new BatchResponse(deletes, updates, gets);
40-
4142
assertEquals(deletes, response.deletes());
4243
assertEquals(updates, response.updates());
4344
assertEquals(gets, response.gets());
4445
}
46+
47+
@Test
48+
public void testEquals() {
49+
List<Result<Boolean>> deletes = ImmutableList.of(Result.of(true), Result.of(false));
50+
List<Result<BlobInfo>> updates =
51+
ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2));
52+
List<Result<BlobInfo>> gets = ImmutableList.of(Result.of(BLOB_INFO_2), Result.of(BLOB_INFO_3));
53+
List<Result<Boolean>> otherDeletes = ImmutableList.of(Result.of(false), Result.of(true));
54+
List<Result<BlobInfo>> otherUpdates =
55+
ImmutableList.of(Result.of(BLOB_INFO_2), Result.of(BLOB_INFO_3));
56+
List<Result<BlobInfo>> otherGets =
57+
ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2));
58+
BatchResponse response = new BatchResponse(deletes, updates, gets);
59+
BatchResponse responseEquals = new BatchResponse(deletes, updates, gets);
60+
BatchResponse responseNotEquals1 = new BatchResponse(otherDeletes, updates, gets);
61+
BatchResponse responseNotEquals2 = new BatchResponse(deletes, otherUpdates, gets);
62+
BatchResponse responseNotEquals3 = new BatchResponse(deletes, updates, otherGets);
63+
assertEquals(response, responseEquals);
64+
assertEquals(response.hashCode(), responseEquals.hashCode());
65+
assertNotEquals(response, responseNotEquals1);
66+
assertNotEquals(response.hashCode(), responseNotEquals1.hashCode());
67+
assertNotEquals(response, responseNotEquals2);
68+
assertNotEquals(response.hashCode(), responseNotEquals2.hashCode());
69+
assertNotEquals(response, responseNotEquals3);
70+
assertNotEquals(response.hashCode(), responseNotEquals3.hashCode());
71+
}
4572
}

0 commit comments

Comments
 (0)