|
|
|
@ -27,6 +27,7 @@ import com.google.samples.apps.nowinandroid.core.data.testdoubles.TestTopicDao
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.testdoubles.filteredInterestsIds
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.data.testdoubles.nonPresentInterestsIds
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceEntity
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceTopicCrossRef
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.database.model.PopulatedNewsResource
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.database.model.asExternalModel
|
|
|
|
@ -107,8 +108,8 @@ class OfflineFirstNewsRepositoryTest {
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
|
emptyList(),
|
|
|
|
|
subject.getNewsResources(
|
|
|
|
|
expected = emptyList(),
|
|
|
|
|
actual = subject.getNewsResources(
|
|
|
|
|
query = NewsResourceQuery(
|
|
|
|
|
filterTopicIds = nonPresentInterestsIds,
|
|
|
|
|
),
|
|
|
|
@ -131,14 +132,14 @@ class OfflineFirstNewsRepositoryTest {
|
|
|
|
|
.map(PopulatedNewsResource::asExternalModel)
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
|
newsResourcesFromNetwork.map(NewsResource::id),
|
|
|
|
|
newsResourcesFromDb.map(NewsResource::id),
|
|
|
|
|
newsResourcesFromNetwork.map(NewsResource::id).sorted(),
|
|
|
|
|
newsResourcesFromDb.map(NewsResource::id).sorted(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// After sync version should be updated
|
|
|
|
|
assertEquals(
|
|
|
|
|
network.latestChangeListVersion(CollectionType.NewsResources),
|
|
|
|
|
synchronizer.getChangeListVersions().newsResourceVersion,
|
|
|
|
|
expected = network.latestChangeListVersion(CollectionType.NewsResources),
|
|
|
|
|
actual = synchronizer.getChangeListVersions().newsResourceVersion,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -172,14 +173,14 @@ class OfflineFirstNewsRepositoryTest {
|
|
|
|
|
|
|
|
|
|
// Assert that items marked deleted on the network have been deleted locally
|
|
|
|
|
assertEquals(
|
|
|
|
|
newsResourcesFromNetwork.map(NewsResource::id) - deletedItems,
|
|
|
|
|
newsResourcesFromDb.map(NewsResource::id),
|
|
|
|
|
expected = (newsResourcesFromNetwork.map(NewsResource::id) - deletedItems).sorted(),
|
|
|
|
|
actual = newsResourcesFromDb.map(NewsResource::id).sorted(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// After sync version should be updated
|
|
|
|
|
assertEquals(
|
|
|
|
|
network.latestChangeListVersion(CollectionType.NewsResources),
|
|
|
|
|
synchronizer.getChangeListVersions().newsResourceVersion,
|
|
|
|
|
expected = network.latestChangeListVersion(CollectionType.NewsResources),
|
|
|
|
|
actual = synchronizer.getChangeListVersions().newsResourceVersion,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -211,14 +212,14 @@ class OfflineFirstNewsRepositoryTest {
|
|
|
|
|
.map(PopulatedNewsResource::asExternalModel)
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
|
newsResourcesFromNetwork.map(NewsResource::id),
|
|
|
|
|
newsResourcesFromDb.map(NewsResource::id),
|
|
|
|
|
expected = newsResourcesFromNetwork.map(NewsResource::id).sorted(),
|
|
|
|
|
actual = newsResourcesFromDb.map(NewsResource::id).sorted(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// After sync version should be updated
|
|
|
|
|
assertEquals(
|
|
|
|
|
changeList.last().changeListVersion,
|
|
|
|
|
synchronizer.getChangeListVersions().newsResourceVersion,
|
|
|
|
|
expected = changeList.last().changeListVersion,
|
|
|
|
|
actual = synchronizer.getChangeListVersions().newsResourceVersion,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -228,12 +229,14 @@ class OfflineFirstNewsRepositoryTest {
|
|
|
|
|
subject.syncWith(synchronizer)
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
|
network.getNewsResources()
|
|
|
|
|
expected = network.getNewsResources()
|
|
|
|
|
.map(NetworkNewsResource::topicEntityShells)
|
|
|
|
|
.flatten()
|
|
|
|
|
.distinctBy(TopicEntity::id),
|
|
|
|
|
topicDao.getTopicEntities()
|
|
|
|
|
.first(),
|
|
|
|
|
.distinctBy(TopicEntity::id)
|
|
|
|
|
.sortedBy(TopicEntity::toString),
|
|
|
|
|
actual = topicDao.getTopicEntities()
|
|
|
|
|
.first()
|
|
|
|
|
.sortedBy(TopicEntity::toString),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -243,11 +246,13 @@ class OfflineFirstNewsRepositoryTest {
|
|
|
|
|
subject.syncWith(synchronizer)
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
|
network.getNewsResources()
|
|
|
|
|
expected = network.getNewsResources()
|
|
|
|
|
.map(NetworkNewsResource::topicCrossReferences)
|
|
|
|
|
.flatten()
|
|
|
|
|
.distinct()
|
|
|
|
|
.flatten(),
|
|
|
|
|
newsResourceDao.topicCrossReferences,
|
|
|
|
|
.sortedBy(NewsResourceTopicCrossRef::toString),
|
|
|
|
|
actual = newsResourceDao.topicCrossReferences
|
|
|
|
|
.sortedBy(NewsResourceTopicCrossRef::toString),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|