1- /**
1+ /*
22 * Copyright 2015 Google Inc. All Rights Reserved.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
1616
1717// [START all]
1818
19- import static org . junit . Assert .* ;
19+ import static com . google . common . truth . Truth . assertThat ;
2020
2121import com .google .api .services .storage .model .Bucket ;
2222import com .google .api .services .storage .model .StorageObject ;
2323
2424import org .junit .Test ;
2525
26- import java .util .List ;
27- import java .util .regex .Pattern ;
2826import java .io .ByteArrayInputStream ;
27+ import java .util .List ;
28+ import java .util .stream .Collectors ;
2929
3030public class StorageSampleTest {
3131 private static final String BUCKET = "cloud-samples-tests" ;
@@ -34,49 +34,37 @@ public class StorageSampleTest {
3434 @ Test
3535 public void testListBucket () throws Exception {
3636 List <StorageObject > listing = StorageSample .listBucket (BUCKET );
37- assertTrue (listing . size () > 0 );
37+ assertThat (listing ). isNotEmpty ( );
3838 }
3939
4040 @ Test
4141 public void testGetBucket () throws Exception {
4242 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" );
4545 }
4646
4747 @ Test
4848 public void testUploadDelete () throws Exception {
4949 StorageSample .uploadStream (
5050 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 "
5253 + "StorageSampleTest integration test." ).getBytes ()),
5354 BUCKET );
5455
5556 try {
5657 // Verify that the object was created
5758 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 );
6761 } finally {
6862 StorageSample .deleteObject (TEST_OBJECT , BUCKET );
6963
7064 // Verify that the object no longer exists
7165 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 );
8068 }
8169 }
8270}
0 commit comments