1
- /**
1
+ /*
2
2
* Copyright 2015 Google Inc. All Rights Reserved.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
16
16
17
17
// [START all]
18
18
19
- import static org . junit . Assert .* ;
19
+ import static com . google . common . truth . Truth . assertThat ;
20
20
21
21
import com .google .api .services .storage .model .Bucket ;
22
22
import com .google .api .services .storage .model .StorageObject ;
23
23
24
24
import org .junit .Test ;
25
25
26
- import java .util .List ;
27
- import java .util .regex .Pattern ;
28
26
import java .io .ByteArrayInputStream ;
27
+ import java .util .List ;
28
+ import java .util .stream .Collectors ;
29
29
30
30
public class StorageSampleTest {
31
31
private static final String BUCKET = "cloud-samples-tests" ;
@@ -34,49 +34,37 @@ public class StorageSampleTest {
34
34
@ Test
35
35
public void testListBucket () throws Exception {
36
36
List <StorageObject > listing = StorageSample .listBucket (BUCKET );
37
- assertTrue (listing . size () > 0 );
37
+ assertThat (listing ). isNotEmpty ( );
38
38
}
39
39
40
40
@ Test
41
41
public void testGetBucket () throws Exception {
42
42
Bucket bucket = StorageSample .getBucket (BUCKET );
43
- assertEquals (bucket .getName (), BUCKET );
44
- assertEquals (bucket .getLocation (), "US-CENTRAL1" );
43
+ assertThat (bucket .getName ()). named ( "bucket name" ). isEqualTo ( BUCKET );
44
+ assertThat (bucket .getLocation ()). named ( "bucket location" ). isEqualTo ( "US-CENTRAL1" );
45
45
}
46
46
47
47
@ Test
48
48
public void testUploadDelete () throws Exception {
49
49
StorageSample .uploadStream (
50
50
TEST_OBJECT , "text/plain" ,
51
- new ByteArrayInputStream (("This object is uploaded and deleted as part of the "
51
+ new ByteArrayInputStream (
52
+ ("This object is uploaded and deleted as part of the "
52
53
+ "StorageSampleTest integration test." ).getBytes ()),
53
54
BUCKET );
54
55
55
56
try {
56
57
// Verify that the object was created
57
58
List <StorageObject > listing = StorageSample .listBucket (BUCKET );
58
- boolean found = false ;
59
- for (StorageObject so : listing ) {
60
- if (TEST_OBJECT .equals (so .getName ())) {
61
- found = true ;
62
- break ;
63
- }
64
- }
65
- assertTrue ("Should have uploaded successfully" , found );
66
-
59
+ List <String > names = listing .stream ().map (so -> so .getName ()).collect (Collectors .toList ());
60
+ assertThat (names ).named ("objects found after upload" ).contains (TEST_OBJECT );
67
61
} finally {
68
62
StorageSample .deleteObject (TEST_OBJECT , BUCKET );
69
63
70
64
// Verify that the object no longer exists
71
65
List <StorageObject > listing = StorageSample .listBucket (BUCKET );
72
- boolean found = false ;
73
- for (StorageObject so : listing ) {
74
- if (TEST_OBJECT .equals (so .getName ())) {
75
- found = true ;
76
- break ;
77
- }
78
- }
79
- assertFalse ("Object (" + TEST_OBJECT + ") should have been deleted" , found );
66
+ List <String > names = listing .stream ().map (so -> so .getName ()).collect (Collectors .toList ());
67
+ assertThat (names ).named ("objects found after delete" ).doesNotContain (TEST_OBJECT );
80
68
}
81
69
}
82
70
}
0 commit comments