From bb45820ae8e5431b0dd3f85ea63487e20dc411fe Mon Sep 17 00:00:00 2001 From: davidoskky Date: Tue, 7 Feb 2023 20:44:34 +0100 Subject: [PATCH] Fix tests --- androidApp/src/test/kotlin/RepositoryTest.kt | 68 +++++++++++--------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/androidApp/src/test/kotlin/RepositoryTest.kt b/androidApp/src/test/kotlin/RepositoryTest.kt index ec307b9..af41ab5 100644 --- a/androidApp/src/test/kotlin/RepositoryTest.kt +++ b/androidApp/src/test/kotlin/RepositoryTest.kt @@ -303,6 +303,7 @@ class RepositoryTest { repository.setSourceFilter(SelfossModel.Source( 1, "Test", + 0, listOf("tags"), SPOUT, "", @@ -609,19 +610,19 @@ class RepositoryTest { fun get_sources() { val (sources, sourcesDB) = prepareSources() initializeRepository() - var testSources: List? + var testSources: List runBlocking { - testSources = repository.getSources() + testSources = repository.getSourcesDetails() } - assertSame(sources, testSources) + assertEquals(sources.map { SelfossModel.Source(it) }, testSources) assertNotEquals(sourcesDB.map { it.toView() }, testSources) - coVerify(exactly = 1) { api.sources() } + coVerify(exactly = 1) { api.sourcesDetailed() } } - private fun prepareSources(): Pair, List> { + private fun prepareSources(): Pair, List> { val sources = arrayListOf( - SelfossModel.Source( + SelfossModel.SourceDetail( 1, "First source", listOf("Test", "second"), @@ -630,7 +631,7 @@ class RepositoryTest { IMAGE_URL_2, SelfossModel.SourceParams("url") ), - SelfossModel.Source( + SelfossModel.SourceDetail( 2, "Second source", listOf("second"), @@ -644,6 +645,7 @@ class RepositoryTest { SOURCE( "1", "First DB source", + 3, "Test,second", SPOUT, "", @@ -653,6 +655,7 @@ class RepositoryTest { SOURCE( "2", "Second source", + null, "second", SPOUT, "", @@ -661,7 +664,7 @@ class RepositoryTest { ) ) - coEvery { api.sources() } returns StatusAndData(success = true, data = sources) + coEvery { api.sourcesDetailed() } returns StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB return Pair(sources, sourcesDB) } @@ -675,13 +678,13 @@ class RepositoryTest { initializeRepository() var testSources: List? runBlocking { - testSources = repository.getSources() + testSources = repository.getSourcesDetails() // Sources will be fetched from the database on the second call, thus testSources != sources - testSources = repository.getSources() + testSources = repository.getSourcesDetails() } - coVerify(exactly = 1) { api.sources() } - assertNotSame(sources, testSources) + coVerify(exactly = 1) { api.sourcesDetailed() } + assertNotEquals(sources.map { SelfossModel.Source(it) }, testSources) assertEquals(sourcesDB.map { it.toView() }, testSources) verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() } } @@ -693,13 +696,13 @@ class RepositoryTest { every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns false initializeRepository() - var testSources: List? + var testSources: List runBlocking { - testSources = repository.getSources() + testSources = repository.getSourcesDetails() } - assertSame(sources, testSources) - coVerify(exactly = 1) { api.sources() } + assertEquals(sources.map { SelfossModel.Source(it) }, testSources) + coVerify(exactly = 1) { api.sourcesDetailed() } verify(exactly = 0) { db.sourcesQueries } } @@ -710,13 +713,13 @@ class RepositoryTest { every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false initializeRepository() - var testSources: List? + var testSources: List runBlocking { - testSources = repository.getSources() + testSources = repository.getSourcesDetails() } - assertSame(sources, testSources) - coVerify(exactly = 1) { api.sources() } + assertEquals(sources.map { SelfossModel.Source(it) }, testSources) + coVerify(exactly = 1) { api.sourcesDetailed() } verify(atLeast = 1) { db.sourcesQueries } } @@ -724,13 +727,13 @@ class RepositoryTest { fun get_sources_without_connection() { val (_, sourcesDB) = prepareSources() initializeRepository(MutableStateFlow(false)) - var testSources: List? + var testSources: List runBlocking { - testSources = repository.getSources() + testSources = repository.getSourcesDetails() } assertEquals(sourcesDB.map { it.toView() }, testSources) - coVerify(exactly = 0) { api.sources() } + coVerify(exactly = 0) { api.sourcesDetailed() } verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() } } @@ -741,13 +744,13 @@ class RepositoryTest { every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns true initializeRepository(MutableStateFlow(false)) - var testSources: List? + var testSources: List runBlocking { - testSources = repository.getSources() + testSources = repository.getSourcesDetails() } assertEquals(emptyList(), testSources) - coVerify(exactly = 0) { api.sources() } + coVerify(exactly = 0) { api.sourcesDetailed() } verify(exactly = 0) { db.sourcesQueries.sources().executeAsList() } } @@ -758,13 +761,13 @@ class RepositoryTest { every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isUpdateSourcesEnabled() } returns false initializeRepository(MutableStateFlow(false)) - var testSources: List? + var testSources: List runBlocking { - testSources = repository.getSources() + testSources = repository.getSourcesDetails() } assertEquals(sourcesDB.map { it.toView() }, testSources) - coVerify(exactly = 0) { api.sources() } + coVerify(exactly = 0) { api.sourcesDetailed() } verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() } } @@ -775,13 +778,13 @@ class RepositoryTest { every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false initializeRepository(MutableStateFlow(false)) - var testSources: List? + var testSources: List runBlocking { - testSources = repository.getSources() + testSources = repository.getSourcesDetails() } assertEquals(sourcesDB.map { it.toView() }, testSources) - coVerify(exactly = 0) { api.sources() } + coVerify(exactly = 0) { api.sourcesDetailed() } verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() } } @@ -1105,6 +1108,7 @@ class RepositoryTest { SelfossModel.Source( 1, "First source", + 5, listOf("Test", "second"), SPOUT, "",