Skip to content

Commit

Permalink
chore: remove deprecated method (#32)
Browse files Browse the repository at this point in the history
* chore: remove deprecated method

* chore: modified code
  • Loading branch information
Praful Makani committed Jan 30, 2020
1 parent 195096c commit 53abe4a
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 69 deletions.
Expand Up @@ -27,6 +27,7 @@
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand All @@ -46,10 +47,9 @@
import org.easymock.Capture;
import org.easymock.CaptureType;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class BlobWriteChannelTest {

Expand All @@ -65,8 +65,6 @@ public class BlobWriteChannelTest {
private static final String SIGNED_URL =
"http://www.test.com/test-bucket/test1.txt?GoogleAccessId=testClient-test@test.com&Expires=1553839761&Signature=MJUBXAZ7";

@Rule public ExpectedException thrown = ExpectedException.none();

private StorageOptions options;
private StorageRpcFactory rpcFactoryMock;
private StorageRpc storageRpcMock;
Expand Down Expand Up @@ -113,8 +111,12 @@ public void testCreateNonRetryableError() {
expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS))
.andThrow(new RuntimeException());
replay(storageRpcMock);
thrown.expect(RuntimeException.class);
new BlobWriteChannel(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
try {
new BlobWriteChannel(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
Assert.fail();
} catch (RuntimeException ex) {
assertNotNull(ex.getMessage());
}
}

@Test
Expand Down Expand Up @@ -391,9 +393,12 @@ public void testRuntimeExceptionWithSignedURL() throws MalformedURLException {
expect(new BlobWriteChannel(options, new URL(SIGNED_URL)))
.andThrow(new RuntimeException(exceptionMessage));
replay(storageRpcMock);
thrown.expect(StorageException.class);
thrown.expectMessage(exceptionMessage);
writer = new BlobWriteChannel(options, new URL(SIGNED_URL));
try {
writer = new BlobWriteChannel(options, new URL(SIGNED_URL));
Assert.fail();
} catch (StorageException ex) {
assertNotNull(ex.getMessage());
}
}

private static ByteBuffer randomBuffer(int size) {
Expand Down
Expand Up @@ -24,6 +24,7 @@
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -52,10 +53,9 @@
import java.util.Map;
import javax.crypto.spec.SecretKeySpec;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class BucketTest {

Expand Down Expand Up @@ -135,8 +135,6 @@ public class BucketTest {
private Bucket expectedBucket;
private List<Blob> blobResults;

@Rule public ExpectedException thrown = ExpectedException.none();

@Before
public void setUp() {
storage = createStrictMock(Storage.class);
Expand Down Expand Up @@ -446,15 +444,17 @@ public void testCreateWithWrongGenerationOptions() throws Exception {
replay(storage);
initializeBucket();
byte[] content = {0xD, 0xE, 0xA, 0xD};
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"Only one option of generationMatch, doesNotExist or generationNotMatch can be provided");
bucket.create(
"n",
content,
CONTENT_TYPE,
Bucket.BlobTargetOption.generationMatch(42L),
Bucket.BlobTargetOption.generationNotMatch(24L));
try {
bucket.create(
"n",
content,
CONTENT_TYPE,
Bucket.BlobTargetOption.generationMatch(42L),
Bucket.BlobTargetOption.generationNotMatch(24L));
Assert.fail();
} catch (IllegalArgumentException ex) {
assertNotNull(ex.getMessage());
}
}

@Test
Expand All @@ -464,15 +464,17 @@ public void testCreateWithWrongMetagenerationOptions() throws Exception {
replay(storage);
initializeBucket();
byte[] content = {0xD, 0xE, 0xA, 0xD};
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"metagenerationMatch and metagenerationNotMatch options can not be both provided");
bucket.create(
"n",
content,
CONTENT_TYPE,
Bucket.BlobTargetOption.metagenerationMatch(42L),
Bucket.BlobTargetOption.metagenerationNotMatch(24L));
try {
bucket.create(
"n",
content,
CONTENT_TYPE,
Bucket.BlobTargetOption.metagenerationMatch(42L),
Bucket.BlobTargetOption.metagenerationNotMatch(24L));
Assert.fail();
} catch (IllegalArgumentException ex) {
assertNotNull(ex.getMessage());
}
}

@Test
Expand Down Expand Up @@ -592,15 +594,17 @@ public void testCreateFromStreamWithWrongGenerationOptions() throws Exception {
initializeBucket();
byte[] content = {0xD, 0xE, 0xA, 0xD};
InputStream streamContent = new ByteArrayInputStream(content);
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"Only one option of generationMatch, doesNotExist or generationNotMatch can be provided");
bucket.create(
"n",
streamContent,
CONTENT_TYPE,
Bucket.BlobWriteOption.generationMatch(42L),
Bucket.BlobWriteOption.generationNotMatch(24L));
try {
bucket.create(
"n",
streamContent,
CONTENT_TYPE,
Bucket.BlobWriteOption.generationMatch(42L),
Bucket.BlobWriteOption.generationNotMatch(24L));
Assert.fail();
} catch (IllegalArgumentException ex) {
assertNotNull(ex.getMessage());
}
}

@Test
Expand All @@ -611,15 +615,17 @@ public void testCreateFromStreamWithWrongMetagenerationOptions() throws Exceptio
initializeBucket();
byte[] content = {0xD, 0xE, 0xA, 0xD};
InputStream streamContent = new ByteArrayInputStream(content);
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"metagenerationMatch and metagenerationNotMatch options can not be both provided");
bucket.create(
"n",
streamContent,
CONTENT_TYPE,
Bucket.BlobWriteOption.metagenerationMatch(42L),
Bucket.BlobWriteOption.metagenerationNotMatch(24L));
try {
bucket.create(
"n",
streamContent,
CONTENT_TYPE,
Bucket.BlobWriteOption.metagenerationMatch(42L),
Bucket.BlobWriteOption.metagenerationNotMatch(24L));
Assert.fail();
} catch (IllegalArgumentException ex) {
assertNotNull(ex.getMessage());
}
}

@Test
Expand Down
Expand Up @@ -86,11 +86,10 @@
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class StorageImplTest {

Expand Down Expand Up @@ -384,8 +383,6 @@ public long millisTime() {
private Blob expectedBlob1, expectedBlob2, expectedBlob3;
private Bucket expectedBucket1, expectedBucket2, expectedBucket3;

@Rule public ExpectedException thrown = ExpectedException.none();

@BeforeClass
public static void beforeClass() throws NoSuchAlgorithmException, InvalidKeySpecException {
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
Expand Down Expand Up @@ -785,9 +782,12 @@ public void testCreateBlobFromStreamRetryableException() throws IOException {

// Even though this exception is retryable, storage.create(BlobInfo, InputStream)
// shouldn't retry.
thrown.expect(StorageException.class);
thrown.expectMessage("internalError");
storage.create(infoWithHashes, fileStream);
try {
storage.create(infoWithHashes, fileStream);
Assert.fail();
} catch (StorageException ex) {
assertNotNull(ex.getMessage());
}
}

@Test
Expand Down Expand Up @@ -2973,9 +2973,12 @@ public void testNonRetryableException() {
.build()
.getService();
initializeServiceDependentObjects();
thrown.expect(StorageException.class);
thrown.expectMessage(exceptionMessage);
storage.get(blob);
try {
storage.get(blob);
Assert.fail();
} catch (StorageException ex) {
Assert.assertNotNull(ex.getMessage());
}
}

@Test
Expand All @@ -2991,9 +2994,12 @@ public void testRuntimeException() {
.setRetrySettings(ServiceOptions.getDefaultRetrySettings())
.build()
.getService();
thrown.expect(StorageException.class);
thrown.expectMessage(exceptionMessage);
storage.get(blob);
try {
storage.get(blob);
Assert.fail();
} catch (StorageException ex) {
Assert.assertNotNull(ex.getMessage());
}
}

@Test
Expand Down
Expand Up @@ -29,7 +29,8 @@ public void testInvalidTransport() {
StorageOptions.newBuilder()
.setTransportOptions(EasyMock.<TransportOptions>createMock(TransportOptions.class));
Assert.fail();
} catch (IllegalArgumentException expected) {
} catch (IllegalArgumentException ex) {
Assert.assertNotNull(ex.getMessage());
}
}
}
Expand Up @@ -18,6 +18,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.google.api.gax.paging.Page;
Expand All @@ -37,10 +38,9 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.threeten.bp.Duration;

public class RemoteStorageHelperTest {
Expand Down Expand Up @@ -86,8 +86,6 @@ public class RemoteStorageHelperTest {
private List<Blob> blobList;
private Page<Blob> blobPage;

@Rule public ExpectedException thrown = ExpectedException.none();

@Before
public void setUp() {
blob1 = EasyMock.createMock(Blob.class);
Expand Down Expand Up @@ -175,9 +173,11 @@ public void testForceDeleteFail() throws InterruptedException, ExecutionExceptio
.andReturn(blobPage);
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(FATAL_EXCEPTION);
EasyMock.replay(storageMock, blob1, blob2);
thrown.expect(ExecutionException.class);
try {
RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME, 5, TimeUnit.SECONDS);
Assert.fail();
} catch (ExecutionException ex) {
assertNotNull(ex.getMessage());
} finally {
EasyMock.verify(storageMock);
}
Expand Down Expand Up @@ -213,9 +213,11 @@ public void testForceDeleteNoTimeoutFail() {
.andReturn(blobPage);
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(FATAL_EXCEPTION);
EasyMock.replay(storageMock, blob1, blob2);
thrown.expect(StorageException.class);
try {
RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME);
Assert.fail();
} catch (StorageException ex) {
assertNotNull(ex.getMessage());
} finally {
EasyMock.verify(storageMock);
}
Expand Down

0 comments on commit 53abe4a

Please sign in to comment.