public void testLoadContactWithContactIdUri() {
    // Use content Uris that only contain the ID
    final long contactId = 1;
    final long rawContactId = 11;
    final long dataId = 21;

    final String lookupKey = "aa%12%@!";
    final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
    final Uri entityUri = Uri.withAppendedPath(baseUri, Contacts.Entity.CONTENT_DIRECTORY);
    final Uri lookupUri =
        ContentUris.withAppendedId(
            Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey), contactId);

    ContactQueries queries = new ContactQueries();
    mContactsProvider.expectTypeQuery(baseUri, Contacts.CONTENT_ITEM_TYPE);
    queries.fetchAllData(entityUri, contactId, rawContactId, dataId, lookupKey);

    Contact contact = assertLoadContact(baseUri);

    assertEquals(contactId, contact.getId());
    assertEquals(rawContactId, contact.getNameRawContactId());
    assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
    assertEquals(lookupKey, contact.getLookupKey());
    assertEquals(lookupUri, contact.getLookupUri());
    assertEquals(1, contact.getRawContacts().size());
    assertEquals(1, contact.getStatuses().size());
    mContactsProvider.verify();
  }
  public void testLoadContactWithOldStyleUri() {
    // Use content Uris that only contain the ID but use the format used in Donut
    final long contactId = 1;
    final long rawContactId = 11;
    final long dataId = 21;

    final String lookupKey = "aa%12%@!";
    final Uri legacyUri = ContentUris.withAppendedId(Uri.parse("content://contacts"), rawContactId);
    final Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
    final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
    final Uri lookupUri =
        ContentUris.withAppendedId(
            Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey), contactId);
    final Uri entityUri = Uri.withAppendedPath(lookupUri, Contacts.Entity.CONTENT_DIRECTORY);

    ContactQueries queries = new ContactQueries();
    queries.fetchContactIdAndLookupFromRawContactUri(rawContactUri, contactId, lookupKey);
    queries.fetchAllData(entityUri, contactId, rawContactId, dataId, lookupKey);

    Contact contact = assertLoadContact(legacyUri);

    assertEquals(contactId, contact.getId());
    assertEquals(rawContactId, contact.getNameRawContactId());
    assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
    assertEquals(lookupKey, contact.getLookupKey());
    assertEquals(lookupUri, contact.getLookupUri());
    assertEquals(1, contact.getRawContacts().size());
    assertEquals(1, contact.getStatuses().size());
    mContactsProvider.verify();
  }
  public void testLoadContactWithContactLookupWithIncorrectIdUri() {
    // Use lookup-style Uris that contain incorrect Contact-ID
    // (we want to ensure that still the correct contact is chosen)

    final long contactId = 1;
    final long wrongContactId = 2;
    final long rawContactId = 11;
    final long wrongRawContactId = 12;
    final long dataId = 21;

    final String lookupKey = "aa%12%@!";
    final String wrongLookupKey = "ab%12%@!";
    final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
    final Uri wrongBaseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, wrongContactId);
    final Uri lookupUri =
        ContentUris.withAppendedId(
            Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey), contactId);
    final Uri lookupWithWrongIdUri =
        ContentUris.withAppendedId(
            Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey), wrongContactId);
    final Uri entityUri =
        Uri.withAppendedPath(lookupWithWrongIdUri, Contacts.Entity.CONTENT_DIRECTORY);

    ContactQueries queries = new ContactQueries();
    mContactsProvider.expectTypeQuery(lookupWithWrongIdUri, Contacts.CONTENT_ITEM_TYPE);
    queries.fetchAllData(entityUri, contactId, rawContactId, dataId, lookupKey);

    Contact contact = assertLoadContact(lookupWithWrongIdUri);

    assertEquals(contactId, contact.getId());
    assertEquals(rawContactId, contact.getNameRawContactId());
    assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
    assertEquals(lookupKey, contact.getLookupKey());
    assertEquals(lookupUri, contact.getLookupUri());
    assertEquals(1, contact.getRawContacts().size());
    assertEquals(1, contact.getStatuses().size());

    mContactsProvider.verify();
  }