Improve SyncResultAnalyser tests

This commit is contained in:
Shinokuni 2020-03-03 22:14:04 +01:00
parent e232d2973c
commit ed2af2125c
1 changed files with 15 additions and 39 deletions

View File

@ -49,7 +49,7 @@ class SyncResultAnalyserTest {
val feed = Feed().apply { val feed = Feed().apply {
name = "feed ${i + 1}" name = "feed ${i + 1}"
iconUrl = "https://i0.wp.com/mrmondialisation.org/wp-content/uploads/2017/05/ico_final.gif" iconUrl = "https://i0.wp.com/mrmondialisation.org/wp-content/uploads/2017/05/ico_final.gif"
this.accountId = if (i %2 == 0) account1Id else account2Id this.accountId = if (i % 2 == 0) account1Id else account2Id
} }
database.feedDao().insert(feed).subscribe() database.feedDao().insert(feed).subscribe()
@ -68,10 +68,7 @@ class SyncResultAnalyserTest {
feedId = 1 feedId = 1
} }
val syncResult = SyncResult().apply { val syncResult = SyncResult().apply { items = mutableListOf(item) }
items = mutableListOf(item)
}
val notifContent = SyncResultAnalyser(context, mapOf(Pair(account1, syncResult)), database).getSyncNotifContent() val notifContent = SyncResultAnalyser(context, mapOf(Pair(account1, syncResult)), database).getSyncNotifContent()
assertEquals("caseOneElementEveryWhere", notifContent.content) assertEquals("caseOneElementEveryWhere", notifContent.content)
@ -82,59 +79,38 @@ class SyncResultAnalyserTest {
@Test @Test
fun caseTwoItemsOneFeed() { fun caseTwoItemsOneFeed() {
val item = Item().apply { val item = Item().apply {
title = "caseOneElementEveryWhere" title = "caseTwoItemsOneFeed"
feedId = 1 feedId = 1
} }
val syncResult = SyncResult().apply { val syncResult = SyncResult().apply { items = mutableListOf(item, item, item) }
items = mutableListOf(item, item, item)
}
val notifContent = SyncResultAnalyser(context, mapOf(Pair(account1, syncResult)), database).getSyncNotifContent() val notifContent = SyncResultAnalyser(context, mapOf(Pair(account1, syncResult)), database).getSyncNotifContent()
assertEquals("3 new articles", notifContent.content) assertEquals(context.getString(R.string.new_items, 3), notifContent.content)
assertEquals("feed 1", notifContent.title) assertEquals("feed 1", notifContent.title)
assertTrue(notifContent.largeIcon != null) assertTrue(notifContent.largeIcon != null)
} }
@Test @Test
fun caseMultipleFeeds() { fun caseMultipleFeeds() {
val item = Item().apply { val item = Item().apply { feedId = 1 }
feedId = 1 val item2 = Item().apply { feedId = 2 }
}
val item2 = Item().apply {
feedId = 2
}
val syncResult = SyncResult().apply {
items = mutableListOf(item, item2)
}
val syncResult = SyncResult().apply { items = mutableListOf(item, item2) }
val notifContent = SyncResultAnalyser(context, mapOf(Pair(account1, syncResult)), database).getSyncNotifContent() val notifContent = SyncResultAnalyser(context, mapOf(Pair(account1, syncResult)), database).getSyncNotifContent()
assertEquals("2 new articles", notifContent.content) assertEquals(context.getString(R.string.new_items, 2), notifContent.content)
assertEquals(account1.accountName, notifContent.title) assertEquals(account1.accountName, notifContent.title)
//assertTrue(notifContent.largeIcon != null) doesn't work currently assertTrue(notifContent.largeIcon != null)
} }
@Test @Test
fun multipleAccounts() { fun multipleAccounts() {
val item = Item().apply { val item = Item().apply { feedId = 1 }
feedId = 1 val item2 = Item().apply { feedId = 2 }
}
val item2 = Item().apply { val syncResult = SyncResult().apply { items = mutableListOf(item, item2) }
feedId = 2 val syncResult2 = SyncResult().apply { items = mutableListOf(item, item2) }
}
val syncResult = SyncResult().apply {
items = mutableListOf(item, item2)
}
val syncResult2 = SyncResult().apply {
items = mutableListOf(item, item2)
}
val syncResults = mutableMapOf<Account, SyncResult>().apply { val syncResults = mutableMapOf<Account, SyncResult>().apply {
put(account1, syncResult) put(account1, syncResult)
@ -144,6 +120,6 @@ class SyncResultAnalyserTest {
val notifContent = SyncResultAnalyser(context, syncResults, database).getSyncNotifContent() val notifContent = SyncResultAnalyser(context, syncResults, database).getSyncNotifContent()
assertEquals("Notifications", notifContent.title) assertEquals("Notifications", notifContent.title)
assertEquals("4 new articles", notifContent.content) assertEquals(context.getString(R.string.new_items, 4), notifContent.content)
} }
} }