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