Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c6c39d92 authored by shamim-emon's avatar shamim-emon
Browse files

SettingsImporter::getImportStreamContents throw exception when both global and...

SettingsImporter::getImportStreamContents throw exception when both global and account setting is absent
parent fb561e3c
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ class SettingsImporter internal constructor(
     *
     * @throws SettingsImportExportException In case of an error.
     */
    @Suppress("TooGenericExceptionCaught")
    @Suppress("TooGenericExceptionCaught", "ThrowsCount")
    @Throws(SettingsImportExportException::class)
    fun getImportStreamContents(inputStream: InputStream): ImportContents {
        try {
@@ -46,7 +46,10 @@ class SettingsImporter internal constructor(
                )
            }

            // TODO: throw exception if neither global settings nor account settings could be found
            if (!globalSettings && accounts.isEmpty()) {
                throw SettingsImportExportException("Neither global settings nor account settings could be found")
            }

            return ImportContents(globalSettings, accounts)
        } catch (e: SettingsImportExportException) {
            throw e
+15 −0
Original line number Diff line number Diff line
@@ -320,4 +320,19 @@ class SettingsImporterTest : K9RobolectricTest() {
            }
        }
    }

    @Test
    fun `getImportStreamContents() should throw when no setting is present in inputStream`() {
        val inputStream =
            """
            <k9settings format="1" version="1">
              <accounts>
              </accounts>
            </k9settings>
            """.trimIndent().byteInputStream()

        assertFailure {
            settingsImporter.getImportStreamContents(inputStream)
        }.isInstanceOf<SettingsImportExportException>()
    }
}