Skip to content

Commit

Permalink
Update KDoc and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc2822 committed Oct 9, 2024
1 parent 271576b commit 48e3ac6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 11 additions & 3 deletions app/src/androidTest/kotlin/at/bitfire/davdroid/sync/SyncerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import io.mockk.spyk
import io.mockk.verify
import okhttp3.HttpUrl.Companion.toHttpUrl
import org.junit.After
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
Expand Down Expand Up @@ -84,10 +85,13 @@ class SyncerTest {
val localCollection = mockk<LocalTestCollection>()
every { localCollection.collectionUrl } returns "http://delete.the/collection"
every { localCollection.deleteCollection() } returns true
every { localCollection.title } returns "Collection to be deleted locally"

// Should delete the localCollection if dbCollection (remote) does not exist
syncer.updateCollections(listOf(localCollection), dbCollections = emptyMap())
val localCollections = mutableListOf(localCollection)
syncer.updateCollections(localCollections, dbCollections = emptyMap())
verify(exactly = 1) { localCollection.deleteCollection() }
assertTrue(localCollections.isEmpty())
}

@Test
Expand All @@ -99,9 +103,11 @@ class SyncerTest {
every { localCollection.collectionUrl } returns "http://update.the/collection"

// Should update the localCollection if it exists ...
val newCollections = syncer.updateCollections(listOf(localCollection), dbCollections)
val localCollections = mutableListOf(localCollection)
val newCollections = syncer.updateCollections(localCollections, dbCollections)
verify(exactly = 1) { syncer.update(localCollection, dbCollection) }
// ... and remove it from the "new found" collections which are to be created
assertArrayEquals(arrayOf(localCollection), localCollections.toTypedArray())
assertTrue(newCollections.isEmpty())
}

Expand All @@ -112,8 +118,10 @@ class SyncerTest {
every { dbCollection.url } returns "http://newly.found/collection".toHttpUrl()

// Should return the new collection, because it was not updated
val newCollections = syncer.updateCollections(listOf(), dbCollections)
val localCollections = mutableListOf<LocalTestCollection>()
val newCollections = syncer.updateCollections(localCollections, dbCollections)
assertEquals(dbCollection, newCollections["http://newly.found/collection".toHttpUrl()])
assertTrue(localCollections.isEmpty())
}


Expand Down
8 changes: 6 additions & 2 deletions app/src/main/kotlin/at/bitfire/davdroid/sync/Syncer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,16 @@ abstract class Syncer<CollectionType: LocalCollection<*>>(

/**
* Updates and deletes local collections. Specifically:
* - Deletes local collections if corresponding database collections are missing.
*
* - Deletes local collections if corresponding database collections are missing. If
* a local collection is removed because it's not in [dbCollections], **it becomes also removed from [localCollections]!**
*
* - Updates local collections with possibly new info from corresponding database collections.
* - Determines new database collections to be also created as local collections.
*
* @param localCollections The local collections to be updated or deleted
* @param localCollections The local collections to be updated or deleted. May be modified by this method.
* @param dbCollections The database collections possibly containing new information
*
* @return New found database collections to be created in provider
*/
@VisibleForTesting
Expand Down

0 comments on commit 48e3ac6

Please sign in to comment.