Fix android tests (#2410)

This commit is contained in:
Rafał Borcz 2024-02-04 10:48:59 +01:00 committed by GitHub
parent fc91936884
commit e58a60410c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 17 deletions

2
.gitignore vendored
View File

@ -65,6 +65,8 @@ captures/
.idea/uiDesigner.xml .idea/uiDesigner.xml
.idea/runConfigurations.xml .idea/runConfigurations.xml
.idea/discord.xml .idea/discord.xml
.idea/migrations.xml
.idea/androidTestResultsUserPreferences.xml
# Keystore files # Keystore files
*.jks *.jks

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectMigrations">
<option name="MigrateToGradleLocalJavaHome">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</component>
</project>

View File

@ -142,7 +142,9 @@ android {
packagingOptions { packagingOptions {
resources { resources {
excludes += ['META-INF/library_release.kotlin_module', excludes += ['META-INF/library_release.kotlin_module',
'META-INF/library-core_release.kotlin_module'] 'META-INF/library-core_release.kotlin_module',
'META-INF/LICENSE.md',
'META-INF/LICENSE-notice.md']
} }
} }

View File

@ -14,34 +14,37 @@ import kotlin.test.assertFailsWith
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class ScramblerTest { class ScramblerTest {
private val scrambler = Scrambler(ApplicationProvider.getApplicationContext())
@Test @Test
fun encryptDecryptTest() { fun encryptDecryptTest() {
assertEquals("TEST", decrypt(encrypt("TEST", assertEquals(
ApplicationProvider.getApplicationContext()))) "TEST", scrambler.decrypt(scrambler.encrypt("TEST"))
)
} }
@Test @Test
fun emptyTextEncryptTest() { fun emptyTextEncryptTest() {
assertFailsWith<ScramblerException> { assertFailsWith<ScramblerException> {
decrypt("") scrambler.decrypt("")
} }
assertFailsWith<ScramblerException> { assertFailsWith<ScramblerException> {
encrypt("", ApplicationProvider.getApplicationContext()) scrambler.encrypt("")
} }
} }
@Test @Test
@SdkSuppress(minSdkVersion = 18) @SdkSuppress(minSdkVersion = 18)
fun emptyKeyStoreTest() { fun emptyKeyStoreTest() {
val text = encrypt("test", ApplicationProvider.getApplicationContext()) val text = scrambler.encrypt("test")
val keyStore = KeyStore.getInstance("AndroidKeyStore") val keyStore = KeyStore.getInstance("AndroidKeyStore")
keyStore.load(null) keyStore.load(null)
keyStore.deleteEntry("wulkanowy_password") keyStore.deleteEntry("wulkanowy_password")
assertFailsWith<ScramblerException> { assertFailsWith<ScramblerException> {
decrypt(text) scrambler.decrypt(text)
} }
} }
} }