Skip to content

Commit de74963

Browse files
committed
Merge pull request #104 from GoogleCloudPlatform/aesdk
Fix checkstyle errors in BigQuery sample tests.
2 parents b9d0517 + 565e7ee commit de74963

10 files changed

+236
-173
lines changed

bigquery/pom.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@
5151
<scope>test</scope>
5252
</dependency>
5353
<dependency>
54-
<groupId>com.jcabi</groupId>
55-
<artifactId>jcabi-matchers</artifactId>
54+
<groupId>com.google.truth</groupId>
55+
<artifactId>truth</artifactId>
56+
<version>0.28</version>
5657
<scope>test</scope>
5758
</dependency>
5859
</dependencies>

bigquery/src/main/resources/constants.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"datasetId": "test_dataset_java",
44
"currentTableId": "test_table_java",
55
"newTableId": "test_table_java_2",
6-
"cloudStorageInputURI": "gs://cloud-samples-tests/data.csv",
7-
"cloudStorageOutputURI": "gs://cloud-samples-tests/output.csv",
6+
"cloudStorageInputUri": "gs://cloud-samples-tests/data.csv",
7+
"cloudStorageOutputUri": "gs://cloud-samples-tests/output.csv",
88
"query": "SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus;"
99
}
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,60 @@
1+
/*
2+
* Copyright (c) 2015 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
* not use this file except in compliance with the License. You may obtain a
6+
* copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
117
package com.google.cloud.bigquery.samples.test;
218

19+
import static com.google.common.truth.Truth.assertThat;
20+
321
import com.google.api.services.bigquery.model.GetQueryResultsResponse;
422
import com.google.cloud.bigquery.samples.AsyncQuerySample;
523
import com.google.gson.JsonIOException;
624
import com.google.gson.JsonSyntaxException;
725

8-
import org.junit.*;
9-
10-
import static org.junit.Assert.*;
26+
import org.junit.Ignore;
27+
import org.junit.Test;
1128

1229
import java.io.FileNotFoundException;
1330
import java.io.IOException;
1431
import java.util.Iterator;
1532

33+
/**
34+
* Tests for asynchronous query sample.
35+
*/
1636
public class AsyncQuerySampleTest extends BigquerySampleTest{
1737

18-
/**
19-
* @throws JsonSyntaxException
20-
* @throws JsonIOException
21-
* @throws FileNotFoundException
22-
*/
23-
public AsyncQuerySampleTest() throws JsonSyntaxException, JsonIOException,
24-
FileNotFoundException {
38+
public AsyncQuerySampleTest() throws JsonSyntaxException, JsonIOException, FileNotFoundException {
2539
super();
26-
// TODO(elibixby): Auto-generated constructor stub
2740
}
2841

29-
3042
@Test
31-
public void testInteractive() throws IOException, InterruptedException{
32-
Iterator<GetQueryResultsResponse> pages = AsyncQuerySample.run(CONSTANTS.getProjectId(), CONSTANTS.getQuery(), false, 5000);
33-
while(pages.hasNext()){
34-
assertTrue(!pages.next().getRows().isEmpty());
43+
public void testInteractive() throws IOException, InterruptedException {
44+
Iterator<GetQueryResultsResponse> pages =
45+
AsyncQuerySample.run(CONSTANTS.getProjectId(), CONSTANTS.getQuery(), false, 5000);
46+
while (pages.hasNext()) {
47+
assertThat(pages.next().getRows()).isNotEmpty();
3548
}
3649
}
37-
38-
50+
3951
@Test
4052
@Ignore // Batches can take up to 3 hours to run, probably shouldn't use this
41-
public void testBatch() throws IOException, InterruptedException{
42-
Iterator<GetQueryResultsResponse> pages = AsyncQuerySample.run(CONSTANTS.getProjectId(), CONSTANTS.getQuery(), true, 5000);
43-
while(pages.hasNext()){
44-
assertTrue(!pages.next().getRows().isEmpty());
53+
public void testBatch() throws IOException, InterruptedException {
54+
Iterator<GetQueryResultsResponse> pages =
55+
AsyncQuerySample.run(CONSTANTS.getProjectId(), CONSTANTS.getQuery(), true, 5000);
56+
while (pages.hasNext()) {
57+
assertThat(pages.next().getRows()).isNotEmpty();
4558
}
4659
}
47-
48-
4960
}
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,81 @@
1+
/*
2+
* Copyright (c) 2015 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
* not use this file except in compliance with the License. You may obtain a
6+
* copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
117
package com.google.cloud.bigquery.samples.test;
218

319
import com.google.cloud.bigquery.samples.BigqueryUtils;
420
import com.google.gson.Gson;
521
import com.google.gson.JsonIOException;
622
import com.google.gson.JsonSyntaxException;
723

8-
import java.io.*;
9-
import java.nio.file.Path;
10-
import java.nio.file.Paths;
11-
24+
import java.io.FileNotFoundException;
25+
import java.io.InputStream;
26+
import java.io.InputStreamReader;
1227

1328
/**
14-
* TODO: Insert description here. (generated by elibixby)
29+
* Superclass for tests for samples.
1530
*/
1631
public class BigquerySampleTest extends BigqueryUtils {
1732

18-
protected static class Constants{
33+
protected static class Constants {
1934
private String projectId;
2035
private String datasetId;
2136
private String currentTableId;
2237
private String newTableId;
23-
private String cloudStorageInputURI;
24-
private String cloudStorageOutputURI;
38+
private String cloudStorageInputUri;
39+
private String cloudStorageOutputUri;
2540
private String query;
26-
/**
27-
* @return the projectId
28-
*/
41+
2942
public String getProjectId() {
3043
return projectId;
3144
}
32-
/**
33-
* @return the datasetId
34-
*/
45+
3546
public String getDatasetId() {
3647
return datasetId;
3748
}
38-
/**
39-
* @return the currentTableId
40-
*/
49+
4150
public String getCurrentTableId() {
4251
return currentTableId;
4352
}
44-
/**
45-
* @return the newTableId
46-
*/
53+
4754
public String getNewTableId() {
4855
return newTableId;
4956
}
50-
/**
51-
* @return the query
52-
*/
57+
5358
public String getQuery() {
5459
return query;
5560
}
56-
/**
57-
* @return the cloudStorageOutputURI
58-
*/
59-
public String getCloudStorageOutputURI() {
60-
return cloudStorageOutputURI;
61+
62+
public String getCloudStorageOutputUri() {
63+
return cloudStorageOutputUri;
6164
}
62-
/**
63-
* @return the cloudStorageInputURI
64-
*/
65-
public String getCloudStorageInputURI() {
66-
return cloudStorageInputURI;
65+
66+
public String getCloudStorageInputUri() {
67+
return cloudStorageInputUri;
6768
}
6869
}
6970

70-
protected static Constants CONSTANTS = null ;
71+
@SuppressWarnings("checkstyle:abbreviationaswordinname")
72+
protected static Constants CONSTANTS = null;
7173

72-
protected BigquerySampleTest() throws JsonSyntaxException, JsonIOException, FileNotFoundException{
73-
if(CONSTANTS == null){
74-
InputStream is = this.getClass().getResourceAsStream
75-
("/constants.json");
76-
CONSTANTS = (new Gson()).<Constants>fromJson(
77-
new InputStreamReader(is),
78-
Constants.class);
74+
protected BigquerySampleTest()
75+
throws JsonSyntaxException, JsonIOException, FileNotFoundException {
76+
if (CONSTANTS == null) {
77+
InputStream is = this.getClass().getResourceAsStream("/constants.json");
78+
CONSTANTS = (new Gson()).<Constants>fromJson(new InputStreamReader(is), Constants.class);
7979
}
8080
}
81-
82-
83-
8481
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2015 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
* not use this file except in compliance with the License. You may obtain a
6+
* copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
117
package com.google.cloud.bigquery.samples.test;
218

319
import com.google.cloud.bigquery.samples.ExportDataCloudStorageSample;
@@ -10,29 +26,22 @@
1026
import java.io.IOException;
1127

1228
/**
13-
* TODO: Insert description here. (generated by elibixby)
29+
* Tests for export data Cloud Storage sample.
1430
*/
1531
public class ExportDataCloudStorageSampleTest extends BigquerySampleTest {
1632

17-
/**
18-
* @throws JsonSyntaxException
19-
* @throws JsonIOException
20-
* @throws FileNotFoundException
21-
*/
22-
public ExportDataCloudStorageSampleTest() throws JsonSyntaxException, JsonIOException,
23-
FileNotFoundException {
33+
public ExportDataCloudStorageSampleTest()
34+
throws JsonSyntaxException, JsonIOException, FileNotFoundException {
2435
super();
2536
}
26-
37+
2738
@Test
28-
public void testExportData() throws IOException, InterruptedException{
29-
ExportDataCloudStorageSample.run(CONSTANTS.getCloudStorageOutputURI(),
39+
public void testExportData() throws IOException, InterruptedException {
40+
ExportDataCloudStorageSample.run(
41+
CONSTANTS.getCloudStorageOutputUri(),
3042
CONSTANTS.getProjectId(),
3143
CONSTANTS.getDatasetId(),
3244
CONSTANTS.getCurrentTableId(),
3345
5000L);
3446
}
35-
36-
37-
3847
}
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,45 @@
1+
/*
2+
* Copyright (c) 2015 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
* not use this file except in compliance with the License. You may obtain a
6+
* copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
117
package com.google.cloud.bigquery.samples.test;
218

3-
import com.google.api.services.bigquery.model.GetQueryResultsResponse;
19+
import static com.google.common.truth.Truth.assertThat;
20+
421
import com.google.cloud.bigquery.samples.GettingStarted;
5-
import com.google.gson.JsonIOException;
6-
import com.google.gson.JsonSyntaxException;
722

823
import org.junit.After;
924
import org.junit.Before;
1025
import org.junit.Test;
11-
import org.junit.Test;
12-
13-
import static com.jcabi.matchers.RegexMatchers.*;
14-
import static org.junit.Assert.*;
15-
import static org.junit.matchers.JUnitMatchers.*;
1626

1727
import java.io.ByteArrayOutputStream;
1828
import java.io.FileNotFoundException;
1929
import java.io.IOException;
2030
import java.io.PrintStream;
21-
import java.util.Iterator;
2231

2332

2433
/**
2534
* Test for GettingStarted.java
2635
*/
2736
public class GettingStartedTest extends BigquerySampleTest {
28-
private final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
29-
private final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
3037
private static final PrintStream REAL_OUT = System.out;
3138
private static final PrintStream REAL_ERR = System.err;
3239

40+
private final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
41+
private final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
42+
3343
public GettingStartedTest() throws FileNotFoundException {
3444
super();
3545
}
@@ -50,7 +60,7 @@ public void tearDown() {
5060
public void testSyncQuery() throws IOException {
5161
GettingStarted.main(new String[] { CONSTANTS.getProjectId() });
5262
String out = stdout.toString();
53-
assertThat(out, containsPattern("Query Results:"));
54-
assertThat(out, containsString("hamlet"));
63+
assertThat(out).named("stdout").containsMatch("Query Results:");
64+
assertThat(out).named("stdout").contains("hamlet");
5565
}
5666
}

0 commit comments

Comments
 (0)