Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01f50790 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

refactor: sanitize getBuildVersionInfo() prototype returning non-nullable

parent bb05b155
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -41,8 +41,8 @@ class FDroidRepository @Inject constructor(
            }
    }

    suspend fun getBuildVersionInfo(packageName: String): List<BuildInfo>? {
        return getFdroidApiResponse(packageName)?.body()?.builds
    suspend fun getBuildVersionInfo(packageName: String): List<BuildInfo> {
        return getFdroidApiResponse(packageName)?.body()?.builds ?: emptyList()
    }

    override suspend fun getAuthorName(application: Application): String {
+1 −1
Original line number Diff line number Diff line
@@ -389,7 +389,7 @@ class UpdatesManagerImpl @Inject constructor(
        // Received list has build info of the latest version at the bottom.
        // We want it at the top.
        val builds = handleNetworkResult {
            fDroidRepository.getBuildVersionInfo(packageName)?.asReversed() ?: listOf()
            fDroidRepository.getBuildVersionInfo(packageName).asReversed()
        }.data

        val matchingIndex = builds?.find {
+4 −4
Original line number Diff line number Diff line
@@ -129,13 +129,13 @@ class FDroidRepositoryTest {
    }

    @Test
    fun getBuildVersionInfo_returnsNullWhenRequestFails() = runTest {
    fun getBuildVersionInfo_returnsEmptyListWhenRequestFails() = runTest {
        coEvery { fdroidApi.getFdroidInfoForPackage("org.example.app") } throws
            InterruptedIOException("timeout")

        val buildVersionInfo = repository.getBuildVersionInfo("org.example.app")

        assertThat(buildVersionInfo).isNull()
        assertThat(buildVersionInfo).isEmpty()
    }

    @Test
@@ -150,8 +150,8 @@ class FDroidRepositoryTest {
        val buildVersionInfo = repository.getBuildVersionInfo("org.example.app")

        assertThat(buildVersionInfo).hasSize(2)
        assertThat(buildVersionInfo?.map { it.versionCode }).containsExactly("123", "124").inOrder()
        assertThat(buildVersionInfo?.map { it.versionName }).containsExactly("1.2.3", "1.2.4").inOrder()
        assertThat(buildVersionInfo.map { it.versionCode }).containsExactly("123", "124").inOrder()
        assertThat(buildVersionInfo.map { it.versionName }).containsExactly("1.2.3", "1.2.4").inOrder()
    }

    @Test