Skip to content

Commit 14e393a

Browse files
committed
Merge pull request #109 from GoogleCloudPlatform/csstorage
Checkstyle fixes in Cloud Storage JSON API tests.
2 parents 90cb60f + d1857b0 commit 14e393a

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

storage/json-api/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
<artifactId>storage-json-sample</artifactId>
1313
<version>1</version>
1414
<name>Sample accessing the Google Cloud Storage JSON API using OAuth 2.0.</name>
15+
16+
<properties>
17+
<maven.compiler.target>1.8</maven.compiler.target>
18+
<maven.compiler.source>1.8</maven.compiler.source>
19+
</properties>
20+
1521
<build>
1622
<plugins>
1723
<plugin>
@@ -45,5 +51,11 @@
4551
<version>4.10</version>
4652
<scope>test</scope>
4753
</dependency>
54+
<dependency>
55+
<groupId>com.google.truth</groupId>
56+
<artifactId>truth</artifactId>
57+
<version>0.28</version>
58+
<scope>test</scope>
59+
</dependency>
4860
</dependencies>
4961
</project>

storage/json-api/src/test/java/StorageSampleTest.java

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2015 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,16 +16,16 @@
1616

1717
// [START all]
1818

19-
import static org.junit.Assert.*;
19+
import static com.google.common.truth.Truth.assertThat;
2020

2121
import com.google.api.services.storage.model.Bucket;
2222
import com.google.api.services.storage.model.StorageObject;
2323

2424
import org.junit.Test;
2525

26-
import java.util.List;
27-
import java.util.regex.Pattern;
2826
import java.io.ByteArrayInputStream;
27+
import java.util.List;
28+
import java.util.stream.Collectors;
2929

3030
public 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

Comments
 (0)