Introduce useful assertions in repository instantiation tests

This commit is contained in:
davidoskky 2022-09-28 09:14:47 +02:00
parent 15ec0f2d26
commit 6cb4b35c93

View File

@ -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