Skip to content

Commit

Permalink
SettingsImporter::getImportStreamContents throw exception when both g…
Browse files Browse the repository at this point in the history
…lobal and account setting is absent
  • Loading branch information
shamim-emon committed Jan 10, 2025
1 parent fb561e3 commit 482ca1a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ class SettingsImporter internal constructor(
)
}

// TODO: throw exception if neither global settings nor account settings could be found
val hasAccountsWithSettings = imported.accounts.any { it.settings != null }
if(!globalSettings && !hasAccountsWithSettings)
throw SettingsImportExportException("Neither global settings nor account settings could be found")

return ImportContents(globalSettings, accounts)
} catch (e: SettingsImportExportException) {
throw e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ class SettingsImporterTest : K9RobolectricTest() {
<email>[email protected]</email>
</identity>
</identities>
<settings>
<value key="a">b</value>
</settings>
</account>
</accounts>
</k9settings>
Expand Down Expand Up @@ -302,6 +305,9 @@ class SettingsImporterTest : K9RobolectricTest() {
<email>[email protected]</email>
</identity>
</identities>
<settings>
<value key="a">b</value>
</settings>
</account>
</accounts>
</k9settings>
Expand All @@ -320,4 +326,29 @@ class SettingsImporterTest : K9RobolectricTest() {
}
}
}

@Test
fun `getImportStreamContents() should throw when no setting is present in inputStream`() {
val accountUuid = UUID.randomUUID().toString()
val inputStream =
"""
<k9settings format="1" version="1">
<accounts>
<account uuid="$accountUuid">
<name></name>
<identities>
<identity>
<email>[email protected]</email>
</identity>
</identities>
</account>
</accounts>
</k9settings>
""".trimIndent().byteInputStream()

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

}
}

0 comments on commit 482ca1a

Please sign in to comment.