Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
Signed-off-by: Arnau Mora Gras <[email protected]>
  • Loading branch information
ArnyminerZ committed Apr 10, 2024
1 parent 2ee5726 commit 825306e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
34 changes: 21 additions & 13 deletions app/src/androidTest/java/at/bitfire/icsdroid/CalendarFetcherTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import androidx.test.platform.app.InstrumentationRegistry
import at.bitfire.icsdroid.HttpUtils.toAndroidUri
import at.bitfire.icsdroid.test.BuildConfig
import at.bitfire.icsdroid.test.R
import java.io.IOException
import java.io.InputStream
import java.net.HttpURLConnection
import java.util.LinkedList
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import okhttp3.MediaType
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
Expand All @@ -21,10 +27,6 @@ import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.BeforeClass
import org.junit.Test
import java.io.IOException
import java.io.InputStream
import java.net.HttpURLConnection
import java.util.*

class CalendarFetcherTest {

Expand Down Expand Up @@ -55,9 +57,11 @@ class CalendarFetcherTest {

var ical: String? = null
val fetcher = object: CalendarFetcher(appContext, uri) {
override fun onSuccess(data: InputStream, contentType: MediaType?, eTag: String?, lastModified: Long?, displayName: String?) {
override suspend fun onSuccess(data: InputStream, contentType: MediaType?, eTag: String?, lastModified: Long?, displayName: String?) {
ical = IOUtils.toString(data, Charsets.UTF_8)
data.close()
withContext(Dispatchers.IO) {
data.close()
}
}
}
runBlocking {
Expand Down Expand Up @@ -90,11 +94,13 @@ class CalendarFetcherTest {
var etag: String? = null
var lastmod: Long? = null
val fetcher = object: CalendarFetcher(appContext, server.url("/").toAndroidUri()) {
override fun onSuccess(data: InputStream, contentType: MediaType?, eTag: String?, lastModified: Long?, displayName: String?) {
override suspend fun onSuccess(data: InputStream, contentType: MediaType?, eTag: String?, lastModified: Long?, displayName: String?) {
ical = IOUtils.toString(data, Charsets.UTF_8)
etag = eTag
lastmod = lastModified
data.close()
withContext(Dispatchers.IO) {
data.close()
}
}
}
runBlocking {
Expand Down Expand Up @@ -132,9 +138,11 @@ class CalendarFetcherTest {
redirects += target
super.onRedirect(httpCode, target)
}
override fun onSuccess(data: InputStream, contentType: MediaType?, eTag: String?, lastModified: Long?, displayName: String?) {
override suspend fun onSuccess(data: InputStream, contentType: MediaType?, eTag: String?, lastModified: Long?, displayName: String?) {
ical = IOUtils.toString(data, Charsets.UTF_8)
data.close()
withContext(Dispatchers.IO) {
data.close()
}
}
}
runBlocking {
Expand Down Expand Up @@ -165,7 +173,7 @@ class CalendarFetcherTest {
var e: Exception? = null
runBlocking {
object : CalendarFetcher(appContext, server.url("/").toAndroidUri()) {
override fun onError(error: Exception) {
override suspend fun onError(error: Exception) {
e = error
}
}.fetch()
Expand All @@ -182,7 +190,7 @@ class CalendarFetcherTest {
var notModified = false
runBlocking {
object : CalendarFetcher(appContext, server.url("/").toAndroidUri()) {
override fun onNotModified() {
override suspend fun onNotModified() {
notModified = true
}
}.fetch()
Expand All @@ -199,7 +207,7 @@ class CalendarFetcherTest {
var e: Exception? = null
runBlocking {
object : CalendarFetcher(appContext, server.url("/").toAndroidUri()) {
override fun onError(error: Exception) {
override suspend fun onError(error: Exception) {
e = error
}
}.fetch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ import at.bitfire.icsdroid.db.dao.CredentialsDao
import at.bitfire.icsdroid.db.dao.SubscriptionsDao
import at.bitfire.icsdroid.db.entity.Subscription
import kotlinx.coroutines.runBlocking
import org.junit.*
import org.junit.Assert.*
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
import org.junit.Test

class CalendarToRoomMigrationTest {

Expand Down Expand Up @@ -158,7 +165,7 @@ class CalendarToRoomMigrationTest {
}

@Test
fun testMigrateFromV2_1() {
fun testMigrateFromV2_1() = runBlocking {
// prepare: create local calendar plus subscription with subscription.id = LocalCalendar.id,
// but with calendarId=null and COLUMN_MANAGED_BY_DB=null
val calendar = createCalendar()
Expand Down

0 comments on commit 825306e

Please sign in to comment.