From 6cb4b35c9371aee51d4e11a92a55e1dbbe9c0d87 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 28 Sep 2022 09:14:47 +0200 Subject: [PATCH] Introduce useful assertions in repository instantiation tests --- .../repository/RepositoryTest.kt | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt b/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt index 4418e5d..d2c9044 100644 --- a/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt +++ b/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt @@ -46,14 +46,10 @@ class RepositoryTest() { @Test fun `Instantiate repository`() { - val success = try { - Repository(api, appSettingsService, connectivityStatus, db) - true - } catch (e: Exception) { - false - } + Repository(api, appSettingsService, connectivityStatus, db) - assertEquals(true, success) + coVerify(exactly = 1) { api.version() } + coVerify(exactly = 1) { api.stats() } } @Test @@ -61,28 +57,23 @@ class RepositoryTest() { every { appSettingsService.getApiVersion() } returns -1 every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) - val success = try { - Repository(api, appSettingsService, connectivityStatus, db) - true - } catch (e: Exception) { - false - } + Repository(api, appSettingsService, connectivityStatus, db) - assertEquals(true, success) + coVerify(exactly = 0) { api.version() } + coVerify(exactly = 0) { api.stats() } } @Test fun `Instantiate repository with negative stats`() { coEvery { api.stats() } returns SelfossModel.StatusAndData(success = true, data = SelfossModel.Stats(-100, -50, -20)) - val success = try { - Repository(api, appSettingsService, connectivityStatus, db) - true - } catch (e: Exception) { - false - } + val repository = Repository(api, appSettingsService, connectivityStatus, db) - assertEquals(true, success) + assertEquals(0, repository.badgeAll) + assertEquals(0, repository.badgeStarred) + assertEquals(0, repository.badgeUnread) + coVerify(exactly = 1) { api.version() } + coVerify(exactly = 1) { api.stats() } } @Test