Skip to content

Commit

Permalink
RcloneProviderTest: Use Sequence instead of Iterator
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
  • Loading branch information
chenxiaolong committed Oct 13, 2024
1 parent 5f31eab commit 066e946
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions app/src/androidTest/java/com/chiller3/rsaf/RcloneProviderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,8 @@ class RcloneProviderTest {
private const val MIME_TEXT = "text/plain"
private const val MIME_DIR = DocumentsContract.Document.MIME_TYPE_DIR

private fun Cursor.iterate(): Iterator<Cursor> = iterator {
if (moveToFirst()) {
while (true) {
yield(this@iterate)

if (!moveToNext()) {
break
}
}
}
private fun Cursor.asSequence() = generateSequence(seed = takeIf { it.moveToFirst() }) {
takeIf { it.moveToNext() }
}

private fun <R> retryTimeout(timeoutMs: Long, intervalMs: Long = 100, block: () -> R): R {
Expand Down Expand Up @@ -150,7 +142,7 @@ class RcloneProviderTest {
val indexDocumentId = cursor.getColumnIndexOrThrow(
DocumentsContract.Root.COLUMN_DOCUMENT_ID)

for (row in cursor.iterate()) {
for (row in cursor.asSequence()) {
if (row.getString(indexRootId) == remote) {
assertEquals(docFromRoot(), row.getString(indexDocumentId))

Expand Down Expand Up @@ -203,7 +195,7 @@ class RcloneProviderTest {
val indexLastModified = cursor.getColumnIndexOrThrow(
DocumentsContract.Document.COLUMN_LAST_MODIFIED)

for (row in cursor.iterate()) {
for (row in cursor.asSequence()) {
val documentId = row.getString(indexDocumentId)
val mimeType = row.getString(indexMimeType)
val displayName = row.getString(indexDisplayName)
Expand Down

0 comments on commit 066e946

Please sign in to comment.