Skip to content

Commit dc02798

Browse files
committed
Adapt tests
1 parent 28e7369 commit dc02798

File tree

6 files changed

+30
-29
lines changed

6 files changed

+30
-29
lines changed

lib/src/androidTest/kotlin/at/bitfire/ical4android/DmfsTaskTest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ class DmfsTaskTest(
514514
categories.addAll(arrayOf("Cat_1", "Cat 2"))
515515
}.let { result ->
516516
val id = result.getAsLong(Tasks._ID)
517-
val uri = taskList!!.tasksPropertiesSyncUri()
517+
val uri = taskList!!.tasksPropertiesUri()
518518
provider.client.query(uri, arrayOf(Category.CATEGORY_NAME), "${Properties.MIMETYPE}=? AND ${PropertyColumns.TASK_ID}=?",
519519
arrayOf(Category.CONTENT_ITEM_TYPE, id.toString()), null)!!.use { cursor ->
520520
while (cursor.moveToNext())
@@ -535,7 +535,7 @@ class DmfsTaskTest(
535535
comment = "Comment value"
536536
}.let { result ->
537537
val id = result.getAsLong(Tasks._ID)
538-
val uri = taskList!!.tasksPropertiesSyncUri()
538+
val uri = taskList!!.tasksPropertiesUri()
539539
provider.client.query(uri, arrayOf(Property.Comment.COMMENT), "${Properties.MIMETYPE}=? AND ${PropertyColumns.TASK_ID}=?",
540540
arrayOf(Property.Comment.CONTENT_ITEM_TYPE, id.toString()), null)!!.use { cursor ->
541541
if (cursor.moveToNext())
@@ -552,7 +552,7 @@ class DmfsTaskTest(
552552
comment = null
553553
}.let { result ->
554554
val id = result.getAsLong(Tasks._ID)
555-
val uri = taskList!!.tasksPropertiesSyncUri()
555+
val uri = taskList!!.tasksPropertiesUri()
556556
provider.client.query(uri, arrayOf(Property.Comment.COMMENT), "${Properties.MIMETYPE}=? AND ${PropertyColumns.TASK_ID}=?",
557557
arrayOf(Property.Comment.CONTENT_ITEM_TYPE, id.toString()), null)!!.use { cursor ->
558558
hasComment = cursor.count > 0
@@ -562,7 +562,7 @@ class DmfsTaskTest(
562562
}
563563

564564
private fun firstProperty(taskId: Long, mimeType: String): ContentValues? {
565-
val uri = taskList!!.tasksPropertiesSyncUri()
565+
val uri = taskList!!.tasksPropertiesUri()
566566
provider.client.query(uri, null, "${Properties.MIMETYPE}=? AND ${PropertyColumns.TASK_ID}=?",
567567
arrayOf(mimeType, taskId.toString()), null)!!.use { cursor ->
568568
if (cursor.moveToNext()) {
@@ -692,7 +692,7 @@ class DmfsTaskTest(
692692
assertNotNull("Couldn't add task", uri)
693693

694694
// read and parse event from calendar provider
695-
val testTask = taskList!!.findById(ContentUris.parseId(uri))
695+
val testTask = taskList!!.getTask(ContentUris.parseId(uri))
696696
try {
697697
assertNotNull("Inserted task is not here", testTask)
698698
val task2 = testTask.task
@@ -735,7 +735,7 @@ class DmfsTaskTest(
735735
task.alarms += VAlarm(java.time.Duration.ofMinutes(i.toLong()))
736736

737737
val uri = DmfsTask(taskList!!, task, "9468a4cf-0d5b-4379-a704-12f1f84100ba", null, 0).add()
738-
val task2 = taskList!!.findById(ContentUris.parseId(uri))
738+
val task2 = taskList!!.getTask(ContentUris.parseId(uri))
739739
assertEquals(1050, task2.task?.alarms?.size)
740740
}
741741

@@ -752,7 +752,7 @@ class DmfsTaskTest(
752752
val uri = DmfsTask(taskList!!, task, "9468a4cf-0d5b-4379-a704-12f1f84100ba", null, 0).add()
753753
assertNotNull(uri)
754754

755-
val testTask = taskList!!.findById(ContentUris.parseId(uri))
755+
val testTask = taskList!!.getTask(ContentUris.parseId(uri))
756756
try {
757757
// update test event in calendar
758758
val task2 = testTask.task!!
@@ -762,7 +762,7 @@ class DmfsTaskTest(
762762
testTask.update(task2)
763763

764764
// read again and verify result
765-
val updatedTask = taskList!!.findById(ContentUris.parseId(uri)).task!!
765+
val updatedTask = taskList!!.getTask(ContentUris.parseId(uri)).task!!
766766
assertEquals(task2.summary, updatedTask.summary)
767767
assertEquals(task2.location, updatedTask.location)
768768
assertEquals(task2.dtStart, updatedTask.dtStart)
@@ -785,7 +785,7 @@ class DmfsTaskTest(
785785
val uri = DmfsTask(taskList!!, task, "9468a4cf-0d5b-4379-a704-12f1f84100ba", null, 0).add()
786786
assertNotNull(uri)
787787

788-
val testTask = taskList!!.findById(ContentUris.parseId(uri))
788+
val testTask = taskList!!.getTask(ContentUris.parseId(uri))
789789
try {
790790
// read again and verify result
791791
val task2 = testTask.task!!

lib/src/androidTest/kotlin/at/bitfire/ical4android/impl/TestTaskList.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import android.content.ContentUris
1111
import android.content.ContentValues
1212
import at.bitfire.synctools.storage.tasks.DmfsTaskList
1313
import at.bitfire.ical4android.TaskProvider
14+
import at.bitfire.synctools.storage.tasks.DmfsTaskListProvider
1415
import org.dmfs.tasks.contract.TaskContract
1516

1617
object TestTaskList {
@@ -24,9 +25,9 @@ object TestTaskList {
2425
values.put(TaskContract.TaskListColumns.LIST_COLOR, 0xffff0000)
2526
values.put(TaskContract.TaskListColumns.SYNC_ENABLED, 1)
2627
values.put(TaskContract.TaskListColumns.VISIBLE, 1)
27-
val uri = DmfsTaskList.create(account, provider.client, provider.name, values)
28+
val dmfsTaskListProvider = DmfsTaskListProvider(account, provider.client, provider.name)
2829

29-
return DmfsTaskList(account, provider.client, provider.name, ContentUris.parseId(uri))
30+
return DmfsTaskList(dmfsTaskListProvider, values, provider.name)
3031
}
3132

3233
}

lib/src/androidTest/kotlin/at/bitfire/synctools/storage/tasks/ContactsBatchOperationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import at.bitfire.ical4android.util.MiscUtils.closeCompat
1616
import at.bitfire.synctools.storage.BatchOperation
1717
import at.bitfire.synctools.storage.ContactsBatchOperation
1818
import at.bitfire.synctools.storage.LocalStorageException
19+
import at.bitfire.synctools.test.BuildConfig
1920
import org.junit.After
2021
import org.junit.Before
2122
import org.junit.Rule

lib/src/androidTest/kotlin/at/bitfire/synctools/storage/tasks/DmfsTaskListTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ class DmfsTaskListTest(providerName: TaskProvider.ProviderName):
3434
info.put(TaskContract.TaskLists.VISIBLE, 1)
3535

3636
val dmfsTaskListProvider = DmfsTaskListProvider(testAccount, provider.client, providerName)
37-
val uri = dmfsTaskListProvider.createTaskList(testAccount, provider.client, providerName, info)
38-
Assert.assertNotNull(uri)
37+
val id = dmfsTaskListProvider.createTaskList(info)
38+
Assert.assertNotNull(id)
3939

40-
dmfsTaskListProvider.createTaskList()
40+
dmfsTaskListProvider.createTaskList(info)
4141

42-
return DmfsTaskList.findByID(testAccount, provider.client, providerName, ContentUris.parseId(uri))
42+
return dmfsTaskListProvider.getTaskList(id)!!
4343
}
4444

4545
@Test
@@ -50,28 +50,28 @@ class DmfsTaskListTest(providerName: TaskProvider.ProviderName):
5050
// sync URIs
5151
Assert.assertEquals(
5252
"true",
53-
taskList.taskListSyncUri().getQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER)
53+
taskList.taskListUri().getQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER)
5454
)
5555
Assert.assertEquals(
5656
testAccount.type,
57-
taskList.taskListSyncUri().getQueryParameter(TaskContract.ACCOUNT_TYPE)
57+
taskList.taskListUri().getQueryParameter(TaskContract.ACCOUNT_TYPE)
5858
)
5959
Assert.assertEquals(
6060
testAccount.name,
61-
taskList.taskListSyncUri().getQueryParameter(TaskContract.ACCOUNT_NAME)
61+
taskList.taskListUri().getQueryParameter(TaskContract.ACCOUNT_NAME)
6262
)
6363

6464
Assert.assertEquals(
6565
"true",
66-
taskList.tasksSyncUri().getQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER)
66+
taskList.taskListUri().getQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER)
6767
)
6868
Assert.assertEquals(
6969
testAccount.type,
70-
taskList.tasksSyncUri().getQueryParameter(TaskContract.ACCOUNT_TYPE)
70+
taskList.taskListUri().getQueryParameter(TaskContract.ACCOUNT_TYPE)
7171
)
7272
Assert.assertEquals(
7373
testAccount.name,
74-
taskList.tasksSyncUri().getQueryParameter(TaskContract.ACCOUNT_NAME)
74+
taskList.taskListUri().getQueryParameter(TaskContract.ACCOUNT_NAME)
7575
)
7676
} finally {
7777
// delete task list
@@ -111,7 +111,7 @@ class DmfsTaskListTest(providerName: TaskProvider.ProviderName):
111111
val parentId = ContentUris.parseId(parentContentUri)
112112

113113
// OpenTasks should provide the correct relation
114-
taskList.provider.client.query(taskList.tasksPropertiesSyncUri(), null,
114+
taskList.provider.client.query(taskList.tasksPropertiesUri(), null,
115115
"${TaskContract.Properties.TASK_ID}=?", arrayOf(childId.toString()),
116116
null, null)!!.use { cursor ->
117117
Assert.assertEquals(1, cursor.count)

lib/src/main/kotlin/at/bitfire/ical4android/DmfsTask.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class DmfsTask(
137137
}
138138
if (!hasParentRelation) {
139139
// get UID of parent task
140-
val parentContentUri = ContentUris.withAppendedId(taskList.tasksUri(), parentId)
140+
val parentContentUri = ContentUris.withAppendedId(taskList.taskListUri(), parentId)
141141
client.query(parentContentUri, arrayOf(Tasks._UID), null, null, null)?.use { cursor ->
142142
if (cursor.moveToNext()) {
143143
// add RelatedTo for parent task
@@ -342,7 +342,7 @@ class DmfsTask(
342342
fun add(): Uri {
343343
val batch = TasksBatchOperation(taskList.provider.client)
344344

345-
val builder = CpoBuilder.newInsert(taskList.tasksUri())
345+
val builder = CpoBuilder.newInsert(taskList.taskListUri())
346346
buildTask(builder, false)
347347
val idxTask = batch.nextBackrefIdx()
348348
batch += builder
@@ -618,7 +618,7 @@ class DmfsTask(
618618

619619
private fun taskSyncURI(loadProperties: Boolean = false): Uri {
620620
val id = requireNotNull(id)
621-
return ContentUris.withAppendedId(taskList.tasksUri(loadProperties), id)
621+
return ContentUris.withAppendedId(taskList.taskListUri(loadProperties), id)
622622
}
623623

624624
companion object {

lib/src/main/kotlin/at/bitfire/synctools/storage/tasks/DmfsTaskList.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import at.bitfire.synctools.storage.BatchOperation
1616
import at.bitfire.synctools.storage.LocalStorageException
1717
import at.bitfire.synctools.storage.toContentValues
1818
import org.dmfs.tasks.contract.TaskContract
19-
import java.io.FileNotFoundException
2019
import java.util.LinkedList
2120
import java.util.logging.Logger
2221

@@ -65,7 +64,7 @@ class DmfsTaskList(
6564
val tasks = LinkedList<DmfsTask>()
6665
try {
6766
val (protectedWhere, protectedWhereArgs) = whereWithTaskListId(where, whereArgs)
68-
client.query(tasksUri(), null, protectedWhere, protectedWhereArgs, null)?.use { cursor ->
67+
client.query(taskListUri(), null, protectedWhere, protectedWhereArgs, null)?.use { cursor ->
6968
while (cursor.moveToNext())
7069
tasks += DmfsTask(this, cursor.toContentValues())
7170
}
@@ -106,7 +105,7 @@ class DmfsTaskList(
106105
val client
107106
get() = provider.client
108107

109-
fun tasksUri(loadProperties: Boolean = false): Uri {
108+
fun taskListUri(loadProperties: Boolean = false): Uri {
110109
val uri = TaskContract.Tasks.getContentUri(providerName.authority).asSyncAdapter(account)
111110
return if (loadProperties)
112111
uri.buildUpon()
@@ -156,7 +155,7 @@ class DmfsTaskList(
156155
logger.fine("Touching relations to set parent_id")
157156
val batch = TasksBatchOperation(client)
158157
client.query(
159-
tasksUri(true), null,
158+
taskListUri(true), null,
160159
"${TaskContract.Tasks.LIST_ID}=? AND ${TaskContract.Tasks.PARENT_ID} IS NULL AND ${TaskContract.Property.Relation.MIMETYPE}=? AND ${TaskContract.Property.Relation.RELATED_ID} IS NOT NULL",
161160
arrayOf(id.toString(), TaskContract.Property.Relation.CONTENT_ITEM_TYPE),
162161
null, null

0 commit comments

Comments
 (0)