Skip to content

Commit

Permalink
fixed emulator test
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Kalderstam <[email protected]>
  • Loading branch information
spacecowboy committed Jan 22, 2025
1 parent 3b1886d commit 30b678e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ class OPMLTest : DIAware {
writeSampleFile()

val parser = OpmlPullParser(opmlParserHandler)
parser.parseFile(path!!.canonicalPath)
parser.parseFile(path!!.canonicalPath).leftOrNull()?.let { e ->
fail("Failed to parse file: ${e.throwable}")
}

// Verify database is correct
val actual = settingsStore.getAllSettings()

ALL_SETTINGS_WITH_VALUES.forEach { (key, expected) ->
assertEquals(expected, actual[key].toString())
ALL_SETTINGS_WITH_VALUES.toList().forEachIndexed { index, (key, expected) ->
assertEquals("$index: Setting $key, expected $expected but was ${actual[key]}", expected, actual[key].toString())
}

val actualBlocked = settingsStore.blockListPreference.first()
Expand All @@ -146,14 +148,23 @@ class OPMLTest : DIAware {
writeSampleFile()

val parser = OpmlPullParser(opmlParserHandler)
parser.parseFile(path!!.canonicalPath)
parser.parseFile(path!!.canonicalPath).leftOrNull()?.let { e ->
fail("Failed to parse file: ${e.throwable}")
}

// Verify database is correct
val seen = ArrayList<Int>()
val feeds = db.feedDao().getAllFeeds()
assertFalse("No feeds in DB!", feeds.isEmpty())
for (feed in feeds) {
val i = Integer.parseInt(feed.title.replace("[custom \"]".toRegex(), ""))
val i =
try {
val title = feed.customTitle.replace("[custom \"]".toRegex(), "").ifBlank { feed.title }
Integer.parseInt(title.replace("[custom \"]".toRegex(), ""))
} catch (e: NumberFormatException) {
fail("Failed to parse title: ${feed.title}, ${feed.customTitle}")
continue
}
seen.add(i)
assertEquals("URL doesn't match", URL("http://example.com/$i/rss.xml"), feed.url)

Expand Down Expand Up @@ -219,14 +230,23 @@ class OPMLTest : DIAware {

// Read file
val parser = OpmlPullParser(opmlParserHandler)
parser.parseFile(path!!.canonicalPath)
parser.parseFile(path!!.canonicalPath).leftOrNull()?.let { e ->
fail("Failed to parse file: ${e.throwable}")
}

// should not kill the existing stuff
val seen = ArrayList<Int>()
val feeds = db.feedDao().getAllFeeds()
assertFalse("No feeds in DB!", feeds.isEmpty())
for (feed in feeds) {
val i = Integer.parseInt(feed.title.replace("[custom \"]".toRegex(), ""))
val i =
try {
val title = feed.customTitle.replace("[custom \"]".toRegex(), "").ifBlank { feed.title }
Integer.parseInt(title.replace("[custom \"]".toRegex(), ""))
} catch (e: NumberFormatException) {
fail("Failed to parse title: ${feed.title}, ${feed.customTitle}")
continue
}
seen.add(i)
assertEquals(URL("http://example.com/$i/rss.xml"), feed.url)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.nononsenseapps.feeder

import android.app.Application
import android.app.job.JobScheduler
import android.content.ContentResolver
import android.content.SharedPreferences
import android.os.Build.VERSION.SDK_INT
import android.util.Log
import android.widget.Toast
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.getSystemService
import androidx.preference.PreferenceManager
import coil.ImageLoader
import coil.ImageLoaderFactory
Expand Down Expand Up @@ -83,6 +85,7 @@ class FeederApplication : Application(), DIAware, ImageLoaderFactory {
import(archModelModule)

bind<ContentResolver>() with singleton { contentResolver }
bind<JobScheduler>() with singleton { getSystemService(JobScheduler::class.java) }
bind<ToastMaker>() with
singleton {
object : ToastMaker {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.kodein.di.DI
import org.kodein.di.DIAware
import org.kodein.di.android.closestDI
import org.kodein.di.instance
import org.kodein.di.instanceOrNull
import java.time.Duration

const val ARG_FORCE_NETWORK = "force_network"
Expand Down Expand Up @@ -109,7 +110,7 @@ fun schedulePeriodicRssSync(
) {
val repository: Repository by di.instance()
val context: Application by di.instance()
val jobScheduler: JobScheduler? = context.getSystemService()
val jobScheduler: JobScheduler? by di.instanceOrNull()

if (jobScheduler == null) {
Log.e(RssSyncJob.LOG_TAG, "JobScheduler not available")
Expand All @@ -118,7 +119,7 @@ fun schedulePeriodicRssSync(

if (repository.syncFrequency.value.minutes < 1) {
// Cancel and return
jobScheduler.cancel(BackgroundJobId.RSS_SYNC_PERIODIC.jobId)
jobScheduler?.cancel(BackgroundJobId.RSS_SYNC_PERIODIC.jobId)
return
}

Expand All @@ -139,8 +140,8 @@ fun schedulePeriodicRssSync(
.setPersisted(true)
.build()

if (replace || jobScheduler.getMyPendingJob(BackgroundJobId.RSS_SYNC_PERIODIC.jobId) == null) {
jobScheduler.schedule(jobInfo)
if (replace || jobScheduler?.getMyPendingJob(BackgroundJobId.RSS_SYNC_PERIODIC.jobId) == null) {
jobScheduler?.schedule(jobInfo)
}
}

Expand Down

0 comments on commit 30b678e

Please sign in to comment.