Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getResult comparison to BatchResponse.equals #287

Merged
merged 1 commit into from
Oct 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}