@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "requery",
        args = {}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "getCount",
        args = {})
  })
  public void testRequery() {
    final String DELETE = "DELETE FROM " + TABLE_NAME + " WHERE number_1 =";
    final String DELETE_1 = DELETE + "1;";
    final String DELETE_2 = DELETE + "2;";

    SQLiteCursor cursor = getCursor();
    MockObserver observer = new MockObserver();
    cursor.registerDataSetObserver(observer);

    mDatabase.execSQL(DELETE_1);
    // first time run getCount, it will refresh CursorWindow.
    assertEquals(TEST_COUNT - 1, cursor.getCount());
    assertFalse(observer.hasChanged());

    mDatabase.execSQL(DELETE_2);
    // when getCount() has invoked once, it can no longer refresh CursorWindow.
    assertEquals(TEST_COUNT - 1, cursor.getCount());

    assertTrue(cursor.requery());
    // only after requery, getCount can get most up-to-date counting info now.
    assertEquals(TEST_COUNT - 2, cursor.getCount());
    assertTrue(observer.hasChanged());
  }
  @Test
  public void testScriptFetcher_MockWebServer_CategoryDTOIsPopulated() {
    remoteAvailableInstallers.populate();

    assertEquals("Accessories", observer.getDTO().get(0).getName());
    assertEquals(2, observer.getDTO().get(0).getId());
    assertEquals(CategoryDTO.CategoryType.INSTALLERS, observer.getDTO().get(0).getType());
  }
  @Test
  public void testScriptFetcher_MockWebServer_ApplicationsDTOIsPopulated() {
    remoteAvailableInstallers.populate();

    List<ApplicationDTO> applications = observer.getDTO().get(0).getApplications();

    assertEquals("", applications.get(0).getDescription());
    assertEquals(373, applications.get(0).getId());
    assertEquals(
        "http://files.playonlinux.com/resources/icones_install/7-Zip",
        applications.get(0).getIconUrl());
    assertEquals(2, applications.get(0).getMiniaturesUrls().size());
    assertEquals("7-Zip", applications.get(0).getName());
    assertEquals("URL1", applications.get(0).getMiniaturesUrls().get(0));
    assertEquals("URL2", applications.get(0).getMiniaturesUrls().get(1));

    assertEquals("Amazon Description", applications.get(1).getDescription());
    assertEquals(1265, applications.get(1).getId());
    assertEquals(
        "http://files.playonlinux.com/resources/icones_install/Amazon Kindle",
        applications.get(1).getIconUrl());
    assertEquals(0, applications.get(1).getMiniaturesUrls().size());
    assertEquals("Amazon Kindle", applications.get(1).getName());
  }
  @TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "deactivate",
        args = {}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "setWindow",
        args = {android.database.CursorWindow.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "registerDataSetObserver",
        args = {android.database.DataSetObserver.class})
  })
  public void testRegisterDataSetObserver() {
    SQLiteCursor cursor = getCursor();
    MockCursorWindow cursorWindow = new MockCursorWindow(false);

    MockObserver observer = new MockObserver();

    cursor.setWindow(cursorWindow);
    // Before registering, observer can't be notified.
    assertFalse(observer.hasInvalidated());
    cursor.moveToLast();
    assertFalse(cursorWindow.isClosed());
    cursor.deactivate();
    assertFalse(observer.hasInvalidated());
    // deactivate() will close the CursorWindow
    assertTrue(cursorWindow.isClosed());

    // test registering DataSetObserver
    assertTrue(cursor.requery());
    cursor.registerDataSetObserver(observer);
    assertFalse(observer.hasInvalidated());
    cursor.moveToLast();
    assertEquals(TEST_COUNT, cursor.getInt(1));
    cursor.deactivate();
    // deactivate method can invoke invalidate() method, can be observed by DataSetObserver.
    assertTrue(observer.hasInvalidated());

    try {
      cursor.getInt(1);
      fail("After deactivating, cursor cannot execute getting value operations.");
    } catch (StaleDataException e) {
    }

    assertTrue(cursor.requery());
    cursor.moveToLast();
    assertEquals(TEST_COUNT, cursor.getInt(1));

    // can't register a same observer twice.
    try {
      cursor.registerDataSetObserver(observer);
      fail("didn't throw IllegalStateException when register existed observer");
    } catch (IllegalStateException e) {
    }

    // after unregistering, observer can't be notified.
    cursor.unregisterDataSetObserver(observer);
    observer.resetStatus();
    assertFalse(observer.hasInvalidated());
    cursor.deactivate();
    assertFalse(observer.hasInvalidated());
  }