Fix instrumentation tests

Although they are very old, at least they do not break anymore in case
anyone wants to execute them.
This commit is contained in:
Adolfo Santiago 2022-05-28 09:05:51 +02:00
parent 3b268ae745
commit 249cdf2ddf
No known key found for this signature in database
GPG key ID: 244D6F9A317B4A65
3 changed files with 131 additions and 111 deletions

View file

@ -3,7 +3,7 @@ package com.keylesspalace.tusky
import androidx.room.testing.MigrationTestHelper import androidx.room.testing.MigrationTestHelper
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.runner.AndroidJUnit4
import com.keylesspalace.tusky.db.AppDatabase import com.keylesspalace.tusky.db.AppDatabase
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Rule import org.junit.Rule

View file

@ -1,10 +1,15 @@
package com.keylesspalace.tusky package com.keylesspalace.tusky
import androidx.room.Room import androidx.room.Room
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import com.keylesspalace.tusky.db.* import androidx.test.runner.AndroidJUnit4
import com.keylesspalace.tusky.db.AppDatabase
import com.keylesspalace.tusky.db.TimelineAccountEntity
import com.keylesspalace.tusky.db.TimelineDao
import com.keylesspalace.tusky.db.TimelineStatusEntity
import com.keylesspalace.tusky.db.TimelineStatusWithAccount
import com.keylesspalace.tusky.entity.Status import com.keylesspalace.tusky.entity.Status
import com.keylesspalace.tusky.entity.Status.Visibility.PRIVATE
import com.keylesspalace.tusky.repository.TimelineRepository import com.keylesspalace.tusky.repository.TimelineRepository
import org.junit.After import org.junit.After
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
@ -37,16 +42,18 @@ class TimelineDAOTest {
val ignoredOne = makeStatus(statusId = 1) val ignoredOne = makeStatus(statusId = 1)
val ignoredTwo = makeStatus(accountId = 2) val ignoredTwo = makeStatus(accountId = 2)
for ((status, author, reblogger) in listOf(setOne, setTwo, ignoredOne, ignoredTwo)) { for((status, author, reblogger) in listOf(setOne, setTwo, ignoredOne, ignoredTwo)) {
timelineDao.insertInTransaction(status, author, reblogger) timelineDao.insertInTransaction(status, author, reblogger)
} }
val resultsFromDb = timelineDao.getStatusesForAccount(setOne.first.timelineUserId, val resultsFromDb = timelineDao.getStatusesForAccount(
maxId = "21", sinceId = ignoredOne.first.serverId, limit = 10) setOne.first.timelineUserId,
maxId = "21", sinceId = ignoredOne.first.serverId, limit = 10
)
.blockingGet() .blockingGet()
assertEquals(2, resultsFromDb.size) assertEquals(2, resultsFromDb.size)
for ((set, fromDb) in listOf(setTwo, setOne).zip(resultsFromDb)) { for((set, fromDb) in listOf(setTwo, setOne).zip(resultsFromDb)) {
val (status, author, reblogger) = set val (status, author, reblogger) = set
assertEquals(status, fromDb.status) assertEquals(status, fromDb.status)
assertEquals(author, fromDb.account) assertEquals(author, fromDb.account)
@ -97,7 +104,12 @@ class TimelineDAOTest {
accountId = 2 accountId = 2
) )
for ((status, author, reblogAuthor) in listOf(oldThisAccount, oldAnotherAccount, recentThisAccount, recentAnotherAccount)) { for((status, author, reblogAuthor) in listOf(
oldThisAccount,
oldAnotherAccount,
recentThisAccount,
recentAnotherAccount
)) {
timelineDao.insertInTransaction(status, author, reblogAuthor) timelineDao.insertInTransaction(status, author, reblogAuthor)
} }
@ -125,9 +137,13 @@ class TimelineDAOTest {
makeStatus(statusId = 1) makeStatus(statusId = 1)
) )
timelineDao.deleteRange(1, oldStatuses.last().first.serverId, oldStatuses.first().first.serverId) timelineDao.deleteRange(
1,
oldStatuses.last().first.serverId,
oldStatuses.first().first.serverId
)
for ((status, author, reblogAuthor) in oldStatuses) { for((status, author, reblogAuthor) in oldStatuses) {
timelineDao.insertInTransaction(status, author, reblogAuthor) timelineDao.insertInTransaction(status, author, reblogAuthor)
} }
@ -137,9 +153,13 @@ class TimelineDAOTest {
makeStatus(statusId = 1) makeStatus(statusId = 1)
) )
timelineDao.deleteRange(1, newStatuses.last().first.serverId, newStatuses.first().first.serverId) timelineDao.deleteRange(
1,
newStatuses.last().first.serverId,
newStatuses.first().first.serverId
)
for ((status, author, reblogAuthor) in newStatuses) { for((status, author, reblogAuthor) in newStatuses) {
timelineDao.insertInTransaction(status, author, reblogAuthor) timelineDao.insertInTransaction(status, author, reblogAuthor)
} }
@ -171,7 +191,7 @@ class TimelineDAOTest {
false false
) )
val reblogAuthor = if (reblog) { val reblogAuthor = if(reblog) {
TimelineAccountEntity( TimelineAccountEntity(
"R$authorServerId", "R$authorServerId",
accountId, accountId,
@ -204,14 +224,14 @@ class TimelineDAOTest {
favourited = even, favourited = even,
sensitive = !even, sensitive = !even,
spoilerText = "spoier$statusId", spoilerText = "spoier$statusId",
visibility = Status.Visibility.PRIVATE, visibility = PRIVATE,
attachments = "attachments$accountId", attachments = "attachments$accountId",
mentions = "mentions$accountId", mentions = "mentions$accountId",
application = "application$accountId", application = "application$accountId",
reblogServerId = if (reblog) (statusId * 100).toString() else null, reblogServerId = if(reblog) (statusId * 100).toString() else null,
reblogAccountId = reblogAuthor?.serverId, reblogAccountId = reblogAuthor?.serverId,
poll = null, poll = null,
muted = false pleroma = null
) )
return Triple(status, author, reblogAuthor) return Triple(status, author, reblogAuthor)
} }
@ -241,7 +261,7 @@ class TimelineDAOTest {
reblogServerId = null, reblogServerId = null,
reblogAccountId = null, reblogAccountId = null,
poll = null, poll = null,
muted = false pleroma = null
) )
} }