Guest User

Untitled

a guest
Oct 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. package net.sue445.service;
  2.  
  3. import static org.hamcrest.Matchers.*;
  4. import static org.junit.Assert.*;
  5.  
  6. import java.util.Map;
  7.  
  8. import net.sue445.model.Slim3Model;
  9.  
  10. import org.junit.Before;
  11. import org.junit.Test;
  12. import org.slim3.datastore.Datastore;
  13. import org.slim3.tester.AppEngineTestCase;
  14.  
  15. import com.google.appengine.api.datastore.Key;
  16.  
  17. public class SampleServiceTest extends AppEngineTestCase {
  18.  
  19. private Key key1;
  20. private Key key2;
  21. private Key key3;
  22.  
  23. @Before
  24. public void setUpModels(){
  25. key1 = Datastore.createKey(Slim3Model.class, "key1");
  26. key2 = Datastore.createKey(Slim3Model.class, "key2");
  27. key3 = Datastore.createKey(Slim3Model.class, "key3");
  28.  
  29. Slim3Model model1 = new Slim3Model();
  30. model1.setKey(key1);
  31. Datastore.put(model1);
  32.  
  33. Slim3Model model2 = new Slim3Model();
  34. model2.setKey(key2);
  35. Datastore.put(model2);
  36. }
  37.  
  38. @Test
  39. public void getAsMap() throws Exception {
  40. // exercise
  41. Map<Key, Slim3Model> actual = Datastore.getAsMap(Slim3Model.class, key1, key2, key3);
  42.  
  43. // assertion
  44. assertThat(actual.size(), is(2));
  45.  
  46. assertThat(actual, hasKey(key1));
  47. assertThat(actual.get(key1).getKey(), is(key1));
  48.  
  49. assertThat(actual, hasKey(key2));
  50. assertThat(actual.get(key2).getKey(), is(key2));
  51.  
  52. assertThat(actual, not(hasKey(key3)));
  53. assertThat(actual.get(key3), is(nullValue()));
  54. }
  55. }
Add Comment
Please, Sign In to add comment