FileDocCategorySizeDatePackage
ImapStoreUnitTests.javaAPI DocAndroid 1.5 API5881Wed May 06 22:42:46 BST 2009com.android.email.mail.store

ImapStoreUnitTests

public class ImapStoreUnitTests extends android.test.AndroidTestCase
This is a series of unit tests for the ImapStore class. These tests must be locally complete - no server(s) required.

Fields Summary
private ImapStore
mStore
private ImapStore.ImapFolder
mFolder
Constructors Summary
Methods Summary
private voiddoTestImapList()

        ImapResponseParser parser = new ImapResponseParser(null);
        ImapResponseParser.ImapList list = parser.new ImapList();
        String key = "key";
        String date = "01-Jan-2009 01:00:00 -0800";
        list.add(key);
        list.add(date);
        Date result = list.getKeyedDate(key);
        // "01-Jan-2009 09:00:00 +0000" => 1230800400000L 
        assertEquals(1230800400000L, result.getTime());
    
private com.android.email.mail.transport.MockTransportopenAndInjectMockTransport()
TODO: Test the scenario where the transport is "open" but not really (e.g. server closed). /** Set up a basic MockTransport. open it, and inject it into mStore

        // Create mock transport and inject it into the ImapStore that's already set up
        MockTransport mockTransport = new MockTransport();
        mockTransport.setSecurity(Transport.CONNECTION_SECURITY_NONE);
        mStore.setTransport(mockTransport);
        return mockTransport;
    
protected voidsetUp()
Setup code. We generate a lightweight ImapStore and ImapStore.ImapFolder.

    
                   
    
         
        super.setUp();
        
        // These are needed so we can get at the inner classes
        mStore = new ImapStore("imap://user:password@server:999");
        mFolder = (ImapStore.ImapFolder) mStore.getFolder("INBOX");
        
        // This is needed for parsing mime messages
        BinaryTempFileBody.setTempDirectory(this.getContext().getCacheDir());
    
private voidsetupOpenFolder(com.android.email.mail.transport.MockTransport mockTransport)
Helper which stuffs the mock with enough strings to satisfy a call to ImapFolder.open()

param
mockTransport the mock transport we're using

        mockTransport.expect(null, "* OK Imap 2000 Ready To Assist You");
        mockTransport.expect("1 LOGIN user \"password\"", 
                "1 OK user authenticated (Success)");
        mockTransport.expect("2 SELECT \"INBOX\"", new String[] {
                "* FLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen)",
                "* OK [PERMANENTFLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen \\*)]",
                "* 0 EXISTS",
                "* 0 RECENT",
                "* OK [UNSEEN 0]",
                "* OK [UIDNEXT 1]",
                "2 OK [READ-WRITE] INBOX selected. (Success)"});
    
public voidtestImapListWithUsLocale()
Confirms that ImapList object correctly returns an appropriate Date object without throwning MessagingException when getKeyedDate() is called. Here, we try a same test twice using two locales, Locale.US and the other. ImapList uses Locale class internally, and as a result, there's a possibility in which it may throw a MessageException when Locale is not Locale.US. Locale.JAPAN is a typical locale which emits different date formats, which had caused a bug before.

throws
MessagingException

        Locale savedLocale = Locale.getDefault();
        Locale.setDefault(Locale.US);
        doTestImapList();
        Locale.setDefault(Locale.JAPAN);
        doTestImapList();
        Locale.setDefault(savedLocale);
    
public voidtestSimpleLogin()
Confirms simple non-SSL non-TLS login

        
        MockTransport mockTransport = openAndInjectMockTransport();
        
        // try to open it
        setupOpenFolder(mockTransport);
        mFolder.open(OpenMode.READ_WRITE);
        
        // TODO: inject specific facts in the initial folder SELECT and check them here