From fb81ca8bd79a6dcc36a2c57754554eb0c790474b Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Fri, 4 Mar 2016 13:54:14 -0800 Subject: [PATCH] Fix checkstyle errors in BigQuery sample tests. --- bigquery/pom.xml | 5 +- .../samples/test/AsyncQuerySampleTest.java | 59 +++++++------ .../samples/test/BigquerySampleTest.java | 83 +++++++++---------- .../ExportDataCloudStorageSampleTest.java | 37 +++++---- .../samples/test/GettingStartedTest.java | 36 +++++--- .../test/ListDatasetsProjectsTest.java | 36 ++++---- .../samples/test/LoadDataCsvSampleTest.java | 42 ++++++---- .../samples/test/StreamingSampleTest.java | 57 ++++++++----- .../samples/test/SyncQuerySampleTest.java | 46 ++++++---- 9 files changed, 233 insertions(+), 168 deletions(-) diff --git a/bigquery/pom.xml b/bigquery/pom.xml index df882ba47f3..6973a0bebc5 100644 --- a/bigquery/pom.xml +++ b/bigquery/pom.xml @@ -51,8 +51,9 @@ test - com.jcabi - jcabi-matchers + com.google.truth + truth + 0.28 test diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/AsyncQuerySampleTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/AsyncQuerySampleTest.java index 49a6735bf94..c6c886034b4 100644 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/AsyncQuerySampleTest.java +++ b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/AsyncQuerySampleTest.java @@ -1,49 +1,60 @@ +/* + * Copyright (c) 2015 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + package com.google.cloud.bigquery.samples.test; +import static com.google.common.truth.Truth.assertThat; + import com.google.api.services.bigquery.model.GetQueryResultsResponse; import com.google.cloud.bigquery.samples.AsyncQuerySample; import com.google.gson.JsonIOException; import com.google.gson.JsonSyntaxException; -import org.junit.*; - -import static org.junit.Assert.*; +import org.junit.Ignore; +import org.junit.Test; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Iterator; +/** + * Tests for asynchronous query sample. + */ public class AsyncQuerySampleTest extends BigquerySampleTest{ - /** - * @throws JsonSyntaxException - * @throws JsonIOException - * @throws FileNotFoundException - */ - public AsyncQuerySampleTest() throws JsonSyntaxException, JsonIOException, - FileNotFoundException { + public AsyncQuerySampleTest() throws JsonSyntaxException, JsonIOException, FileNotFoundException { super(); - // TODO(elibixby): Auto-generated constructor stub } - @Test - public void testInteractive() throws IOException, InterruptedException{ - Iterator pages = AsyncQuerySample.run(CONSTANTS.getProjectId(), CONSTANTS.getQuery(), false, 5000); - while(pages.hasNext()){ - assertTrue(!pages.next().getRows().isEmpty()); + public void testInteractive() throws IOException, InterruptedException { + Iterator pages = + AsyncQuerySample.run(CONSTANTS.getProjectId(), CONSTANTS.getQuery(), false, 5000); + while (pages.hasNext()) { + assertThat(pages.next().getRows()).isNotEmpty(); } } - - + @Test @Ignore // Batches can take up to 3 hours to run, probably shouldn't use this - public void testBatch() throws IOException, InterruptedException{ - Iterator pages = AsyncQuerySample.run(CONSTANTS.getProjectId(), CONSTANTS.getQuery(), true, 5000); - while(pages.hasNext()){ - assertTrue(!pages.next().getRows().isEmpty()); + public void testBatch() throws IOException, InterruptedException { + Iterator pages = + AsyncQuerySample.run(CONSTANTS.getProjectId(), CONSTANTS.getQuery(), true, 5000); + while (pages.hasNext()) { + assertThat(pages.next().getRows()).isNotEmpty(); } } - - } diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/BigquerySampleTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/BigquerySampleTest.java index 80bb05ae491..e1685964460 100644 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/BigquerySampleTest.java +++ b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/BigquerySampleTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2015 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + package com.google.cloud.bigquery.samples.test; import com.google.cloud.bigquery.samples.BigqueryUtils; @@ -5,80 +21,63 @@ import com.google.gson.JsonIOException; import com.google.gson.JsonSyntaxException; -import java.io.*; -import java.nio.file.Path; -import java.nio.file.Paths; - +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.InputStreamReader; /** - * TODO: Insert description here. (generated by elibixby) + * Superclass for tests for samples. */ public class BigquerySampleTest extends BigqueryUtils { - protected static class Constants{ + protected static class Constants { private String projectId; private String datasetId; private String currentTableId; private String newTableId; - private String cloudStorageInputURI; - private String cloudStorageOutputURI; + private String cloudStorageInputUri; + private String cloudStorageOutputUri; private String query; - /** - * @return the projectId - */ + public String getProjectId() { return projectId; } - /** - * @return the datasetId - */ + public String getDatasetId() { return datasetId; } - /** - * @return the currentTableId - */ + public String getCurrentTableId() { return currentTableId; } - /** - * @return the newTableId - */ + public String getNewTableId() { return newTableId; } - /** - * @return the query - */ + public String getQuery() { return query; } - /** - * @return the cloudStorageOutputURI - */ + + @SuppressWarnings("checkstyle:abbreviationaswordinname") public String getCloudStorageOutputURI() { - return cloudStorageOutputURI; + return cloudStorageOutputUri; } - /** - * @return the cloudStorageInputURI - */ + + @SuppressWarnings("checkstyle:abbreviationaswordinname") public String getCloudStorageInputURI() { - return cloudStorageInputURI; + return cloudStorageInputUri; } } - protected static Constants CONSTANTS = null ; + @SuppressWarnings("checkstyle:abbreviationaswordinname") + protected static Constants CONSTANTS = null; - protected BigquerySampleTest() throws JsonSyntaxException, JsonIOException, FileNotFoundException{ - if(CONSTANTS == null){ - InputStream is = this.getClass().getResourceAsStream - ("/constants.json"); - CONSTANTS = (new Gson()).fromJson( - new InputStreamReader(is), - Constants.class); + protected BigquerySampleTest() + throws JsonSyntaxException, JsonIOException, FileNotFoundException { + if (CONSTANTS == null) { + InputStream is = this.getClass().getResourceAsStream("/constants.json"); + CONSTANTS = (new Gson()).fromJson(new InputStreamReader(is), Constants.class); } } - - - } diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ExportDataCloudStorageSampleTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ExportDataCloudStorageSampleTest.java index 0c43f7e32c5..b496684783f 100644 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ExportDataCloudStorageSampleTest.java +++ b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ExportDataCloudStorageSampleTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2015 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + package com.google.cloud.bigquery.samples.test; import com.google.cloud.bigquery.samples.ExportDataCloudStorageSample; @@ -10,29 +26,22 @@ import java.io.IOException; /** - * TODO: Insert description here. (generated by elibixby) + * Tests for export data Cloud Storage sample. */ public class ExportDataCloudStorageSampleTest extends BigquerySampleTest { - /** - * @throws JsonSyntaxException - * @throws JsonIOException - * @throws FileNotFoundException - */ - public ExportDataCloudStorageSampleTest() throws JsonSyntaxException, JsonIOException, - FileNotFoundException { + public ExportDataCloudStorageSampleTest() + throws JsonSyntaxException, JsonIOException, FileNotFoundException { super(); } - + @Test - public void testExportData() throws IOException, InterruptedException{ - ExportDataCloudStorageSample.run(CONSTANTS.getCloudStorageOutputURI(), + public void testExportData() throws IOException, InterruptedException { + ExportDataCloudStorageSample.run( + CONSTANTS.getCloudStorageOutputURI(), CONSTANTS.getProjectId(), CONSTANTS.getDatasetId(), CONSTANTS.getCurrentTableId(), 5000L); } - - - } diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/GettingStartedTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/GettingStartedTest.java index 6868302c169..0f688239cee 100644 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/GettingStartedTest.java +++ b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/GettingStartedTest.java @@ -1,35 +1,45 @@ +/* + * Copyright (c) 2015 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + package com.google.cloud.bigquery.samples.test; -import com.google.api.services.bigquery.model.GetQueryResultsResponse; +import static com.google.common.truth.Truth.assertThat; + import com.google.cloud.bigquery.samples.GettingStarted; -import com.google.gson.JsonIOException; -import com.google.gson.JsonSyntaxException; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.junit.Test; - -import static com.jcabi.matchers.RegexMatchers.*; -import static org.junit.Assert.*; -import static org.junit.matchers.JUnitMatchers.*; import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; -import java.util.Iterator; /** * Test for GettingStarted.java */ public class GettingStartedTest extends BigquerySampleTest { - private final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); - private final ByteArrayOutputStream stderr = new ByteArrayOutputStream(); private static final PrintStream REAL_OUT = System.out; private static final PrintStream REAL_ERR = System.err; + private final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); + private final ByteArrayOutputStream stderr = new ByteArrayOutputStream(); + public GettingStartedTest() throws FileNotFoundException { super(); } @@ -50,7 +60,7 @@ public void tearDown() { public void testSyncQuery() throws IOException { GettingStarted.main(new String[] { CONSTANTS.getProjectId() }); String out = stdout.toString(); - assertThat(out, containsPattern("Query Results:")); - assertThat(out, containsString("hamlet")); + assertThat(out).named("stdout").containsMatch("Query Results:"); + assertThat(out).named("stdout").contains("hamlet"); } } diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ListDatasetsProjectsTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ListDatasetsProjectsTest.java index 354f7913579..d4ebaeac2b9 100644 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ListDatasetsProjectsTest.java +++ b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ListDatasetsProjectsTest.java @@ -16,9 +16,7 @@ package com.google.cloud.bigquery.samples.test; -import static com.jcabi.matchers.RegexMatchers.*; -import static org.junit.Assert.*; -import static org.junit.matchers.JUnitMatchers.*; +import static com.google.common.truth.Truth.assertThat; import com.google.cloud.bigquery.samples.ListDatasetsProjects; @@ -31,18 +29,20 @@ import java.io.PrintStream; import java.lang.Exception; -/** Unit tests for {@link ListDatasetsProjects}. */ +/** + * Unit tests for {@link ListDatasetsProjects}. + */ public class ListDatasetsProjectsTest extends BigquerySampleTest { + private static final PrintStream REAL_OUT = System.out; + private static final PrintStream REAL_ERR = System.err; + + private final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); + private final ByteArrayOutputStream stderr = new ByteArrayOutputStream(); public ListDatasetsProjectsTest() throws FileNotFoundException { super(); } - private final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); - private final ByteArrayOutputStream stderr = new ByteArrayOutputStream(); - private static final PrintStream REAL_OUT = System.out; - private static final PrintStream REAL_ERR = System.err; - @Before public void setUp() { System.setOut(new PrintStream(stdout)); @@ -58,22 +58,22 @@ public void tearDown() { @Test public void testUsage() throws Exception { ListDatasetsProjects.main(new String[] {}); - assertEquals("Usage: QuickStart \n", stderr.toString()); + assertThat(stderr.toString()).named("stderr").isEqualTo("Usage: QuickStart \n"); } @Test public void testMain() throws Exception { ListDatasetsProjects.main(new String[] { CONSTANTS.getProjectId() }); String out = stdout.toString(); - assertThat(out, containsString("Running the asynchronous query")); - assertThat(out, containsPattern("George W. Bush, [0-9]+")); - assertThat(out, containsPattern("Wikipedia, [0-9]+")); + assertThat(out).named("stdout").contains("Running the asynchronous query"); + assertThat(out).named("stdout").containsMatch("George W. Bush, [0-9]+"); + assertThat(out).named("stdout").containsMatch("Wikipedia, [0-9]+"); - assertThat(out, containsString("Listing all the Datasets")); - assertThat(out, containsString("test_dataset")); + assertThat(out).named("stdout").contains("Listing all the Datasets"); + assertThat(out).named("stdout").contains("test_dataset"); - assertThat(out, containsString("Listing all the Projects")); - assertThat(out, containsString("Project list:")); - assertThat(out, containsPattern("Bigquery Samples|cloud-samples-tests")); + assertThat(out).named("stdout").contains("Listing all the Projects"); + assertThat(out).named("stdout").contains("Project list:"); + assertThat(out).named("stdout").containsMatch("Bigquery Samples|cloud-samples-tests"); } } diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/LoadDataCsvSampleTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/LoadDataCsvSampleTest.java index 837d1ad8462..eb5c2d00da4 100644 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/LoadDataCsvSampleTest.java +++ b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/LoadDataCsvSampleTest.java @@ -1,39 +1,51 @@ +/* + * Copyright (c) 2015 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + package com.google.cloud.bigquery.samples.test; +import com.google.cloud.bigquery.samples.LoadDataCsvSample; import com.google.gson.JsonIOException; import com.google.gson.JsonSyntaxException; -import com.google.cloud.bigquery.samples.LoadDataCsvSample; import org.junit.Test; -import java.io.*; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; /** - * TODO: Insert description here. (generated by elibixby) + * Tests for sample that loads data from CSV. */ public class LoadDataCsvSampleTest extends BigquerySampleTest { - /** - * @throws JsonSyntaxException - * @throws JsonIOException - * @throws FileNotFoundException - */ - public LoadDataCsvSampleTest() throws JsonSyntaxException, JsonIOException, FileNotFoundException { - // TODO(elibixby): Auto-generated constructor stub + public LoadDataCsvSampleTest() + throws JsonSyntaxException, JsonIOException, FileNotFoundException { super(); } @Test - public void testLoadData() throws IOException, InterruptedException{ - - InputStreamReader is = new InputStreamReader(LoadDataCsvSample - .class.getResourceAsStream("/schema.json")); + public void testLoadData() throws IOException, InterruptedException { + InputStreamReader is = + new InputStreamReader(LoadDataCsvSample.class.getResourceAsStream("/schema.json")); LoadDataCsvSample.run( CONSTANTS.getCloudStorageInputURI(), CONSTANTS.getProjectId(), CONSTANTS.getDatasetId(), CONSTANTS.getNewTableId(), - is , + is, 5000L); } diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/StreamingSampleTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/StreamingSampleTest.java index 4e1296a5884..b0624f23c01 100644 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/StreamingSampleTest.java +++ b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/StreamingSampleTest.java @@ -1,6 +1,22 @@ +/* + * Copyright (c) 2015 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + package com.google.cloud.bigquery.samples.test; -import static org.junit.Assert.*; +import static com.google.common.truth.Truth.assertThat; import com.google.api.services.bigquery.model.TableDataInsertAllResponse; import com.google.cloud.bigquery.samples.StreamingSample; @@ -10,38 +26,35 @@ import org.junit.Test; -import java.io.*; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.Iterator; /** - * TODO: Insert description here. (generated by elibixby) + * Tests for streaming sample. */ public class StreamingSampleTest extends BigquerySampleTest { - /** - * @throws JsonSyntaxException - * @throws JsonIOException - * @throws FileNotFoundException - */ public StreamingSampleTest() throws JsonSyntaxException, JsonIOException, FileNotFoundException { super(); } @Test - public void testStream() throws IOException{ - JsonReader json = new JsonReader( - new InputStreamReader(BigquerySampleTest - .class.getResourceAsStream("/streamrows.json"))); - Iterator response = StreamingSample.run( - CONSTANTS.getProjectId(), - CONSTANTS.getDatasetId(), - CONSTANTS.getCurrentTableId(), - json); - - while(response.hasNext()){ - assertTrue(!response.next().isEmpty()); + public void testStream() throws IOException { + JsonReader json = + new JsonReader( + new InputStreamReader( + BigquerySampleTest.class.getResourceAsStream("/streamrows.json"))); + Iterator response = + StreamingSample.run( + CONSTANTS.getProjectId(), + CONSTANTS.getDatasetId(), + CONSTANTS.getCurrentTableId(), + json); + + while (response.hasNext()) { + assertThat(response.next()).isNotEmpty(); } - } - } diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/SyncQuerySampleTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/SyncQuerySampleTest.java index c5bee385d4d..de52abb1f3d 100644 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/SyncQuerySampleTest.java +++ b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/SyncQuerySampleTest.java @@ -1,6 +1,22 @@ +/* + * Copyright (c) 2015 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + package com.google.cloud.bigquery.samples.test; -import static org.junit.Assert.*; +import static com.google.common.truth.Truth.assertThat; import com.google.api.services.bigquery.model.GetQueryResultsResponse; import com.google.cloud.bigquery.samples.SyncQuerySample; @@ -13,31 +29,25 @@ import java.io.IOException; import java.util.Iterator; - /** - * TODO: Insert description here. (generated by elibixby) + * Tests for synchronous query sample. */ public class SyncQuerySampleTest extends BigquerySampleTest { - /** - * @throws JsonSyntaxException - * @throws JsonIOException - * @throws FileNotFoundException - */ - public SyncQuerySampleTest() throws JsonSyntaxException, JsonIOException, - FileNotFoundException { + public SyncQuerySampleTest() + throws JsonSyntaxException, JsonIOException, FileNotFoundException { super(); } @Test - public void testSyncQuery() throws IOException{ - Iterator pages = SyncQuerySample.run( - CONSTANTS.getProjectId(), - CONSTANTS.getQuery(), - 10000); - while(pages.hasNext()){ - assertTrue(!pages.next().getRows().isEmpty()); + public void testSyncQuery() throws IOException { + Iterator pages = + SyncQuerySample.run( + CONSTANTS.getProjectId(), + CONSTANTS.getQuery(), + 10000); + while (pages.hasNext()) { + assertThat(pages.next().getRows()).isNotEmpty(); } } - }