FileDocCategorySizeDatePackage
PreferencesUnitTests.javaAPI DocAndroid 1.5 API3491Wed May 06 22:42:46 BST 2009com.android.email

PreferencesUnitTests

public class PreferencesUnitTests extends android.test.AndroidTestCase
This is a series of unit tests for the Preferences class. Technically these are functional because they use the underlying preferences framework. It would be a really good idea if we could inject our own underlying preferences storage, to better test cases like zero accounts behavior (right now, we have to allow for any number of accounts already being on the device, and not trashing any.)

Fields Summary
private Preferences
mPreferences
private String
mUuid
private Account
mAccount
Constructors Summary
Methods Summary
private voidcreateTestAccount()
Create a dummy account with minimal fields

        mAccount = new Account(getContext());
        mAccount.save(mPreferences);
        
        mUuid = mAccount.getUuid();
    
protected voidsetUp()

        super.setUp();
        
        mPreferences = Preferences.getPreferences(getContext());
    
protected voidtearDown()
Delete any dummy accounts we set up for this test

        super.tearDown();
        
        if (mAccount != null && mPreferences != null) {
            mAccount.delete(mPreferences);
        }
    
public voidtestGetAccountByContentUri()
Test the new getAccountByContentUri() API. This should return null if no accounts are configured, or the Uri doesn't match, and it should return a desired account otherwise. TODO: Not actually testing the no-accounts case

        // Create a dummy account
        createTestAccount();
        
        // test sunny-day lookup by Uri
        Uri testAccountUri = mAccount.getContentUri();
        Account lookup = mPreferences.getAccountByContentUri(testAccountUri);
        assertEquals(mAccount, lookup);
        
        // now make it a bogus Uri - bad scheme, good path, good UUID
        testAccountUri = Uri.parse("bogus://accounts/" + mAccount.getUuid());
        lookup = mPreferences.getAccountByContentUri(testAccountUri);
        assertNull(lookup);
        
        // now make it a bogus Uri - good scheme, bad path, good UUID
        testAccountUri = Uri.parse("content://bogus/" + mAccount.getUuid());
        lookup = mPreferences.getAccountByContentUri(testAccountUri);
        assertNull(lookup);
        
        // now make it a bogus Uri - good scheme/path, bad UUID
        testAccountUri = Uri.parse("content://accounts/" + mAccount.getUuid() + "-bogus");
        lookup = mPreferences.getAccountByContentUri(testAccountUri);
        assertNull(lookup);