Skip to content

Commit 53abe4a

Browse files
author
Praful Makani
authored
chore: remove deprecated method (#32)
* chore: remove deprecated method * chore: modified code
1 parent 195096c commit 53abe4a

File tree

5 files changed

+89
-69
lines changed

5 files changed

+89
-69
lines changed

google-cloud-storage/src/test/java/com/google/cloud/storage/BlobWriteChannelTest.java

+14-9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.easymock.EasyMock.verify;
2828
import static org.junit.Assert.assertArrayEquals;
2929
import static org.junit.Assert.assertEquals;
30+
import static org.junit.Assert.assertNotNull;
3031
import static org.junit.Assert.assertTrue;
3132
import static org.junit.Assert.fail;
3233

@@ -46,10 +47,9 @@
4647
import org.easymock.Capture;
4748
import org.easymock.CaptureType;
4849
import org.junit.After;
50+
import org.junit.Assert;
4951
import org.junit.Before;
50-
import org.junit.Rule;
5152
import org.junit.Test;
52-
import org.junit.rules.ExpectedException;
5353

5454
public class BlobWriteChannelTest {
5555

@@ -65,8 +65,6 @@ public class BlobWriteChannelTest {
6565
private static final String SIGNED_URL =
6666
"http://www.test.com/test-bucket/[email protected]&Expires=1553839761&Signature=MJUBXAZ7";
6767

68-
@Rule public ExpectedException thrown = ExpectedException.none();
69-
7068
private StorageOptions options;
7169
private StorageRpcFactory rpcFactoryMock;
7270
private StorageRpc storageRpcMock;
@@ -113,8 +111,12 @@ public void testCreateNonRetryableError() {
113111
expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS))
114112
.andThrow(new RuntimeException());
115113
replay(storageRpcMock);
116-
thrown.expect(RuntimeException.class);
117-
new BlobWriteChannel(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
114+
try {
115+
new BlobWriteChannel(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
116+
Assert.fail();
117+
} catch (RuntimeException ex) {
118+
assertNotNull(ex.getMessage());
119+
}
118120
}
119121

120122
@Test
@@ -391,9 +393,12 @@ public void testRuntimeExceptionWithSignedURL() throws MalformedURLException {
391393
expect(new BlobWriteChannel(options, new URL(SIGNED_URL)))
392394
.andThrow(new RuntimeException(exceptionMessage));
393395
replay(storageRpcMock);
394-
thrown.expect(StorageException.class);
395-
thrown.expectMessage(exceptionMessage);
396-
writer = new BlobWriteChannel(options, new URL(SIGNED_URL));
396+
try {
397+
writer = new BlobWriteChannel(options, new URL(SIGNED_URL));
398+
Assert.fail();
399+
} catch (StorageException ex) {
400+
assertNotNull(ex.getMessage());
401+
}
397402
}
398403

399404
private static ByteBuffer randomBuffer(int size) {

google-cloud-storage/src/test/java/com/google/cloud/storage/BucketTest.java

+46-40
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.easymock.EasyMock.verify;
2525
import static org.junit.Assert.assertEquals;
2626
import static org.junit.Assert.assertFalse;
27+
import static org.junit.Assert.assertNotNull;
2728
import static org.junit.Assert.assertNull;
2829
import static org.junit.Assert.assertTrue;
2930

@@ -52,10 +53,9 @@
5253
import java.util.Map;
5354
import javax.crypto.spec.SecretKeySpec;
5455
import org.junit.After;
56+
import org.junit.Assert;
5557
import org.junit.Before;
56-
import org.junit.Rule;
5758
import org.junit.Test;
58-
import org.junit.rules.ExpectedException;
5959

6060
public class BucketTest {
6161

@@ -135,8 +135,6 @@ public class BucketTest {
135135
private Bucket expectedBucket;
136136
private List<Blob> blobResults;
137137

138-
@Rule public ExpectedException thrown = ExpectedException.none();
139-
140138
@Before
141139
public void setUp() {
142140
storage = createStrictMock(Storage.class);
@@ -446,15 +444,17 @@ public void testCreateWithWrongGenerationOptions() throws Exception {
446444
replay(storage);
447445
initializeBucket();
448446
byte[] content = {0xD, 0xE, 0xA, 0xD};
449-
thrown.expect(IllegalArgumentException.class);
450-
thrown.expectMessage(
451-
"Only one option of generationMatch, doesNotExist or generationNotMatch can be provided");
452-
bucket.create(
453-
"n",
454-
content,
455-
CONTENT_TYPE,
456-
Bucket.BlobTargetOption.generationMatch(42L),
457-
Bucket.BlobTargetOption.generationNotMatch(24L));
447+
try {
448+
bucket.create(
449+
"n",
450+
content,
451+
CONTENT_TYPE,
452+
Bucket.BlobTargetOption.generationMatch(42L),
453+
Bucket.BlobTargetOption.generationNotMatch(24L));
454+
Assert.fail();
455+
} catch (IllegalArgumentException ex) {
456+
assertNotNull(ex.getMessage());
457+
}
458458
}
459459

460460
@Test
@@ -464,15 +464,17 @@ public void testCreateWithWrongMetagenerationOptions() throws Exception {
464464
replay(storage);
465465
initializeBucket();
466466
byte[] content = {0xD, 0xE, 0xA, 0xD};
467-
thrown.expect(IllegalArgumentException.class);
468-
thrown.expectMessage(
469-
"metagenerationMatch and metagenerationNotMatch options can not be both provided");
470-
bucket.create(
471-
"n",
472-
content,
473-
CONTENT_TYPE,
474-
Bucket.BlobTargetOption.metagenerationMatch(42L),
475-
Bucket.BlobTargetOption.metagenerationNotMatch(24L));
467+
try {
468+
bucket.create(
469+
"n",
470+
content,
471+
CONTENT_TYPE,
472+
Bucket.BlobTargetOption.metagenerationMatch(42L),
473+
Bucket.BlobTargetOption.metagenerationNotMatch(24L));
474+
Assert.fail();
475+
} catch (IllegalArgumentException ex) {
476+
assertNotNull(ex.getMessage());
477+
}
476478
}
477479

478480
@Test
@@ -592,15 +594,17 @@ public void testCreateFromStreamWithWrongGenerationOptions() throws Exception {
592594
initializeBucket();
593595
byte[] content = {0xD, 0xE, 0xA, 0xD};
594596
InputStream streamContent = new ByteArrayInputStream(content);
595-
thrown.expect(IllegalArgumentException.class);
596-
thrown.expectMessage(
597-
"Only one option of generationMatch, doesNotExist or generationNotMatch can be provided");
598-
bucket.create(
599-
"n",
600-
streamContent,
601-
CONTENT_TYPE,
602-
Bucket.BlobWriteOption.generationMatch(42L),
603-
Bucket.BlobWriteOption.generationNotMatch(24L));
597+
try {
598+
bucket.create(
599+
"n",
600+
streamContent,
601+
CONTENT_TYPE,
602+
Bucket.BlobWriteOption.generationMatch(42L),
603+
Bucket.BlobWriteOption.generationNotMatch(24L));
604+
Assert.fail();
605+
} catch (IllegalArgumentException ex) {
606+
assertNotNull(ex.getMessage());
607+
}
604608
}
605609

606610
@Test
@@ -611,15 +615,17 @@ public void testCreateFromStreamWithWrongMetagenerationOptions() throws Exceptio
611615
initializeBucket();
612616
byte[] content = {0xD, 0xE, 0xA, 0xD};
613617
InputStream streamContent = new ByteArrayInputStream(content);
614-
thrown.expect(IllegalArgumentException.class);
615-
thrown.expectMessage(
616-
"metagenerationMatch and metagenerationNotMatch options can not be both provided");
617-
bucket.create(
618-
"n",
619-
streamContent,
620-
CONTENT_TYPE,
621-
Bucket.BlobWriteOption.metagenerationMatch(42L),
622-
Bucket.BlobWriteOption.metagenerationNotMatch(24L));
618+
try {
619+
bucket.create(
620+
"n",
621+
streamContent,
622+
CONTENT_TYPE,
623+
Bucket.BlobWriteOption.metagenerationMatch(42L),
624+
Bucket.BlobWriteOption.metagenerationNotMatch(24L));
625+
Assert.fail();
626+
} catch (IllegalArgumentException ex) {
627+
assertNotNull(ex.getMessage());
628+
}
623629
}
624630

625631
@Test

google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java

+19-13
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@
8686
import org.easymock.Capture;
8787
import org.easymock.EasyMock;
8888
import org.junit.After;
89+
import org.junit.Assert;
8990
import org.junit.Before;
9091
import org.junit.BeforeClass;
91-
import org.junit.Rule;
9292
import org.junit.Test;
93-
import org.junit.rules.ExpectedException;
9493

9594
public class StorageImplTest {
9695

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

387-
@Rule public ExpectedException thrown = ExpectedException.none();
388-
389386
@BeforeClass
390387
public static void beforeClass() throws NoSuchAlgorithmException, InvalidKeySpecException {
391388
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
@@ -785,9 +782,12 @@ public void testCreateBlobFromStreamRetryableException() throws IOException {
785782

786783
// Even though this exception is retryable, storage.create(BlobInfo, InputStream)
787784
// shouldn't retry.
788-
thrown.expect(StorageException.class);
789-
thrown.expectMessage("internalError");
790-
storage.create(infoWithHashes, fileStream);
785+
try {
786+
storage.create(infoWithHashes, fileStream);
787+
Assert.fail();
788+
} catch (StorageException ex) {
789+
assertNotNull(ex.getMessage());
790+
}
791791
}
792792

793793
@Test
@@ -2973,9 +2973,12 @@ public void testNonRetryableException() {
29732973
.build()
29742974
.getService();
29752975
initializeServiceDependentObjects();
2976-
thrown.expect(StorageException.class);
2977-
thrown.expectMessage(exceptionMessage);
2978-
storage.get(blob);
2976+
try {
2977+
storage.get(blob);
2978+
Assert.fail();
2979+
} catch (StorageException ex) {
2980+
Assert.assertNotNull(ex.getMessage());
2981+
}
29792982
}
29802983

29812984
@Test
@@ -2991,9 +2994,12 @@ public void testRuntimeException() {
29912994
.setRetrySettings(ServiceOptions.getDefaultRetrySettings())
29922995
.build()
29932996
.getService();
2994-
thrown.expect(StorageException.class);
2995-
thrown.expectMessage(exceptionMessage);
2996-
storage.get(blob);
2997+
try {
2998+
storage.get(blob);
2999+
Assert.fail();
3000+
} catch (StorageException ex) {
3001+
Assert.assertNotNull(ex.getMessage());
3002+
}
29973003
}
29983004

29993005
@Test

google-cloud-storage/src/test/java/com/google/cloud/storage/StorageOptionsTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public void testInvalidTransport() {
2929
StorageOptions.newBuilder()
3030
.setTransportOptions(EasyMock.<TransportOptions>createMock(TransportOptions.class));
3131
Assert.fail();
32-
} catch (IllegalArgumentException expected) {
32+
} catch (IllegalArgumentException ex) {
33+
Assert.assertNotNull(ex.getMessage());
3334
}
3435
}
3536
}

google-cloud-storage/src/test/java/com/google/cloud/storage/testing/RemoteStorageHelperTest.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNotNull;
2122
import static org.junit.Assert.assertTrue;
2223

2324
import com.google.api.gax.paging.Page;
@@ -37,10 +38,9 @@
3738
import java.util.concurrent.ExecutionException;
3839
import java.util.concurrent.TimeUnit;
3940
import org.easymock.EasyMock;
41+
import org.junit.Assert;
4042
import org.junit.Before;
41-
import org.junit.Rule;
4243
import org.junit.Test;
43-
import org.junit.rules.ExpectedException;
4444
import org.threeten.bp.Duration;
4545

4646
public class RemoteStorageHelperTest {
@@ -86,8 +86,6 @@ public class RemoteStorageHelperTest {
8686
private List<Blob> blobList;
8787
private Page<Blob> blobPage;
8888

89-
@Rule public ExpectedException thrown = ExpectedException.none();
90-
9189
@Before
9290
public void setUp() {
9391
blob1 = EasyMock.createMock(Blob.class);
@@ -175,9 +173,11 @@ public void testForceDeleteFail() throws InterruptedException, ExecutionExceptio
175173
.andReturn(blobPage);
176174
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(FATAL_EXCEPTION);
177175
EasyMock.replay(storageMock, blob1, blob2);
178-
thrown.expect(ExecutionException.class);
179176
try {
180177
RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME, 5, TimeUnit.SECONDS);
178+
Assert.fail();
179+
} catch (ExecutionException ex) {
180+
assertNotNull(ex.getMessage());
181181
} finally {
182182
EasyMock.verify(storageMock);
183183
}
@@ -213,9 +213,11 @@ public void testForceDeleteNoTimeoutFail() {
213213
.andReturn(blobPage);
214214
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(FATAL_EXCEPTION);
215215
EasyMock.replay(storageMock, blob1, blob2);
216-
thrown.expect(StorageException.class);
217216
try {
218217
RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME);
218+
Assert.fail();
219+
} catch (StorageException ex) {
220+
assertNotNull(ex.getMessage());
219221
} finally {
220222
EasyMock.verify(storageMock);
221223
}

0 commit comments

Comments
 (0)