@Test
 public void testReset() throws InterruptedException {
   saveData(10, "name", "description");
   store.reset();
   Data readData = store.read(10);
   Assert.assertNull(readData);
 }
  @Test
  public void testNestedListSaveAndFilter() throws InterruptedException, JSONException {
    ReadFilter filter;
    JSONObject where;
    List<TrivialNestedClassWithCollection> result;

    List<Data> data = new ArrayList<Data>();
    data.add(new Data(10, "name", "description"));
    data.add(new Data(30, "name", "description"));

    TrivialNestedClassWithCollection newNested = new TrivialNestedClassWithCollection();
    newNested.setId(1);
    newNested.setText("nestedText");
    newNested.setData(data);

    open(nestedWithCollectionStore);
    nestedWithCollectionStore.save(newNested);

    filter = new ReadFilter();
    where = new JSONObject();
    where.put("text", "nestedText");
    where.put("id", 1);

    filter.setWhere(where);
    result = nestedWithCollectionStore.readWithFilter(filter);
    Assert.assertEquals(1, result.size());
    TrivialNestedClassWithCollection nestedResult = result.get(0);
    Assert.assertEquals((Integer) 10, nestedResult.data.get(0).getId());
    Assert.assertEquals((Integer) 30, nestedResult.data.get(1).getId());
  }
  @Test
  public void testNestedSaveAndFilter() throws InterruptedException, JSONException {
    ReadFilter filter;
    JSONObject where;
    List<TrivialNestedClass> result;

    Data data = new Data(10, "name", "description");

    TrivialNestedClass newNested = new TrivialNestedClass();
    newNested.setId(1);
    newNested.setText("nestedText");
    newNested.setData(data);

    open(nestedStore);
    nestedStore.save(newNested);

    filter = new ReadFilter();
    where = new JSONObject();
    where.put("text", "nestedText");
    JSONObject dataFilter = new JSONObject();
    dataFilter.put("id", 10);
    where.put("data", dataFilter);
    filter.setWhere(where);
    result = nestedStore.readWithFilter(filter);
    Assert.assertEquals(1, result.size());
    TrivialNestedClass nestedResult = result.get(0);
    Assert.assertEquals("name", nestedResult.data.getName());
  }
  @Test
  public void testFilter() throws InterruptedException, JSONException {
    ReadFilter filter;
    JSONObject where;
    List<Data> result;

    loadBulkData();

    result = store.readWithFilter(null);
    Assert.assertEquals(6, result.size());

    filter = new ReadFilter();
    where = new JSONObject();
    where.put("name", "name2");
    filter.setWhere(where);
    result = store.readWithFilter(filter);
    Assert.assertEquals(3, result.size());

    filter = new ReadFilter();
    where = new JSONObject();
    where.put("name", "name2");
    where.put("description", "description");
    filter.setWhere(where);
    result = store.readWithFilter(filter);
    Assert.assertEquals(2, result.size());
  }
  @Test
  public void testRemove() throws InterruptedException, JSONException {
    loadBulkData();
    store.remove(1);

    List<Data> allData = new ArrayList<Data>(store.readAll());
    Collections.sort(allData);
    Assert.assertEquals(5, allData.size());
    Assert.assertEquals(2l, (long) allData.get(0).getId());
    Assert.assertEquals("name2", allData.get(4).getName());
  }
  @Test
  public void testSaveListOfBoringData() throws InterruptedException {
    SQLStore<ListWithId> longStore = new SQLStore<ListWithId>(ListWithId.class, context);
    open(longStore);
    ListWithId<Long> longList = new ListWithId<Long>(100);

    longList.setId(1);

    for (long i = 0; i < 100; i++) {
      longList.data.add(i);
    }
    longStore.save(longList);
    Assert.assertEquals(100, longStore.readAll().iterator().next().data.size());
  }
  @Test
  public void testSave() throws InterruptedException {

    Data data = new Data(10, "name", "description");
    data.setEnable(true);
    saveData(10, "name", "description", true);
    Data readData = store.read(10);
    Assert.assertEquals(data, readData);
  }
  private <T> void open(SQLStore<T> store) throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    store.open(
        new Callback<SQLStore<T>>() {
          @Override
          public void onSuccess(SQLStore<T> sqlStore) {
            latch.countDown();
          }

          @Override
          public void onFailure(Exception e) {
            latch.countDown();
            throw new RuntimeException(e);
          }
        });
    latch.await();
  }
  @Test
  public void testSuccessCallback() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(2);
    store.open(
        new Callback<SQLStore<Data>>() {
          @Override
          public void onSuccess(SQLStore<Data> data) {
            latch.countDown();
          }

          @Override
          public void onFailure(Exception e) {
            throw new RuntimeException(e);
          }
        });

    latch.await(5, TimeUnit.SECONDS);
    Assert.assertEquals("OnSuccess should be called exactly once!", 1, latch.getCount());
  }
 @Test
 public void testIsNotEmpty() throws InterruptedException {
   saveData(10, "name", "description");
   Assert.assertFalse(store.isEmpty());
 }
 @Test
 public void testIsEmpty() throws InterruptedException {
   open(store);
   Assert.assertTrue(store.isEmpty());
 }
 private void saveData(Integer id, String name, String desc, boolean enable)
     throws InterruptedException {
   open(store);
   store.save(new Data(id, name, desc, enable));
 }