From f457de38211f10e49e5a7531f83497bc4154f933 Mon Sep 17 00:00:00 2001 From: GoneUp Date: Tue, 10 Jan 2017 21:03:31 +0100 Subject: [PATCH] Added tests --- .../k9/preferences/SettingsImporterTest.java | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/k9mail/src/test/java/com/fsck/k9/preferences/SettingsImporterTest.java b/k9mail/src/test/java/com/fsck/k9/preferences/SettingsImporterTest.java index 40a234d2f..de722948c 100644 --- a/k9mail/src/test/java/com/fsck/k9/preferences/SettingsImporterTest.java +++ b/k9mail/src/test/java/com/fsck/k9/preferences/SettingsImporterTest.java @@ -109,8 +109,26 @@ public class SettingsImporterTest { } @Test - public void parseSettings_account_cram_md5() throws SettingsImportExportException { + public void parseSettings_account_identities() throws SettingsImportExportException { + String validUUID = UUID.randomUUID().toString(); + InputStream inputStream = new StringInputStream("" + + "Account" + + "user@gmail.com" + + ""); + List accountUuids = new ArrayList<>(); + accountUuids.add("1"); + SettingsImporter.Imported results = SettingsImporter.parseSettings(inputStream, true, accountUuids, true); + + assertEquals(1, results.accounts.size()); + assertEquals(validUUID, results.accounts.get(validUUID).uuid); + assertEquals(1, results.accounts.get(validUUID).identities.size()); + assertEquals("user@gmail.com", results.accounts.get(validUUID).identities.get(0).email); + } + + + @Test + public void parseSettings_account_cram_md5() throws SettingsImportExportException { String validUUID = UUID.randomUUID().toString(); InputStream inputStream = new StringInputStream("" + "Account" + @@ -148,7 +166,7 @@ public class SettingsImporterTest { ""); List accountUuids = new ArrayList<>(); accountUuids.add(validUUID); - + SettingsImporter.ImportResults results = SettingsImporter.importSettings( RuntimeEnvironment.application, inputStream, true, accountUuids, false); @@ -161,4 +179,35 @@ public class SettingsImporterTest { .getAccount(validUUID).isEnabled()); } + @Test + public void getImportStreamContents_account() throws SettingsImportExportException { + String validUUID = UUID.randomUUID().toString(); + InputStream inputStream = new StringInputStream("" + + "Account" + + "user@gmail.com" + + ""); + + SettingsImporter.ImportContents results = SettingsImporter.getImportStreamContents(inputStream); + + assertEquals(false, results.globalSettings); + assertEquals(1, results.accounts.size()); + assertEquals("Account", results.accounts.get(0).name); + assertEquals(validUUID, results.accounts.get(0).uuid); + } + + @Test + public void getImportStreamContents_alternativeName() throws SettingsImportExportException { + String validUUID = UUID.randomUUID().toString(); + InputStream inputStream = new StringInputStream("" + + "" + + "user@gmail.com" + + ""); + + SettingsImporter.ImportContents results = SettingsImporter.getImportStreamContents(inputStream); + + assertEquals(false, results.globalSettings); + assertEquals(1, results.accounts.size()); + assertEquals("user@gmail.com", results.accounts.get(0).name); + assertEquals(validUUID, results.accounts.get(0).uuid); + } }