Skip to content

Commit

Permalink
Merge pull request #287 from mziccard/fix-batch-response-equals
Browse files Browse the repository at this point in the history
Add getResult comparison to BatchResponse.equals
  • Loading branch information
aozarov committed Oct 23, 2015
2 parents 10e1cb4 + 4db34b7 commit e4da160
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public boolean equals(Object obj) {
BatchResponse other = (BatchResponse) obj;
return Objects.equals(deleteResult, other.deleteResult)
&& Objects.equals(updateResult, other.updateResult)
&& Objects.equals(updateResult, other.updateResult);
&& Objects.equals(getResult, other.getResult);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.gcloud.storage.Storage.PredefinedAcl.PUBLIC_READ;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -82,4 +83,56 @@ public void testBatchRequest() {
assertTrue(Iterables.isEmpty(get.getValue()));
assertFalse(gets.hasNext());
}

@Test
public void testEquals() {
BatchRequest request = BatchRequest.builder()
.delete("b1", "o1")
.delete("b1", "o2")
.update(BlobInfo.builder("b2", "o1").build())
.update(BlobInfo.builder("b2", "o2").build())
.get("b3", "o1")
.get("b3", "o2")
.build();
BatchRequest requestEquals = BatchRequest.builder()
.delete("b1", "o1")
.delete("b1", "o2")
.update(BlobInfo.builder("b2", "o1").build())
.update(BlobInfo.builder("b2", "o2").build())
.get("b3", "o1")
.get("b3", "o2")
.build();
BatchRequest requestNotEquals1 = BatchRequest.builder()
.delete("b1", "o1")
.delete("b1", "o3")
.update(BlobInfo.builder("b2", "o1").build())
.update(BlobInfo.builder("b2", "o2").build())
.get("b3", "o1")
.get("b3", "o2")
.build();
BatchRequest requestNotEquals2 = BatchRequest.builder()
.delete("b1", "o1")
.delete("b1", "o2")
.update(BlobInfo.builder("b2", "o1").build())
.update(BlobInfo.builder("b2", "o3").build())
.get("b3", "o1")
.get("b3", "o2")
.build();
BatchRequest requestNotEquals3 = BatchRequest.builder()
.delete("b1", "o1")
.delete("b1", "o2")
.update(BlobInfo.builder("b2", "o1").build())
.update(BlobInfo.builder("b2", "o2").build())
.get("b3", "o1")
.get("b3", "o3")
.build();
assertEquals(request, requestEquals);
assertEquals(request.hashCode(), requestEquals.hashCode());
assertNotEquals(request, requestNotEquals1);
assertNotEquals(request.hashCode(), requestNotEquals1.hashCode());
assertNotEquals(request, requestNotEquals2);
assertNotEquals(request.hashCode(), requestNotEquals2.hashCode());
assertNotEquals(request, requestNotEquals3);
assertNotEquals(request.hashCode(), requestNotEquals3.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.gcloud.storage;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import com.google.common.collect.ImmutableList;
import com.google.gcloud.storage.BatchResponse.Result;
Expand All @@ -34,12 +35,38 @@ public class BatchResponseTest {
@Test
public void testBatchResponse() {
List<Result<Boolean>> deletes = ImmutableList.of(Result.of(true), Result.of(false));
List<Result<BlobInfo>> updates = ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2));
List<Result<BlobInfo>> updates =
ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2));
List<Result<BlobInfo>> gets = ImmutableList.of(Result.of(BLOB_INFO_2), Result.of(BLOB_INFO_3));
BatchResponse response = new BatchResponse(deletes, updates, gets);

assertEquals(deletes, response.deletes());
assertEquals(updates, response.updates());
assertEquals(gets, response.gets());
}

@Test
public void testEquals() {
List<Result<Boolean>> deletes = ImmutableList.of(Result.of(true), Result.of(false));
List<Result<BlobInfo>> updates =
ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2));
List<Result<BlobInfo>> gets = ImmutableList.of(Result.of(BLOB_INFO_2), Result.of(BLOB_INFO_3));
List<Result<Boolean>> otherDeletes = ImmutableList.of(Result.of(false), Result.of(true));
List<Result<BlobInfo>> otherUpdates =
ImmutableList.of(Result.of(BLOB_INFO_2), Result.of(BLOB_INFO_3));
List<Result<BlobInfo>> otherGets =
ImmutableList.of(Result.of(BLOB_INFO_1), Result.of(BLOB_INFO_2));
BatchResponse response = new BatchResponse(deletes, updates, gets);
BatchResponse responseEquals = new BatchResponse(deletes, updates, gets);
BatchResponse responseNotEquals1 = new BatchResponse(otherDeletes, updates, gets);
BatchResponse responseNotEquals2 = new BatchResponse(deletes, otherUpdates, gets);
BatchResponse responseNotEquals3 = new BatchResponse(deletes, updates, otherGets);
assertEquals(response, responseEquals);
assertEquals(response.hashCode(), responseEquals.hashCode());
assertNotEquals(response, responseNotEquals1);
assertNotEquals(response.hashCode(), responseNotEquals1.hashCode());
assertNotEquals(response, responseNotEquals2);
assertNotEquals(response.hashCode(), responseNotEquals2.hashCode());
assertNotEquals(response, responseNotEquals3);
assertNotEquals(response.hashCode(), responseNotEquals3.hashCode());
}
}

0 comments on commit e4da160

Please sign in to comment.