Remove WebDavStore.createUri/decodeUri

This commit is contained in:
cketti 2018-07-16 17:38:36 +02:00
parent 6758b6546e
commit 2b97211612
5 changed files with 40 additions and 42 deletions

View file

@ -7,6 +7,8 @@ import com.fsck.k9.backend.api.Backend
import com.fsck.k9.backend.webdav.WebDavBackend
import com.fsck.k9.mail.ServerSettings
import com.fsck.k9.mail.store.webdav.WebDavStore
import com.fsck.k9.mail.store.webdav.WebDavStoreUriCreator
import com.fsck.k9.mail.store.webdav.WebDavStoreUriDecoder
import com.fsck.k9.mail.transport.WebDavTransport
import com.fsck.k9.mailstore.K9BackendStorage
@ -26,18 +28,18 @@ class WebDavBackendFactory(private val preferences: Preferences) : BackendFactor
}
override fun decodeStoreUri(storeUri: String): ServerSettings {
return WebDavStore.decodeUri(storeUri)
return WebDavStoreUriDecoder.decode(storeUri)
}
override fun createStoreUri(serverSettings: ServerSettings): String {
return WebDavStore.createUri(serverSettings)
return WebDavStoreUriCreator.create(serverSettings)
}
override fun decodeTransportUri(transportUri: String): ServerSettings {
return WebDavStore.decodeUri(transportUri)
return WebDavStoreUriDecoder.decode(transportUri)
}
override fun createTransportUri(serverSettings: ServerSettings): String {
return WebDavStore.createUri(serverSettings)
return WebDavStoreUriCreator.create(serverSettings)
}
}

View file

@ -22,7 +22,6 @@ import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.K9MailLib;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mail.filter.Base64;
import com.fsck.k9.mail.store.RemoteStore;
import com.fsck.k9.mail.store.StoreConfig;
@ -60,15 +59,6 @@ import static com.fsck.k9.mail.helper.UrlEncodingHelper.decodeUtf8;
*/
@SuppressWarnings("deprecation")
public class WebDavStore extends RemoteStore {
public static WebDavStoreSettings decodeUri(String uri) {
return WebDavStoreUriDecoder.decode(uri);
}
public static String createUri(ServerSettings server) {
return WebDavStoreUriCreator.create(server);
}
private ConnectionSecurity mConnectionSecurity;
private String username;
private String alias;
@ -102,7 +92,7 @@ public class WebDavStore extends RemoteStore {
WebDavStoreSettings settings;
try {
settings = WebDavStore.decodeUri(storeConfig.getStoreUri());
settings = WebDavStoreUriDecoder.decode(storeConfig.getStoreUri());
} catch (IllegalArgumentException e) {
throw new MessagingException("Error while decoding store URI", e);
}

View file

@ -17,7 +17,6 @@ public class WebDavStoreUriCreator {
* @param server The {@link ServerSettings} object that holds the server settings.
* @return A WebDavStore URI that holds the same information as the {@code server} parameter.
* @see StoreConfig#getStoreUri()
* @see WebDavStore#decodeUri(String)
*/
public static String create(ServerSettings server) {
String userEnc = encodeUtf8(server.username);

View file

@ -6,19 +6,13 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.CertificateValidationException;
import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mail.ServerSettings.Type;
import com.fsck.k9.mail.filter.Base64;
import com.fsck.k9.mail.store.StoreConfig;
import javax.net.ssl.SSLException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
@ -84,26 +78,6 @@ public class WebDavStoreTest {
when(mockClientConnectionManager.getSchemeRegistry()).thenReturn(mockSchemeRegistry);
}
@Test
public void createUri_withSetting_shouldProvideUri() {
ServerSettings serverSettings = new ServerSettings(Type.WebDAV, "example.org", 123456, ConnectionSecurity.NONE,
AuthType.PLAIN, "user", "password", null);
String result = WebDavStore.createUri(serverSettings);
assertEquals("webdav://user:password@example.org:123456/%7C%7C", result);
}
@Test
public void createUri_withSettingsWithTLS_shouldProvideSSLUri() {
ServerSettings serverSettings = new ServerSettings(Type.WebDAV, "example.org", 123456,
ConnectionSecurity.SSL_TLS_REQUIRED, AuthType.PLAIN, "user", "password", null);
String result = WebDavStore.createUri(serverSettings);
assertEquals("webdav+ssl+://user:password@example.org:123456/%7C%7C", result);
}
@Test(expected = MessagingException.class)
public void constructor_withImapStoreUri_shouldThrow() throws Exception {
StoreConfig storeConfig = createStoreConfig("imap://user:password@imap.example.org");

View file

@ -0,0 +1,33 @@
package com.fsck.k9.mail.store.webdav;
import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mail.ServerSettings.Type;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class WebDavStoreUriCreatorTest {
@Test
public void createUri_withSetting_shouldProvideUri() {
ServerSettings serverSettings = new ServerSettings(Type.WebDAV, "example.org", 123456, ConnectionSecurity.NONE,
AuthType.PLAIN, "user", "password", null);
String result = WebDavStoreUriCreator.create(serverSettings);
assertEquals("webdav://user:password@example.org:123456/%7C%7C", result);
}
@Test
public void createUri_withSettingsWithTLS_shouldProvideSSLUri() {
ServerSettings serverSettings = new ServerSettings(Type.WebDAV, "example.org", 123456,
ConnectionSecurity.SSL_TLS_REQUIRED, AuthType.PLAIN, "user", "password", null);
String result = WebDavStoreUriCreator.create(serverSettings);
assertEquals("webdav+ssl+://user:password@example.org:123456/%7C%7C", result);
}
}