@Test(expected = MessagingException.class) public void shouldThrowExceptionIfUsernameIsMissing() throws Exception { new BackupImapStore(RuntimeEnvironment.application, "imap://imap.gmail.com:1234", false); }
@Test(expected = MessagingException.class) public void shouldThrowExceptionIfPasswordIsMissing() throws Exception { new BackupImapStore(RuntimeEnvironment.application, "imap://plain:foo:@imap.gmail.com:1234", false); }
@Test public void testShouldCreateCorrectTrustFactoryForTrustAllSSLUrl() throws Exception { String uri = "imap+ssl://xoauth:foooo@imap.gmail.com"; BackupImapStore store = new BackupImapStore(RuntimeEnvironment.application, uri, true); assertThat(store.getTrustedSocketFactory()).isInstanceOf(AllTrustedSocketFactory.class); }
@Test public void testShouldCreateCorrectTrustFactoryForTrustedTLSUrl() throws Exception { String uri = "imap+tls+://xoauth:foooo@imap.gmail.com"; BackupImapStore store = new BackupImapStore(RuntimeEnvironment.application, uri, false); assertThat(store.getTrustedSocketFactory()).isInstanceOf(DefaultTrustedSocketFactory.class); }
@Test public void shouldHaveToStringWithStoreUriForLogging() throws Exception { BackupImapStore store = new BackupImapStore(RuntimeEnvironment.application, "imap://xoauth:foooo@imap.gmail.com", false); assertThat(store.toString()).isEqualTo("BackupImapStore{uri=imap://xoauth:XXXXX@imap.gmail.com}"); } }
@Test public void testAccountHasStoreUri() throws Exception { String uri = "imap://xoauth:foooo@imap.gmail.com"; BackupImapStore store = new BackupImapStore(RuntimeEnvironment.application, uri, false); assertThat(store.getStoreUri()).isEqualTo(uri); }
@Test public void testShouldCreateCorrectTrustFactoryForTrustedSSLUrl() throws Exception { String uri = "imap+ssl+://xoauth:foooo@imap.gmail.com"; BackupImapStore store = new BackupImapStore(RuntimeEnvironment.application, uri, false); assertThat(store.getTrustedSocketFactory()).isInstanceOf(DefaultTrustedSocketFactory.class); }
@Test public void shouldHaveToStringWithObfuscatedStoreURIWithPort() throws Exception { BackupImapStore store = new BackupImapStore(RuntimeEnvironment.application, "imap://xoauth:foooo@imap.gmail.com:456", false); assertThat(store.getStoreUriForLogging()).isEqualTo("imap://xoauth:XXXXX@imap.gmail.com:456"); }
@Test public void shouldHaveToStringWithObfuscatedStoreURI() throws Exception { BackupImapStore store = new BackupImapStore(RuntimeEnvironment.application, "imap://xoauth:foooo@imap.gmail.com", false); assertThat(store.getStoreUriForLogging()).isEqualTo("imap://xoauth:XXXXX@imap.gmail.com"); }
protected BackupImapStore getBackupImapStore() throws MessagingException { final String uri = getAuthPreferences().getStoreUri(); if (!BackupImapStore.isValidUri(uri)) { throw new MessagingException("No valid IMAP URI: "+uri); } return new BackupImapStore(getApplicationContext(), uri, getAuthPreferences().isTrustAllCertificates()); }