From a44df88ac6a292542ce57602e29fccdcb5e733ba Mon Sep 17 00:00:00 2001 From: Sunik Kupfer Date: Wed, 6 Nov 2024 15:24:53 +0100 Subject: [PATCH] Add test --- .../davdroid/resource/LocalAddressBookTest.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/src/androidTest/kotlin/at/bitfire/davdroid/resource/LocalAddressBookTest.kt b/app/src/androidTest/kotlin/at/bitfire/davdroid/resource/LocalAddressBookTest.kt index a6651b311..4be85ac12 100644 --- a/app/src/androidTest/kotlin/at/bitfire/davdroid/resource/LocalAddressBookTest.kt +++ b/app/src/androidTest/kotlin/at/bitfire/davdroid/resource/LocalAddressBookTest.kt @@ -12,6 +12,7 @@ import android.content.Context import android.provider.ContactsContract import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.GrantPermissionRule +import at.bitfire.davdroid.db.Collection import at.bitfire.vcard4android.Contact import at.bitfire.vcard4android.GroupMethod import at.bitfire.vcard4android.LabeledProperty @@ -19,6 +20,8 @@ import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest import ezvcard.property.Telephone +import io.mockk.every +import io.mockk.mockk import java.util.LinkedList import javax.inject.Inject import org.junit.After @@ -26,6 +29,7 @@ import org.junit.AfterClass import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotNull +import org.junit.Assert.assertTrue import org.junit.Before import org.junit.BeforeClass import org.junit.ClassRule @@ -123,6 +127,21 @@ class LocalAddressBookTest { assertEquals("Test Group", group.displayName) } + /** + * Tests the calculation of read only state is correct + */ + @Test + fun test_shouldBeReadOnly() { + val collectionReadOnly = mockk { every { readOnly() } returns true } + assertTrue(LocalAddressBook.shouldBeReadOnly(collectionReadOnly, null)) + assertTrue(LocalAddressBook.shouldBeReadOnly(collectionReadOnly, false)) + assertTrue(LocalAddressBook.shouldBeReadOnly(collectionReadOnly, true)) + + val collectionNotReadOnly = mockk { every { readOnly() } returns false } + assertFalse(LocalAddressBook.shouldBeReadOnly(collectionNotReadOnly, null)) + assertFalse(LocalAddressBook.shouldBeReadOnly(collectionNotReadOnly, false)) + assertTrue(LocalAddressBook.shouldBeReadOnly(collectionNotReadOnly, true)) + } companion object {