Skip to content

Commit

Permalink
Refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
jlara310 committed Apr 12, 2023
1 parent 2cdaf5d commit eeff0ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.datastore;

// Imports the Google Cloud client library
// [START datastore_regional_endpoint]

import com.google.cloud.datastore.Datastore;
import com.google.cloud.datastore.DatastoreOptions;
Expand All @@ -25,11 +26,10 @@ public class RegionalEndpoint {

public Datastore createClient() throws Exception {
// Instantiates a client
// [START datastore_regional_endpoint]
DatastoreOptions options =
DatastoreOptions.newBuilder().setHost("https://nam5-datastore.googleapis.com").build();
Datastore datastore = options.getService();
// [END datastore_regional_endpoint]
return datastore;
}
}
// [END datastore_regional_endpoint]
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@

package com.example.datastore;

import static org.junit.Assert.assertEquals;

import com.google.cloud.datastore.Datastore;
import com.google.cloud.datastore.Entity;
import com.google.cloud.datastore.Key;
import com.rule.SystemsOutRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Tests for quickstart sample. */
/**
* Tests for quickstart sample.
*/
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class RegionalEndpointIT {

private static RegionalEndpoint regionalEndpoint;
@Rule public final SystemsOutRule systemsOutRule = new SystemsOutRule();

private static final void deleteTestEntity(Datastore datastore) {
String kind = "Task";
Expand All @@ -47,11 +47,6 @@ public void setUp() {
regionalEndpoint = new RegionalEndpoint();
}

@After
public void tearDown() {
System.setOut(null);
}

@Test
public void testRegionalEndpoint() throws Exception {
Datastore datastoreWithEndpoint = regionalEndpoint.createClient();
Expand All @@ -71,15 +66,10 @@ public void testRegionalEndpoint() throws Exception {
// Saves the entity
datastoreWithEndpoint.put(task);

System.out.printf("Saved %s: %s%n", task.getKey().getName(), task.getString("description"));

// Retrieve entity
Entity retrieved = datastoreWithEndpoint.get(taskKey);

System.out.printf("Retrieved %s: %s%n", taskKey.getName(), retrieved.getString("description"));

systemsOutRule.assertContains("Saved sampletask1: Buy milk");
systemsOutRule.assertContains("Retrieved sampletask1: Buy milk");
assertEquals(task, retrieved);
deleteTestEntity(datastoreWithEndpoint);
}
}

0 comments on commit eeff0ae

Please sign in to comment.