24
24
import static org .easymock .EasyMock .verify ;
25
25
import static org .junit .Assert .assertEquals ;
26
26
import static org .junit .Assert .assertFalse ;
27
+ import static org .junit .Assert .assertNotNull ;
27
28
import static org .junit .Assert .assertNull ;
28
29
import static org .junit .Assert .assertTrue ;
29
30
52
53
import java .util .Map ;
53
54
import javax .crypto .spec .SecretKeySpec ;
54
55
import org .junit .After ;
56
+ import org .junit .Assert ;
55
57
import org .junit .Before ;
56
- import org .junit .Rule ;
57
58
import org .junit .Test ;
58
- import org .junit .rules .ExpectedException ;
59
59
60
60
public class BucketTest {
61
61
@@ -135,8 +135,6 @@ public class BucketTest {
135
135
private Bucket expectedBucket ;
136
136
private List <Blob > blobResults ;
137
137
138
- @ Rule public ExpectedException thrown = ExpectedException .none ();
139
-
140
138
@ Before
141
139
public void setUp () {
142
140
storage = createStrictMock (Storage .class );
@@ -446,15 +444,17 @@ public void testCreateWithWrongGenerationOptions() throws Exception {
446
444
replay (storage );
447
445
initializeBucket ();
448
446
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
+ }
458
458
}
459
459
460
460
@ Test
@@ -464,15 +464,17 @@ public void testCreateWithWrongMetagenerationOptions() throws Exception {
464
464
replay (storage );
465
465
initializeBucket ();
466
466
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
+ }
476
478
}
477
479
478
480
@ Test
@@ -592,15 +594,17 @@ public void testCreateFromStreamWithWrongGenerationOptions() throws Exception {
592
594
initializeBucket ();
593
595
byte [] content = {0xD , 0xE , 0xA , 0xD };
594
596
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
+ }
604
608
}
605
609
606
610
@ Test
@@ -611,15 +615,17 @@ public void testCreateFromStreamWithWrongMetagenerationOptions() throws Exceptio
611
615
initializeBucket ();
612
616
byte [] content = {0xD , 0xE , 0xA , 0xD };
613
617
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
+ }
623
629
}
624
630
625
631
@ Test
0 commit comments