From 9e8a25ed3e5725b2b8ff26fd93a8d87f183fb875 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Tue, 8 Nov 2022 22:02:20 +0100 Subject: [PATCH] Fixing tests. --- androidApp/src/test/kotlin/RepositoryTest.kt | 94 ++++++++++---------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/androidApp/src/test/kotlin/RepositoryTest.kt b/androidApp/src/test/kotlin/RepositoryTest.kt index fd16d9b..2f219bf 100644 --- a/androidApp/src/test/kotlin/RepositoryTest.kt +++ b/androidApp/src/test/kotlin/RepositoryTest.kt @@ -4,6 +4,8 @@ import bou.amine.apps.readerforselfossv2.dao.ReaderForSelfossDB import bou.amine.apps.readerforselfossv2.dao.SOURCE import bou.amine.apps.readerforselfossv2.dao.TAG import bou.amine.apps.readerforselfossv2.model.SelfossModel +import bou.amine.apps.readerforselfossv2.model.StatusAndData +import bou.amine.apps.readerforselfossv2.model.SuccessResponse import bou.amine.apps.readerforselfossv2.rest.SelfossApi import bou.amine.apps.readerforselfossv2.service.AppSettingsService import bou.amine.apps.readerforselfossv2.utils.ItemType @@ -47,11 +49,11 @@ class RepositoryTest { every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false - coEvery { api.version() } returns SelfossModel.StatusAndData( + coEvery { api.version() } returns StatusAndData( success = true, data = SelfossModel.ApiVersion("2.19-ba1e8e3", "4.0.0") ) - coEvery { api.stats() } returns SelfossModel.StatusAndData( + coEvery { api.stats() } returns StatusAndData( success = true, data = SelfossModel.Stats(NUMBER_ARTICLES, NUMBER_UNREAD, NUMBER_STARRED) ) @@ -83,7 +85,7 @@ class RepositoryTest { fun get_api_4_date_with_api_1_version_stored() { every { appSettingsService.getApiVersion() } returns 1 coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns - SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) + StatusAndData(success = true, data = generateTestApiItem()) every { appSettingsService.updateApiVersion(any()) } returns Unit initializeRepository() @@ -98,11 +100,11 @@ class RepositoryTest { @Test fun get_api_1_date_with_api_4_version_stored() { every { appSettingsService.getApiVersion() } returns 4 - coEvery { api.version() } returns SelfossModel.StatusAndData(success = false, null) + coEvery { api.version() } returns StatusAndData(success = false, null) val itemParameters = FakeItemParameters() itemParameters.datetime = "2021-04-23 11:45:32" coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns - SelfossModel.StatusAndData( + StatusAndData( success = true, data = generateTestApiItem(itemParameters) ) @@ -118,7 +120,7 @@ class RepositoryTest { @Test fun get_newer_items() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns - SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) + StatusAndData(success = true, data = generateTestApiItem()) initializeRepository() runBlocking { @@ -133,7 +135,7 @@ class RepositoryTest { @Test fun get_all_newer_items() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns - SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) + StatusAndData(success = true, data = generateTestApiItem()) initializeRepository() repository.displayedItems = ItemType.ALL @@ -149,7 +151,7 @@ class RepositoryTest { @Test fun get_newer_starred_items() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns - SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) + StatusAndData(success = true, data = generateTestApiItem()) initializeRepository() repository.displayedItems = ItemType.STARRED @@ -242,7 +244,7 @@ class RepositoryTest { @Test fun get_older_items() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns - SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) + StatusAndData(success = true, data = generateTestApiItem()) initializeRepository() repository.items = ArrayList(generateTestApiItem()) @@ -258,7 +260,7 @@ class RepositoryTest { @Test fun get_all_older_items() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns - SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) + StatusAndData(success = true, data = generateTestApiItem()) initializeRepository() repository.items = ArrayList(generateTestApiItem()) @@ -275,7 +277,7 @@ class RepositoryTest { @Test fun get_older_starred_items() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns - SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) + StatusAndData(success = true, data = generateTestApiItem()) initializeRepository() repository.displayedItems = ItemType.STARRED @@ -308,7 +310,7 @@ class RepositoryTest { @Test fun reload_badges_without_response() { - coEvery { api.stats() } returns SelfossModel.StatusAndData(success = false, data = null) + coEvery { api.stats() } returns StatusAndData(success = false, data = null) var success: Boolean @@ -376,7 +378,7 @@ class RepositoryTest { TAG("second_DB", "yellow", 0) ) - coEvery { api.tags() } returns SelfossModel.StatusAndData(success = true, data = tags) + coEvery { api.tags() } returns StatusAndData(success = true, data = tags) coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true @@ -403,7 +405,7 @@ class RepositoryTest { TAG("second_DB", "yellow", 0) ) - coEvery { api.tags() } returns SelfossModel.StatusAndData(success = true, data = tags) + coEvery { api.tags() } returns StatusAndData(success = true, data = tags) coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns true @@ -433,7 +435,7 @@ class RepositoryTest { TAG("second_DB", "yellow", 0) ) - coEvery { api.tags() } returns SelfossModel.StatusAndData(success = true, data = tags) + coEvery { api.tags() } returns StatusAndData(success = true, data = tags) coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns false @@ -460,7 +462,7 @@ class RepositoryTest { TAG("second_DB", "yellow", 0) ) - coEvery { api.tags() } returns SelfossModel.StatusAndData(success = true, data = tags) + coEvery { api.tags() } returns StatusAndData(success = true, data = tags) coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false @@ -489,7 +491,7 @@ class RepositoryTest { TAG("second_DB", "yellow", 0) ) - coEvery { api.tags() } returns SelfossModel.StatusAndData(success = true, data = tags) + coEvery { api.tags() } returns StatusAndData(success = true, data = tags) coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true @@ -517,7 +519,7 @@ class RepositoryTest { TAG("second_DB", "yellow", 0) ) - coEvery { api.tags() } returns SelfossModel.StatusAndData(success = true, data = tags) + coEvery { api.tags() } returns StatusAndData(success = true, data = tags) coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns true @@ -544,7 +546,7 @@ class RepositoryTest { TAG("second_DB", "yellow", 0) ) - coEvery { api.tags() } returns SelfossModel.StatusAndData(success = true, data = tags) + coEvery { api.tags() } returns StatusAndData(success = true, data = tags) coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns true @@ -572,7 +574,7 @@ class RepositoryTest { TAG("second_DB", "yellow", 0) ) - coEvery { api.tags() } returns SelfossModel.StatusAndData(success = true, data = tags) + coEvery { api.tags() } returns StatusAndData(success = true, data = tags) coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false @@ -627,7 +629,7 @@ class RepositoryTest { ) ) - coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) + coEvery { api.sources() } returns StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB initializeRepository() var testSources: List? @@ -681,7 +683,7 @@ class RepositoryTest { every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns true - coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) + coEvery { api.sources() } returns StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB initializeRepository() var testSources: List? @@ -738,7 +740,7 @@ class RepositoryTest { every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns false - coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) + coEvery { api.sources() } returns StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB initializeRepository() var testSources: List? @@ -792,7 +794,7 @@ class RepositoryTest { every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false - coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) + coEvery { api.sources() } returns StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB initializeRepository() var testSources: List? @@ -844,7 +846,7 @@ class RepositoryTest { ) ) - coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) + coEvery { api.sources() } returns StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB initializeRepository(MutableStateFlow(false)) var testSources: List? @@ -898,7 +900,7 @@ class RepositoryTest { every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns true - coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) + coEvery { api.sources() } returns StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB initializeRepository(MutableStateFlow(false)) var testSources: List? @@ -952,7 +954,7 @@ class RepositoryTest { every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isUpdateSourcesEnabled() } returns false - coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) + coEvery { api.sources() } returns StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB initializeRepository(MutableStateFlow(false)) var testSources: List? @@ -1006,7 +1008,7 @@ class RepositoryTest { every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false - coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) + coEvery { api.sources() } returns StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB initializeRepository(MutableStateFlow(false)) var testSources: List? @@ -1022,7 +1024,7 @@ class RepositoryTest { @Test fun create_source() { coEvery { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) } returns - SelfossModel.SuccessResponse(true) + SuccessResponse(true) initializeRepository() var response: Boolean @@ -1052,7 +1054,7 @@ class RepositoryTest { @Test fun create_source_but_response_fails() { coEvery { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) } returns - SelfossModel.SuccessResponse(false) + SuccessResponse(false) initializeRepository() var response: Boolean @@ -1082,7 +1084,7 @@ class RepositoryTest { @Test fun create_source_without_connection() { coEvery { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) } returns - SelfossModel.SuccessResponse(true) + SuccessResponse(true) initializeRepository(MutableStateFlow(false)) var response: Boolean @@ -1111,7 +1113,7 @@ class RepositoryTest { @Test fun delete_source() { - coEvery { api.deleteSource(any()) } returns SelfossModel.SuccessResponse(true) + coEvery { api.deleteSource(any()) } returns SuccessResponse(true) initializeRepository() var response: Boolean @@ -1125,7 +1127,7 @@ class RepositoryTest { @Test fun delete_source_but_response_fails() { - coEvery { api.deleteSource(any()) } returns SelfossModel.SuccessResponse(false) + coEvery { api.deleteSource(any()) } returns SuccessResponse(false) initializeRepository() var response: Boolean @@ -1139,7 +1141,7 @@ class RepositoryTest { @Test fun delete_source_without_connection() { - coEvery { api.deleteSource(any()) } returns SelfossModel.SuccessResponse(false) + coEvery { api.deleteSource(any()) } returns SuccessResponse(false) initializeRepository(MutableStateFlow(false)) var response: Boolean @@ -1153,7 +1155,7 @@ class RepositoryTest { @Test fun update_remote() { - coEvery { api.update() } returns SelfossModel.StatusAndData( + coEvery { api.update() } returns StatusAndData( success = true, data = "finished" ) @@ -1170,7 +1172,7 @@ class RepositoryTest { @Test fun update_remote_but_response_fails() { - coEvery { api.update() } returns SelfossModel.StatusAndData( + coEvery { api.update() } returns StatusAndData( success = false, data = "unallowed access" ) @@ -1187,7 +1189,7 @@ class RepositoryTest { @Test fun update_remote_with_unallowed_access() { - coEvery { api.update() } returns SelfossModel.StatusAndData( + coEvery { api.update() } returns StatusAndData( success = true, data = "unallowed access" ) @@ -1204,7 +1206,7 @@ class RepositoryTest { @Test fun update_remote_without_connection() { - coEvery { api.update() } returns SelfossModel.StatusAndData( + coEvery { api.update() } returns StatusAndData( success = true, data = "undocumented..." ) @@ -1221,7 +1223,7 @@ class RepositoryTest { @Test fun login() { - coEvery { api.login() } returns SelfossModel.SuccessResponse(success = true) + coEvery { api.login() } returns SuccessResponse(success = true) initializeRepository() var response: Boolean @@ -1235,7 +1237,7 @@ class RepositoryTest { @Test fun login_but_response_fails() { - coEvery { api.login() } returns SelfossModel.SuccessResponse(success = false) + coEvery { api.login() } returns SuccessResponse(success = false) initializeRepository() var response: Boolean @@ -1249,7 +1251,7 @@ class RepositoryTest { @Test fun login_but_without_connection() { - coEvery { api.login() } returns SelfossModel.SuccessResponse(success = true) + coEvery { api.login() } returns SuccessResponse(success = true) initializeRepository(MutableStateFlow(false)) var response: Boolean @@ -1297,9 +1299,9 @@ class RepositoryTest { any() ) } returnsMany listOf( - SelfossModel.StatusAndData(success = true, data = generateTestApiItem(itemParameter1)), - SelfossModel.StatusAndData(success = true, data = generateTestApiItem(itemParameter2)), - SelfossModel.StatusAndData(success = true, data = generateTestApiItem(itemParameter1)), + StatusAndData(success = true, data = generateTestApiItem(itemParameter1)), + StatusAndData(success = true, data = generateTestApiItem(itemParameter2)), + StatusAndData(success = true, data = generateTestApiItem(itemParameter1)), ) initializeRepository() @@ -1323,7 +1325,7 @@ class RepositoryTest { @Test fun cache_items_but_response_fails() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns - SelfossModel.StatusAndData(success = false, data = generateTestApiItem()) + StatusAndData(success = false, data = generateTestApiItem()) initializeRepository() repository.tagFilter = SelfossModel.Tag("Tag", "read", 0) @@ -1346,7 +1348,7 @@ class RepositoryTest { @Test fun cache_items_without_connection() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns - SelfossModel.StatusAndData(success = false, data = generateTestApiItem()) + StatusAndData(success = false, data = generateTestApiItem()) initializeRepository(MutableStateFlow(false)) repository.tagFilter = SelfossModel.Tag("Tag", "read", 0)