Skip to content

Checkstyle fixes in Cloud Storage JSON API tests. #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions storage/json-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<artifactId>storage-json-sample</artifactId>
<version>1</version>
<name>Sample accessing the Google Cloud Storage JSON API using OAuth 2.0.</name>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -45,5 +51,11 @@
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>0.28</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
38 changes: 13 additions & 25 deletions storage/json-api/src/test/java/StorageSampleTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,16 +16,16 @@

// [START all]

import static org.junit.Assert.*;
import static com.google.common.truth.Truth.assertThat;

import com.google.api.services.storage.model.Bucket;
import com.google.api.services.storage.model.StorageObject;

import org.junit.Test;

import java.util.List;
import java.util.regex.Pattern;
import java.io.ByteArrayInputStream;
import java.util.List;
import java.util.stream.Collectors;

public class StorageSampleTest {
private static final String BUCKET = "cloud-samples-tests";
Expand All @@ -34,49 +34,37 @@ public class StorageSampleTest {
@Test
public void testListBucket() throws Exception {
List<StorageObject> listing = StorageSample.listBucket(BUCKET);
assertTrue(listing.size() > 0);
assertThat(listing).isNotEmpty();
}

@Test
public void testGetBucket() throws Exception {
Bucket bucket = StorageSample.getBucket(BUCKET);
assertEquals(bucket.getName(), BUCKET);
assertEquals(bucket.getLocation(), "US-CENTRAL1");
assertThat(bucket.getName()).named("bucket name").isEqualTo(BUCKET);
assertThat(bucket.getLocation()).named("bucket location").isEqualTo("US-CENTRAL1");
}

@Test
public void testUploadDelete() throws Exception {
StorageSample.uploadStream(
TEST_OBJECT, "text/plain",
new ByteArrayInputStream(("This object is uploaded and deleted as part of the "
new ByteArrayInputStream(
("This object is uploaded and deleted as part of the "
+ "StorageSampleTest integration test.").getBytes()),
BUCKET);

try {
// Verify that the object was created
List<StorageObject> listing = StorageSample.listBucket(BUCKET);
boolean found = false;
for (StorageObject so : listing) {
if (TEST_OBJECT.equals(so.getName())) {
found = true;
break;
}
}
assertTrue("Should have uploaded successfully", found);

List<String> names = listing.stream().map(so -> so.getName()).collect(Collectors.toList());
assertThat(names).named("objects found after upload").contains(TEST_OBJECT);
} finally {
StorageSample.deleteObject(TEST_OBJECT, BUCKET);

// Verify that the object no longer exists
List<StorageObject> listing = StorageSample.listBucket(BUCKET);
boolean found = false;
for (StorageObject so : listing) {
if (TEST_OBJECT.equals(so.getName())) {
found = true;
break;
}
}
assertFalse("Object (" + TEST_OBJECT + ") should have been deleted", found);
List<String> names = listing.stream().map(so -> so.getName()).collect(Collectors.toList());
assertThat(names).named("objects found after delete").doesNotContain(TEST_OBJECT);
}
}
}
Expand Down