private static synchronized void retrieveTestAccountsForAppIfNeeded() {
    if (appTestAccounts != null) {
      return;
    }

    appTestAccounts = new HashMap<String, TestAccount>();

    // The data we need is split across two different FQL tables. We construct two queries, submit
    // them
    // together (the second one refers to the first one), then cross-reference the results.

    // Get the test accounts for this app.
    String testAccountQuery =
        String.format(
            "SELECT id,access_token FROM test_account WHERE app_id = %s", testApplicationId);
    // Get the user names for those accounts.
    String userQuery = "SELECT uid,name FROM user WHERE uid IN (SELECT id FROM #test_accounts)";

    Bundle parameters = new Bundle();

    // Build a JSON string that contains our queries and pass it as the 'q' parameter of the query.
    JSONObject multiquery;
    try {
      multiquery = new JSONObject();
      multiquery.put("test_accounts", testAccountQuery);
      multiquery.put("users", userQuery);
    } catch (JSONException exception) {
      throw new FacebookException(exception);
    }
    parameters.putString("q", multiquery.toString());

    // We need to authenticate as this app.
    parameters.putString("access_token", getAppAccessToken());

    Request request = new Request(null, "fql", parameters, null);
    Response response = request.executeAndWait();

    if (response.getError() != null) {
      throw response.getError().getException();
    }

    FqlResponse fqlResponse = response.getGraphObjectAs(FqlResponse.class);

    GraphObjectList<FqlResult> fqlResults = fqlResponse.getData();
    if (fqlResults == null || fqlResults.size() != 2) {
      throw new FacebookException("Unexpected number of results from FQL query");
    }

    // We get back two sets of results. The first is from the test_accounts query, the second from
    // the users query.
    Collection<TestAccount> testAccounts =
        fqlResults.get(0).getFqlResultSet().castToListOf(TestAccount.class);
    Collection<UserAccount> userAccounts =
        fqlResults.get(1).getFqlResultSet().castToListOf(UserAccount.class);

    // Use both sets of results to populate our static array of accounts.
    populateTestAccounts(testAccounts, userAccounts);

    return;
  }
  private void addResults(Response response) {
    SimpleGraphObjectCursor<T> cursorToModify =
        (cursor == null || !appendResults)
            ? new SimpleGraphObjectCursor<T>()
            : new SimpleGraphObjectCursor<T>(cursor);

    PagedResults result = response.getGraphObjectAs(PagedResults.class);
    boolean fromCache = response.getIsFromCache();

    GraphObjectList<T> data = result.getData().castToListOf(graphObjectClass);
    boolean haveData = data.size() > 0;

    if (haveData) {
      nextRequest = response.getRequestForPagedResults(Response.PagingDirection.NEXT);

      cursorToModify.addGraphObjects(data, fromCache);
      if (nextRequest != null) {
        cursorToModify.setMoreObjectsAvailable(true);
      } else {
        cursorToModify.setMoreObjectsAvailable(false);
      }
    }

    if (!haveData) {
      cursorToModify.setMoreObjectsAvailable(false);
      cursorToModify.setFromCache(fromCache);

      nextRequest = null;
    }

    // Once we get any set of results NOT from the cache, stop trying to get any future ones
    // from it.
    if (!fromCache) {
      skipRoundtripIfCached = false;
    }

    deliverResult(cursorToModify);
  }