diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/RemoteBigQueryHelperTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/testing/RemoteBigQueryHelperTest.java similarity index 97% rename from gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/RemoteBigQueryHelperTest.java rename to gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/testing/RemoteBigQueryHelperTest.java index 267ae161b7aa..a9c0f63d68ea 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/RemoteBigQueryHelperTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/testing/RemoteBigQueryHelperTest.java @@ -14,13 +14,14 @@ * limitations under the License. */ -package com.google.gcloud.bigquery; +package com.google.gcloud.bigquery.testing; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import com.google.gcloud.bigquery.BigQuery; import com.google.gcloud.bigquery.BigQuery.DatasetDeleteOption; -import com.google.gcloud.bigquery.testing.RemoteBigQueryHelper; +import com.google.gcloud.bigquery.BigQueryOptions; import org.easymock.EasyMock; import org.junit.Rule; diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalDatastoreHelperTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/testing/LocalDatastoreHelperTest.java similarity index 94% rename from gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalDatastoreHelperTest.java rename to gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/testing/LocalDatastoreHelperTest.java index f731657d6bcc..25ddef1ee4be 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalDatastoreHelperTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/testing/LocalDatastoreHelperTest.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.google.gcloud.datastore; +package com.google.gcloud.datastore.testing; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import com.google.gcloud.AuthCredentials; -import com.google.gcloud.datastore.testing.LocalDatastoreHelper; +import com.google.gcloud.datastore.DatastoreOptions; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/gcloud-java-resourcemanager/src/test/java/com/google/gcloud/resourcemanager/LocalResourceManagerHelperTest.java b/gcloud-java-resourcemanager/src/test/java/com/google/gcloud/resourcemanager/testing/LocalResourceManagerHelperTest.java similarity index 99% rename from gcloud-java-resourcemanager/src/test/java/com/google/gcloud/resourcemanager/LocalResourceManagerHelperTest.java rename to gcloud-java-resourcemanager/src/test/java/com/google/gcloud/resourcemanager/testing/LocalResourceManagerHelperTest.java index 75df0ef9e3ae..612a4752df6d 100644 --- a/gcloud-java-resourcemanager/src/test/java/com/google/gcloud/resourcemanager/LocalResourceManagerHelperTest.java +++ b/gcloud-java-resourcemanager/src/test/java/com/google/gcloud/resourcemanager/testing/LocalResourceManagerHelperTest.java @@ -1,4 +1,4 @@ -package com.google.gcloud.resourcemanager; +package com.google.gcloud.resourcemanager.testing; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -11,10 +11,10 @@ import com.google.api.services.cloudresourcemanager.model.Binding; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.gcloud.resourcemanager.ResourceManagerException; import com.google.gcloud.resourcemanager.spi.DefaultResourceManagerRpc; import com.google.gcloud.resourcemanager.spi.ResourceManagerRpc; import com.google.gcloud.resourcemanager.spi.ResourceManagerRpc.Tuple; -import com.google.gcloud.resourcemanager.testing.LocalResourceManagerHelper; import org.junit.AfterClass; import org.junit.Before; diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java index 9000d0fb8047..72fcfeff034f 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java @@ -526,7 +526,9 @@ public Builder toBuilder() { @Override public final boolean equals(Object obj) { - return obj instanceof Blob && Objects.equals(toPb(), ((Blob) obj).toPb()) + return this == obj + || obj instanceof Blob + && Objects.equals(toPb(), ((Blob) obj).toPb()) && Objects.equals(options, ((Blob) obj).options); } diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteStorageHelperTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/testing/RemoteStorageHelperTest.java similarity index 78% rename from gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteStorageHelperTest.java rename to gcloud-java-storage/src/test/java/com/google/gcloud/storage/testing/RemoteStorageHelperTest.java index 0702d8aba65f..7b8033fc69bb 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteStorageHelperTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/testing/RemoteStorageHelperTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.gcloud.storage; +package com.google.gcloud.storage.testing; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -22,8 +22,12 @@ import com.google.common.collect.ImmutableList; import com.google.gcloud.Page; +import com.google.gcloud.storage.Blob; +import com.google.gcloud.storage.BlobId; +import com.google.gcloud.storage.Storage; import com.google.gcloud.storage.Storage.BlobListOption; -import com.google.gcloud.storage.testing.RemoteStorageHelper; +import com.google.gcloud.storage.StorageException; +import com.google.gcloud.storage.StorageOptions; import org.easymock.EasyMock; import org.junit.Before; @@ -71,8 +75,11 @@ public class RemoteStorageHelperTest { private static final InputStream JSON_KEY_STREAM = new ByteArrayInputStream(JSON_KEY.getBytes()); private static final StorageException RETRYABLE_EXCEPTION = new StorageException(409, ""); private static final StorageException FATAL_EXCEPTION = new StorageException(500, ""); + private static final BlobId BLOB_ID1 = BlobId.of(BUCKET_NAME, "n1"); + private static final BlobId BLOB_ID2 = BlobId.of(BUCKET_NAME, "n2"); - private static Storage serviceMockReturnsOptions; + private Blob blob1; + private Blob blob2; private List blobList; private Page blobPage; @@ -81,18 +88,9 @@ public class RemoteStorageHelperTest { @Before public void setUp() { - serviceMockReturnsOptions = EasyMock.createMock(Storage.class); - EasyMock.expect(serviceMockReturnsOptions.options()) - .andReturn(EasyMock.createMock(StorageOptions.class)) - .times(2); - EasyMock.replay(serviceMockReturnsOptions); - blobList = ImmutableList.of( - new Blob( - serviceMockReturnsOptions, - new BlobInfo.BuilderImpl(BlobInfo.builder(BUCKET_NAME, "n1").build())), - new Blob( - serviceMockReturnsOptions, - new BlobInfo.BuilderImpl(BlobInfo.builder(BUCKET_NAME, "n2").build()))); + blob1 = EasyMock.createMock(Blob.class); + blob2 = EasyMock.createMock(Blob.class); + blobList = ImmutableList.of(blob1, blob2); blobPage = new Page() { @Override public String nextPageCursor() { @@ -119,27 +117,29 @@ public Iterator iterateAll() { @Test public void testForceDelete() throws InterruptedException, ExecutionException { Storage storageMock = EasyMock.createMock(Storage.class); + EasyMock.expect(blob1.blobId()).andReturn(BLOB_ID1); + EasyMock.expect(storageMock.delete(BLOB_ID1)).andReturn(true); + EasyMock.expect(blob2.blobId()).andReturn(BLOB_ID2); + EasyMock.expect(storageMock.delete(BLOB_ID2)).andReturn(true); EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true))) .andReturn(blobPage); - for (BlobInfo info : blobList) { - EasyMock.expect(storageMock.delete(info.blobId())).andReturn(true); - } EasyMock.expect(storageMock.delete(BUCKET_NAME)).andReturn(true); - EasyMock.replay(storageMock); + EasyMock.replay(storageMock, blob1, blob2); assertTrue(RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME, 5, TimeUnit.SECONDS)); - EasyMock.verify(storageMock); + EasyMock.verify(storageMock, blob1, blob2); } @Test public void testForceDeleteTimeout() throws InterruptedException, ExecutionException { Storage storageMock = EasyMock.createMock(Storage.class); + EasyMock.expect(blob1.blobId()).andReturn(BLOB_ID1).anyTimes(); + EasyMock.expect(storageMock.delete(BLOB_ID1)).andReturn(true).anyTimes(); + EasyMock.expect(blob2.blobId()).andReturn(BLOB_ID2).anyTimes(); + EasyMock.expect(storageMock.delete(BLOB_ID2)).andReturn(true).anyTimes(); EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true))) .andReturn(blobPage).anyTimes(); - for (BlobInfo info : blobList) { - EasyMock.expect(storageMock.delete(info.blobId())).andReturn(true).anyTimes(); - } EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(RETRYABLE_EXCEPTION).anyTimes(); - EasyMock.replay(storageMock); + EasyMock.replay(storageMock, blob1, blob2); assertFalse( RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME, 50, TimeUnit.MICROSECONDS)); EasyMock.verify(storageMock); @@ -148,13 +148,14 @@ public void testForceDeleteTimeout() throws InterruptedException, ExecutionExcep @Test public void testForceDeleteFail() throws InterruptedException, ExecutionException { Storage storageMock = EasyMock.createMock(Storage.class); + EasyMock.expect(blob1.blobId()).andReturn(BLOB_ID1); + EasyMock.expect(storageMock.delete(BLOB_ID1)).andReturn(true); + EasyMock.expect(blob2.blobId()).andReturn(BLOB_ID2); + EasyMock.expect(storageMock.delete(BLOB_ID2)).andReturn(true); EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true))) .andReturn(blobPage); - for (BlobInfo info : blobList) { - EasyMock.expect(storageMock.delete(info.blobId())).andReturn(true); - } EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(FATAL_EXCEPTION); - EasyMock.replay(storageMock); + EasyMock.replay(storageMock, blob1, blob2); thrown.expect(ExecutionException.class); try { RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME, 5, TimeUnit.SECONDS); @@ -166,13 +167,14 @@ public void testForceDeleteFail() throws InterruptedException, ExecutionExceptio @Test public void testForceDeleteNoTimeout() { Storage storageMock = EasyMock.createMock(Storage.class); + EasyMock.expect(blob1.blobId()).andReturn(BLOB_ID1); + EasyMock.expect(storageMock.delete(BLOB_ID1)).andReturn(true); + EasyMock.expect(blob2.blobId()).andReturn(BLOB_ID2); + EasyMock.expect(storageMock.delete(BLOB_ID2)).andReturn(true); EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true))) .andReturn(blobPage); - for (BlobInfo info : blobList) { - EasyMock.expect(storageMock.delete(info.blobId())).andReturn(true); - } EasyMock.expect(storageMock.delete(BUCKET_NAME)).andReturn(true); - EasyMock.replay(storageMock); + EasyMock.replay(storageMock, blob1, blob2); RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME); EasyMock.verify(storageMock); } @@ -180,13 +182,14 @@ public void testForceDeleteNoTimeout() { @Test public void testForceDeleteNoTimeoutFail() { Storage storageMock = EasyMock.createMock(Storage.class); + EasyMock.expect(blob1.blobId()).andReturn(BLOB_ID1); + EasyMock.expect(storageMock.delete(BLOB_ID1)).andReturn(true); + EasyMock.expect(blob2.blobId()).andReturn(BLOB_ID2); + EasyMock.expect(storageMock.delete(BLOB_ID2)).andReturn(true); EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true))) .andReturn(blobPage); - for (BlobInfo info : blobList) { - EasyMock.expect(storageMock.delete(info.blobId())).andReturn(true); - } EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(FATAL_EXCEPTION); - EasyMock.replay(storageMock); + EasyMock.replay(storageMock, blob1, blob2); thrown.expect(StorageException.class); try { RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME);