1717package com .google .cloud .datastore .testing ;
1818
1919import static org .junit .Assert .assertEquals ;
20+ import static org .junit .Assert .assertNotNull ;
21+ import static org .junit .Assert .assertNull ;
2022import static org .junit .Assert .assertSame ;
2123import static org .junit .Assert .assertTrue ;
2224
2325import com .google .cloud .AuthCredentials ;
26+ import com .google .cloud .datastore .Datastore ;
27+ import com .google .cloud .datastore .DatastoreException ;
2428import com .google .cloud .datastore .DatastoreOptions ;
29+ import com .google .cloud .datastore .Entity ;
30+ import com .google .cloud .datastore .Key ;
2531
32+ import org .junit .Rule ;
2633import org .junit .Test ;
34+ import org .junit .rules .ExpectedException ;
2735import org .junit .runner .RunWith ;
2836import org .junit .runners .JUnit4 ;
2937
38+ import java .io .IOException ;
39+
3040@ RunWith (JUnit4 .class )
3141public class LocalDatastoreHelperTest {
3242
3343 private static final double TOLERANCE = 0.00001 ;
3444 private static final String PROJECT_ID_PREFIX = "test-project-" ;
3545 private static final String NAMESPACE = "namespace" ;
3646
47+ @ Rule
48+ public ExpectedException thrown = ExpectedException .none ();
49+
3750 @ Test
3851 public void testCreate () {
3952 LocalDatastoreHelper helper = LocalDatastoreHelper .create (0.75 );
@@ -57,4 +70,19 @@ public void testOptions() {
5770 assertSame (AuthCredentials .noAuth (), options .authCredentials ());
5871 assertEquals (NAMESPACE , options .namespace ());
5972 }
73+
74+ @ Test
75+ public void testStartStopReset () throws IOException , InterruptedException {
76+ LocalDatastoreHelper helper = LocalDatastoreHelper .create ();
77+ helper .start ();
78+ Datastore datastore = helper .options ().service ();
79+ Key key = datastore .newKeyFactory ().kind ("kind" ).newKey ("name" );
80+ datastore .put (Entity .builder (key ).build ());
81+ assertNotNull (datastore .get (key ));
82+ helper .reset ();
83+ assertNull (datastore .get (key ));
84+ helper .stop ();
85+ thrown .expect (DatastoreException .class );
86+ datastore .get (key );
87+ }
6088}
0 commit comments