GeezerVison is showing github.com — Checkstyle fix for unittests samples. · tobernator2/java-docs-samples@8620489
File treeExpand file treeCollapse file tree Open diff view settings unittests/src/test/java/com/google/appengine/samples
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -/** | | 1 | +/* | 2 | 2 | * Copyright 2015 Google Inc. All Rights Reserved. | 3 | 3 | * | 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | | 13 | 13 | * See the License for the specific language governing permissions and | 14 | 14 | * limitations under the License. | 15 | 15 | */ | | 16 | + | 16 | 17 | package com.google.appengine.samples; | 17 | 18 |
| 18 | 19 | // [START AuthenticationTest] | 19 | 20 |
| | 21 | +import static org.junit.Assert.assertTrue; | | 22 | + | 20 | 23 | import com.google.appengine.api.users.UserService; | 21 | 24 | import com.google.appengine.api.users.UserServiceFactory; | 22 | 25 | import com.google.appengine.tools.development.testing.LocalServiceTestHelper; | 23 | 26 | import com.google.appengine.tools.development.testing.LocalUserServiceTestConfig; | | 27 | + | 24 | 28 | import org.junit.After; | 25 | 29 | import org.junit.Before; | 26 | 30 | import org.junit.Test; | 27 | 31 |
| 28 | | -import static org.junit.Assert.assertTrue; | 29 | | - | 30 | 32 | public class AuthenticationTest { | 31 | 33 |
| 32 | 34 | private final LocalServiceTestHelper helper = | |
Collapse file Copy file name to clipboardExpand all lines: unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -/** | | 1 | +/* | 2 | 2 | * Copyright 2015 Google Inc. All Rights Reserved. | 3 | 3 | * | 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | | 13 | 13 | * See the License for the specific language governing permissions and | 14 | 14 | * limitations under the License. | 15 | 15 | */ | | 16 | + | 16 | 17 | package com.google.appengine.samples; | 17 | 18 |
| 18 | 19 | // [START DeferredTaskTest] | 19 | 20 |
| | 21 | +import static org.junit.Assert.assertTrue; | | 22 | + | 20 | 23 | import com.google.appengine.api.taskqueue.DeferredTask; | 21 | 24 | import com.google.appengine.api.taskqueue.QueueFactory; | 22 | 25 | import com.google.appengine.api.taskqueue.TaskOptions; | 23 | 26 | import com.google.appengine.tools.development.testing.LocalServiceTestHelper; | 24 | 27 | import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig; | | 28 | + | 25 | 29 | import org.junit.After; | 26 | 30 | import org.junit.Before; | 27 | 31 | import org.junit.Test; | 28 | 32 |
| 29 | 33 | import java.util.concurrent.TimeUnit; | 30 | 34 |
| 31 | | -import static org.junit.Assert.assertTrue; | 32 | | - | 33 | 35 | public class DeferredTaskTest { | 34 | 36 |
| 35 | 37 | // Unlike CountDownLatch, TaskCountDownlatch lets us reset. | |
Collapse file Copy file name to clipboardExpand all lines: unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java +16-10Lines changed: 16 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -/** | | 1 | +/* | 2 | 2 | * Copyright 2015 Google Inc. All Rights Reserved. | 3 | 3 | * | 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | | 13 | 13 | * See the License for the specific language governing permissions and | 14 | 14 | * limitations under the License. | 15 | 15 | */ | | 16 | + | 16 | 17 | package com.google.appengine.samples; | 17 | 18 |
| 18 | 19 | // [START LocalCustomPolicyHighRepDatastoreTest] | 19 | 20 |
| 20 | | -import com.google.appengine.api.datastore.*; | | 21 | +import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; | | 22 | +import static org.junit.Assert.assertEquals; | | 23 | + | | 24 | +import com.google.appengine.api.datastore.DatastoreService; | | 25 | +import com.google.appengine.api.datastore.DatastoreServiceFactory; | | 26 | +import com.google.appengine.api.datastore.Entity; | | 27 | +import com.google.appengine.api.datastore.Key; | | 28 | +import com.google.appengine.api.datastore.Query; | 21 | 29 | import com.google.appengine.api.datastore.dev.HighRepJobPolicy; | 22 | 30 | import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; | 23 | 31 | import com.google.appengine.tools.development.testing.LocalServiceTestHelper; | | 32 | + | 24 | 33 | import org.junit.After; | 25 | 34 | import org.junit.Before; | 26 | 35 | import org.junit.Test; | 27 | 36 |
| 28 | | -import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; | 29 | | -import static org.junit.Assert.assertEquals; | 30 | | - | 31 | 37 | public class LocalCustomPolicyHighRepDatastoreTest { | 32 | 38 | private static final class CustomHighRepJobPolicy implements HighRepJobPolicy { | 33 | 39 | static int newJobCounter = 0; | 34 | 40 | static int existingJobCounter = 0; | 35 | 41 |
| 36 | 42 | @Override | 37 | 43 | public boolean shouldApplyNewJob(Key entityGroup) { | 38 | | - // every other new job fails to apply | | 44 | + // Every other new job fails to apply. | 39 | 45 | return newJobCounter++ % 2 == 0; | 40 | 46 | } | 41 | 47 |
| 42 | 48 | @Override | 43 | 49 | public boolean shouldRollForwardExistingJob(Key entityGroup) { | 44 | | - // every other existing job fails to apply | | 50 | + // Every other existing job fails to apply. | 45 | 51 | return existingJobCounter++ % 2 == 0; | 46 | 52 | } | 47 | 53 | } | @@ -65,10 +71,10 @@ public void testEventuallyConsistentGlobalQueryResult() { | 65 | 71 | DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); | 66 | 72 | ds.put(new Entity("yam")); // applies | 67 | 73 | ds.put(new Entity("yam")); // does not apply | 68 | | - // first global query only sees the first Entity | | 74 | + // First global query only sees the first Entity. | 69 | 75 | assertEquals(1, ds.prepare(new Query("yam")).countEntities(withLimit(10))); | 70 | | - // second global query sees both Entities because we "groom" (attempt to | 71 | | - // apply unapplied jobs) after every query | | 76 | + // Second global query sees both Entities because we "groom" (attempt to | | 77 | + // apply unapplied jobs) after every query. | 72 | 78 | assertEquals(2, ds.prepare(new Query("yam")).countEntities(withLimit(10))); | 73 | 79 | } | 74 | 80 | } | |
Collapse file Copy file name to clipboardExpand all lines: unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java +7-5Lines changed: 7 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -/** | | 1 | +/* | 2 | 2 | * Copyright 2015 Google Inc. All Rights Reserved. | 3 | 3 | * | 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | | 13 | 13 | * See the License for the specific language governing permissions and | 14 | 14 | * limitations under the License. | 15 | 15 | */ | | 16 | + | 16 | 17 | package com.google.appengine.samples; | 17 | 18 |
| 18 | 19 | // [START LocalDatastoreTest] | 19 | 20 |
| | 21 | +import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; | | 22 | +import static org.junit.Assert.assertEquals; | | 23 | + | 20 | 24 | import com.google.appengine.api.datastore.DatastoreService; | 21 | 25 | import com.google.appengine.api.datastore.DatastoreServiceFactory; | 22 | 26 | import com.google.appengine.api.datastore.Entity; | 23 | 27 | import com.google.appengine.api.datastore.Query; | 24 | 28 | import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; | 25 | 29 | import com.google.appengine.tools.development.testing.LocalServiceTestHelper; | | 30 | + | 26 | 31 | import org.junit.After; | 27 | 32 | import org.junit.Before; | 28 | 33 | import org.junit.Test; | 29 | 34 |
| 30 | | -import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; | 31 | | -import static org.junit.Assert.assertEquals; | 32 | | - | 33 | 35 | public class LocalDatastoreTest { | 34 | 36 |
| 35 | 37 | private final LocalServiceTestHelper helper = | @@ -45,7 +47,7 @@ public void tearDown() { | 45 | 47 | helper.tearDown(); | 46 | 48 | } | 47 | 49 |
| 48 | | - // run this test twice to prove we're not leaking any state across tests | | 50 | + // Run this test twice to prove we're not leaking any state across tests. | 49 | 51 | private void doTest() { | 50 | 52 | DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); | 51 | 53 | assertEquals(0, ds.prepare(new Query("yam")).countEntities(withLimit(10))); | |
Collapse file Copy file name to clipboardExpand all lines: unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java +14-8Lines changed: 14 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -/** | | 1 | +/* | 2 | 2 | * Copyright 2015 Google Inc. All Rights Reserved. | 3 | 3 | * | 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | | 18 | 18 |
| 19 | 19 | // [START LocalHighRepDatastoreTest] | 20 | 20 |
| 21 | | -import com.google.appengine.api.datastore.*; | | 21 | +import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; | | 22 | +import static org.junit.Assert.assertEquals; | | 23 | + | | 24 | +import com.google.appengine.api.datastore.DatastoreService; | | 25 | +import com.google.appengine.api.datastore.DatastoreServiceFactory; | | 26 | +import com.google.appengine.api.datastore.Entity; | | 27 | +import com.google.appengine.api.datastore.Key; | | 28 | +import com.google.appengine.api.datastore.KeyFactory; | | 29 | +import com.google.appengine.api.datastore.Query; | 22 | 30 | import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; | 23 | 31 | import com.google.appengine.tools.development.testing.LocalServiceTestHelper; | | 32 | + | 24 | 33 | import org.junit.After; | 25 | 34 | import org.junit.Before; | 26 | 35 | import org.junit.Test; | 27 | 36 |
| 28 | | -import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; | 29 | | -import static org.junit.Assert.assertEquals; | 30 | | - | 31 | 37 | public class LocalHighRepDatastoreTest { | 32 | 38 |
| 33 | | - // maximum eventual consistency | | 39 | + // Maximum eventual consistency. | 34 | 40 | private final LocalServiceTestHelper helper = | 35 | 41 | new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig() | 36 | 42 | .setDefaultHighRepJobPolicyUnappliedJobPercentage(100)); | @@ -51,9 +57,9 @@ public void testEventuallyConsistentGlobalQueryResult() { | 51 | 57 | Key ancestor = KeyFactory.createKey("foo", 3); | 52 | 58 | ds.put(new Entity("yam", ancestor)); | 53 | 59 | ds.put(new Entity("yam", ancestor)); | 54 | | - // global query doesn't see the data | | 60 | + // Global query doesn't see the data. | 55 | 61 | assertEquals(0, ds.prepare(new Query("yam")).countEntities(withLimit(10))); | 56 | | - // ancestor query does see the data | | 62 | + // Ancestor query does see the data. | 57 | 63 | assertEquals(2, ds.prepare(new Query("yam", ancestor)).countEntities(withLimit(10))); | 58 | 64 | } | 59 | 65 | } | |
Collapse file Copy file name to clipboardExpand all lines: unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java +7-6Lines changed: 7 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -/** | | 1 | +/* | 2 | 2 | * Copyright 2015 Google Inc. All Rights Reserved. | 3 | 3 | * | 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | | 13 | 13 | * See the License for the specific language governing permissions and | 14 | 14 | * limitations under the License. | 15 | 15 | */ | | 16 | + | 16 | 17 | package com.google.appengine.samples; | 17 | 18 |
| | 19 | +import static org.junit.Assert.assertFalse; | | 20 | +import static org.junit.Assert.assertTrue; | 18 | 21 |
| 19 | 22 | // [START imports] | | 23 | + | 20 | 24 | import com.google.appengine.api.memcache.MemcacheService; | 21 | 25 | import com.google.appengine.api.memcache.MemcacheServiceFactory; | 22 | 26 | import com.google.appengine.tools.development.testing.LocalMemcacheServiceTestConfig; | 23 | 27 | import com.google.appengine.tools.development.testing.LocalServiceTestHelper; | | 28 | + | 24 | 29 | // [END imports] | 25 | 30 |
| 26 | 31 | import org.junit.After; | 27 | 32 | import org.junit.Before; | 28 | 33 | import org.junit.Test; | 29 | 34 |
| 30 | | -import static org.junit.Assert.assertFalse; | 31 | | -import static org.junit.Assert.assertTrue; | 32 | | - | 33 | 35 | // [START NameAndHelper] | 34 | 36 | public class LocalMemcacheTest { | 35 | 37 |
| @@ -48,8 +50,7 @@ public void tearDown() { | 48 | 50 | helper.tearDown(); | 49 | 51 | } | 50 | 52 |
| 51 | | - // run this test twice to prove we're not leaking any state across tests | 52 | | - | | 53 | + // Run this test twice to prove we're not leaking any state across tests. | 53 | 54 | // [START doTest] | 54 | 55 | private void doTest() { | 55 | 56 | MemcacheService ms = MemcacheServiceFactory.getMemcacheService(); | |
Collapse file Copy file name to clipboardExpand all lines: unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -/** | | 1 | +/* | 2 | 2 | * Copyright 2015 Google Inc. All Rights Reserved. | 3 | 3 | * | 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | | 18 | 18 |
| 19 | 19 | // [START MyFirstTest] | 20 | 20 |
| 21 | | -import org.junit.Test; | | 21 | +import static org.junit.Assert.assertEquals; | 22 | 22 |
| 23 | | -import static org.junit.Assert.*; | | 23 | +import org.junit.Test; | 24 | 24 |
| 25 | 25 | public class MyFirstTest { | 26 | 26 | @Test | |
Collapse file Copy file name to clipboardExpand all lines: unittests/src/test/java/com/google/appengine/samples/OAuthTest.java +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -/** | | 1 | +/* | 2 | 2 | * Copyright 2015 Google Inc. All Rights Reserved. | 3 | 3 | * | 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | | 13 | 13 | * See the License for the specific language governing permissions and | 14 | 14 | * limitations under the License. | 15 | 15 | */ | | 16 | + | 16 | 17 | package com.google.appengine.samples; | 17 | 18 |
| 18 | 19 | // [START OAuthTest] | 19 | 20 |
| | 21 | +import static org.junit.Assert.assertEquals; | | 22 | + | 20 | 23 | import com.google.appengine.api.oauth.OAuthRequestException; | 21 | 24 | import com.google.appengine.api.oauth.OAuthService; | 22 | 25 | import com.google.appengine.api.oauth.OAuthServiceFactory; | 23 | 26 | import com.google.appengine.api.users.User; | 24 | 27 | import com.google.appengine.tools.development.testing.LocalServiceTestHelper; | 25 | 28 | import com.google.appengine.tools.development.testing.LocalUserServiceTestConfig; | | 29 | + | 26 | 30 | import org.junit.After; | 27 | 31 | import org.junit.Before; | 28 | 32 | import org.junit.Test; | 29 | 33 |
| 30 | | -import static org.junit.Assert.assertEquals; | 31 | | - | 32 | 34 | public class OAuthTest { | 33 | 35 | private static final String OAUTH_CONSUMER_KEY = "notexample.com"; | 34 | 36 | | |
Collapse file Copy file name to clipboardExpand all lines: unittests/src/test/java/com/google/appengine/samples/ShortTest.java +6-5Lines changed: 6 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -/** | | 1 | +/* | 2 | 2 | * Copyright 2015 Google Inc. All Rights Reserved. | 3 | 3 | * | 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | | 13 | 13 | * See the License for the specific language governing permissions and | 14 | 14 | * limitations under the License. | 15 | 15 | */ | | 16 | + | 16 | 17 | package com.google.appengine.samples; | 17 | 18 |
| 18 | 19 | // [START ShortTest] | 19 | 20 |
| | 21 | +import static org.junit.Assert.assertEquals; | | 22 | + | 20 | 23 | import com.google.appengine.api.capabilities.Capability; | 21 | 24 | import com.google.appengine.api.capabilities.CapabilityStatus; | 22 | 25 | import com.google.appengine.api.datastore.DatastoreService; | | 26 | 29 | import com.google.appengine.tools.development.testing.LocalCapabilitiesServiceTestConfig; | 27 | 30 | import com.google.appengine.tools.development.testing.LocalServiceTestHelper; | 28 | 31 | import com.google.apphosting.api.ApiProxy; | | 32 | + | 29 | 33 | import org.junit.After; | 30 | 34 | import org.junit.Test; | 31 | 35 |
| 32 | | -import static org.junit.Assert.assertEquals; | 33 | | - | 34 | 36 | public class ShortTest { | 35 | 37 | private LocalServiceTestHelper helper; | 36 | 38 |
| @@ -39,12 +41,11 @@ public void tearDown() { | 39 | 41 | helper.tearDown(); | 40 | 42 | } | 41 | 43 |
| 42 | | - | 43 | 44 | @Test(expected = ApiProxy.CapabilityDisabledException.class) | 44 | 45 | public void testDisabledDatastore() { | 45 | 46 | Capability testOne = new Capability("datastore_v3"); | 46 | 47 | CapabilityStatus testStatus = CapabilityStatus.DISABLED; | 47 | | - //Initialize | | 48 | + // Initialize the test configuration. | 48 | 49 | LocalCapabilitiesServiceTestConfig config = | 49 | 50 | new LocalCapabilitiesServiceTestConfig().setCapabilityStatus(testOne, testStatus); | 50 | 51 | helper = new LocalServiceTestHelper(config); | |
|