Skip to content
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

Checkstyle fix for unittests samples. #114

Merged
merged 1 commit into from
Mar 16, 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
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 @@ -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 =
Expand Down
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 @@ -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.
Expand Down
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 @@ -13,35 +13,41 @@
* 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;
static int existingJobCounter = 0;

@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;
}
}
Expand All @@ -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)));
}
}
Expand Down
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 @@ -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 =
Expand All @@ -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)));
Expand Down
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 @@ -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));
Expand All @@ -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)));
}
}
Expand Down
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 @@ -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 {

Expand All @@ -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();
Expand Down
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 @@ -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
Expand Down
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 @@ -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";
Expand Down
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 @@ -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;
Expand All @@ -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;

Expand All @@ -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);
Expand Down
Loading