From 862048927729f386855268274d2564239f44923b Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Wed, 16 Mar 2016 11:42:57 -0700 Subject: [PATCH] Checkstyle fix for unittests samples. This requires an update to the documentation at https://cloud.google.com/appengine/docs/java/tools/localunittesting. I will ping a tech writer to restage after this merges. --- .../appengine/samples/AuthenticationTest.java | 8 +++--- .../appengine/samples/DeferredTaskTest.java | 8 +++--- ...LocalCustomPolicyHighRepDatastoreTest.java | 26 ++++++++++++------- .../appengine/samples/LocalDatastoreTest.java | 12 +++++---- .../samples/LocalHighRepDatastoreTest.java | 22 ++++++++++------ .../appengine/samples/LocalMemcacheTest.java | 13 +++++----- .../google/appengine/samples/MyFirstTest.java | 6 ++--- .../google/appengine/samples/OAuthTest.java | 8 +++--- .../google/appengine/samples/ShortTest.java | 11 ++++---- .../samples/TaskQueueConfigTest.java | 16 +++++++----- .../appengine/samples/TaskQueueTest.java | 13 +++++----- 11 files changed, 84 insertions(+), 59 deletions(-) diff --git a/unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java b/unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java index 4ba6bf1b8d7..5ef8f133693 100644 --- a/unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,20 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.appengine.samples; // [START AuthenticationTest] +import static org.junit.Assert.assertTrue; + import com.google.appengine.api.users.UserService; import com.google.appengine.api.users.UserServiceFactory; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; import com.google.appengine.tools.development.testing.LocalUserServiceTestConfig; + import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertTrue; - public class AuthenticationTest { private final LocalServiceTestHelper helper = diff --git a/unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java b/unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java index 661a9002605..d96bd974fe2 100644 --- a/unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,23 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.appengine.samples; // [START DeferredTaskTest] +import static org.junit.Assert.assertTrue; + import com.google.appengine.api.taskqueue.DeferredTask; import com.google.appengine.api.taskqueue.QueueFactory; import com.google.appengine.api.taskqueue.TaskOptions; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig; + import org.junit.After; import org.junit.Before; import org.junit.Test; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertTrue; - public class DeferredTaskTest { // Unlike CountDownLatch, TaskCountDownlatch lets us reset. diff --git a/unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java b/unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java index 03f96629c52..59246c5341b 100644 --- a/unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,21 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.appengine.samples; // [START LocalCustomPolicyHighRepDatastoreTest] -import com.google.appengine.api.datastore.*; +import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; +import static org.junit.Assert.assertEquals; + +import com.google.appengine.api.datastore.DatastoreService; +import com.google.appengine.api.datastore.DatastoreServiceFactory; +import com.google.appengine.api.datastore.Entity; +import com.google.appengine.api.datastore.Key; +import com.google.appengine.api.datastore.Query; import com.google.appengine.api.datastore.dev.HighRepJobPolicy; import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; + import org.junit.After; import org.junit.Before; import org.junit.Test; -import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; -import static org.junit.Assert.assertEquals; - public class LocalCustomPolicyHighRepDatastoreTest { private static final class CustomHighRepJobPolicy implements HighRepJobPolicy { static int newJobCounter = 0; @@ -35,13 +41,13 @@ private static final class CustomHighRepJobPolicy implements HighRepJobPolicy { @Override public boolean shouldApplyNewJob(Key entityGroup) { - // every other new job fails to apply + // Every other new job fails to apply. return newJobCounter++ % 2 == 0; } @Override public boolean shouldRollForwardExistingJob(Key entityGroup) { - // every other existing job fails to apply + // Every other existing job fails to apply. return existingJobCounter++ % 2 == 0; } } @@ -65,10 +71,10 @@ public void testEventuallyConsistentGlobalQueryResult() { DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); ds.put(new Entity("yam")); // applies ds.put(new Entity("yam")); // does not apply - // first global query only sees the first Entity + // First global query only sees the first Entity. assertEquals(1, ds.prepare(new Query("yam")).countEntities(withLimit(10))); - // second global query sees both Entities because we "groom" (attempt to - // apply unapplied jobs) after every query + // Second global query sees both Entities because we "groom" (attempt to + // apply unapplied jobs) after every query. assertEquals(2, ds.prepare(new Query("yam")).countEntities(withLimit(10))); } } diff --git a/unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java b/unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java index 6a3e1b64b68..6e2e0185090 100644 --- a/unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,23 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.appengine.samples; // [START LocalDatastoreTest] +import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; +import static org.junit.Assert.assertEquals; + import com.google.appengine.api.datastore.DatastoreService; import com.google.appengine.api.datastore.DatastoreServiceFactory; import com.google.appengine.api.datastore.Entity; import com.google.appengine.api.datastore.Query; import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; + import org.junit.After; import org.junit.Before; import org.junit.Test; -import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; -import static org.junit.Assert.assertEquals; - public class LocalDatastoreTest { private final LocalServiceTestHelper helper = @@ -45,7 +47,7 @@ public void tearDown() { helper.tearDown(); } - // run this test twice to prove we're not leaking any state across tests + // Run this test twice to prove we're not leaking any state across tests. private void doTest() { DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); assertEquals(0, ds.prepare(new Query("yam")).countEntities(withLimit(10))); diff --git a/unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java b/unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java index fbf98855bab..62f6bd05883 100644 --- a/unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,19 +18,25 @@ // [START LocalHighRepDatastoreTest] -import com.google.appengine.api.datastore.*; +import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; +import static org.junit.Assert.assertEquals; + +import com.google.appengine.api.datastore.DatastoreService; +import com.google.appengine.api.datastore.DatastoreServiceFactory; +import com.google.appengine.api.datastore.Entity; +import com.google.appengine.api.datastore.Key; +import com.google.appengine.api.datastore.KeyFactory; +import com.google.appengine.api.datastore.Query; import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; + import org.junit.After; import org.junit.Before; import org.junit.Test; -import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; -import static org.junit.Assert.assertEquals; - public class LocalHighRepDatastoreTest { - // maximum eventual consistency + // Maximum eventual consistency. private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig() .setDefaultHighRepJobPolicyUnappliedJobPercentage(100)); @@ -51,9 +57,9 @@ public void testEventuallyConsistentGlobalQueryResult() { Key ancestor = KeyFactory.createKey("foo", 3); ds.put(new Entity("yam", ancestor)); ds.put(new Entity("yam", ancestor)); - // global query doesn't see the data + // Global query doesn't see the data. assertEquals(0, ds.prepare(new Query("yam")).countEntities(withLimit(10))); - // ancestor query does see the data + // Ancestor query does see the data. assertEquals(2, ds.prepare(new Query("yam", ancestor)).countEntities(withLimit(10))); } } diff --git a/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java b/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java index 0989eb28a3b..8950dc67a92 100644 --- a/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,23 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.appengine.samples; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; // [START imports] + import com.google.appengine.api.memcache.MemcacheService; import com.google.appengine.api.memcache.MemcacheServiceFactory; import com.google.appengine.tools.development.testing.LocalMemcacheServiceTestConfig; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; + // [END imports] import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - // [START NameAndHelper] public class LocalMemcacheTest { @@ -48,8 +50,7 @@ public void tearDown() { helper.tearDown(); } - // run this test twice to prove we're not leaking any state across tests - + // Run this test twice to prove we're not leaking any state across tests. // [START doTest] private void doTest() { MemcacheService ms = MemcacheServiceFactory.getMemcacheService(); diff --git a/unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java b/unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java index fa835d232b0..25aa98c6728 100644 --- a/unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,9 @@ // [START MyFirstTest] -import org.junit.Test; +import static org.junit.Assert.assertEquals; -import static org.junit.Assert.*; +import org.junit.Test; public class MyFirstTest { @Test diff --git a/unittests/src/test/java/com/google/appengine/samples/OAuthTest.java b/unittests/src/test/java/com/google/appengine/samples/OAuthTest.java index 81cb86fed58..7a74897a3d2 100644 --- a/unittests/src/test/java/com/google/appengine/samples/OAuthTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/OAuthTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,22 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.appengine.samples; // [START OAuthTest] +import static org.junit.Assert.assertEquals; + import com.google.appengine.api.oauth.OAuthRequestException; import com.google.appengine.api.oauth.OAuthService; import com.google.appengine.api.oauth.OAuthServiceFactory; import com.google.appengine.api.users.User; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; import com.google.appengine.tools.development.testing.LocalUserServiceTestConfig; + import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; - public class OAuthTest { private static final String OAUTH_CONSUMER_KEY = "notexample.com"; private static final String OAUTH_EMAIL = "bozo@clown.com"; diff --git a/unittests/src/test/java/com/google/appengine/samples/ShortTest.java b/unittests/src/test/java/com/google/appengine/samples/ShortTest.java index 6605668c6c8..071b004db4e 100644 --- a/unittests/src/test/java/com/google/appengine/samples/ShortTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/ShortTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.appengine.samples; // [START ShortTest] +import static org.junit.Assert.assertEquals; + import com.google.appengine.api.capabilities.Capability; import com.google.appengine.api.capabilities.CapabilityStatus; import com.google.appengine.api.datastore.DatastoreService; @@ -26,11 +29,10 @@ import com.google.appengine.tools.development.testing.LocalCapabilitiesServiceTestConfig; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; import com.google.apphosting.api.ApiProxy; + import org.junit.After; import org.junit.Test; -import static org.junit.Assert.assertEquals; - public class ShortTest { private LocalServiceTestHelper helper; @@ -39,12 +41,11 @@ public void tearDown() { helper.tearDown(); } - @Test(expected = ApiProxy.CapabilityDisabledException.class) public void testDisabledDatastore() { Capability testOne = new Capability("datastore_v3"); CapabilityStatus testStatus = CapabilityStatus.DISABLED; - //Initialize + // Initialize the test configuration. LocalCapabilitiesServiceTestConfig config = new LocalCapabilitiesServiceTestConfig().setCapabilityStatus(testOne, testStatus); helper = new LocalServiceTestHelper(config); diff --git a/unittests/src/test/java/com/google/appengine/samples/TaskQueueConfigTest.java b/unittests/src/test/java/com/google/appengine/samples/TaskQueueConfigTest.java index b056662eb5c..a3ac7a3d6e4 100644 --- a/unittests/src/test/java/com/google/appengine/samples/TaskQueueConfigTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/TaskQueueConfigTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,20 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.appengine.samples; +import static org.junit.Assert.assertEquals; + import com.google.appengine.api.taskqueue.QueueFactory; import com.google.appengine.api.taskqueue.TaskOptions; import com.google.appengine.api.taskqueue.dev.LocalTaskQueue; import com.google.appengine.api.taskqueue.dev.QueueStateInfo; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig; + import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; - public class TaskQueueConfigTest { // [START LocalServiceTestHelper] private final LocalServiceTestHelper helper = @@ -44,7 +46,6 @@ public void tearDown() { helper.tearDown(); } - // Run this test twice to demonstrate we're not leaking state across tests. // If we _are_ leaking state across tests we'll get an exception on the // second test because there will already be a task with the given name. @@ -52,11 +53,12 @@ private void doTest() throws InterruptedException { // [START QueueFactory] QueueFactory.getQueue("my-queue-name").add(TaskOptions.Builder.withTaskName("task29")); // [END QueueFactory] - // give the task time to execute if tasks are actually enabled (which they - // aren't, but that's part of the test) + // Give the task time to execute if tasks are actually enabled (which they + // aren't, but that's part of the test). Thread.sleep(1000); LocalTaskQueue ltq = LocalTaskQueueTestConfig.getLocalTaskQueue(); - QueueStateInfo qsi = ltq.getQueueStateInfo().get(QueueFactory.getQueue("my-queue-name").getQueueName()); + QueueStateInfo qsi = + ltq.getQueueStateInfo().get(QueueFactory.getQueue("my-queue-name").getQueueName()); assertEquals(1, qsi.getTaskInfo().size()); assertEquals("task29", qsi.getTaskInfo().get(0).getTaskName()); } diff --git a/unittests/src/test/java/com/google/appengine/samples/TaskQueueTest.java b/unittests/src/test/java/com/google/appengine/samples/TaskQueueTest.java index 21f0d1e326e..cd03d1fb6c4 100644 --- a/unittests/src/test/java/com/google/appengine/samples/TaskQueueTest.java +++ b/unittests/src/test/java/com/google/appengine/samples/TaskQueueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,22 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.appengine.samples; // [START TaskQueueTest] +import static org.junit.Assert.assertEquals; + import com.google.appengine.api.taskqueue.QueueFactory; import com.google.appengine.api.taskqueue.TaskOptions; import com.google.appengine.api.taskqueue.dev.LocalTaskQueue; import com.google.appengine.api.taskqueue.dev.QueueStateInfo; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig; + import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; - public class TaskQueueTest { private final LocalServiceTestHelper helper = @@ -44,14 +46,13 @@ public void tearDown() { helper.tearDown(); } - // Run this test twice to demonstrate we're not leaking state across tests. // If we _are_ leaking state across tests we'll get an exception on the // second test because there will already be a task with the given name. private void doTest() throws InterruptedException { QueueFactory.getDefaultQueue().add(TaskOptions.Builder.withTaskName("task29")); - // give the task time to execute if tasks are actually enabled (which they - // aren't, but that's part of the test) + // Give the task time to execute if tasks are actually enabled (which they + // aren't, but that's part of the test). Thread.sleep(1000); LocalTaskQueue ltq = LocalTaskQueueTestConfig.getLocalTaskQueue(); QueueStateInfo qsi = ltq.getQueueStateInfo().get(QueueFactory.getDefaultQueue().getQueueName());