|
|
@ -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
|
|
|
@ -111,8 +112,8 @@ class OfflineFirstNewsRepositoryTest {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
emptyList(),
|
|
|
|
expected = emptyList(),
|
|
|
|
subject.getNewsResources(
|
|
|
|
actual = subject.getNewsResources(
|
|
|
|
query = NewsResourceQuery(
|
|
|
|
query = NewsResourceQuery(
|
|
|
|
filterTopicIds = nonPresentInterestsIds,
|
|
|
|
filterTopicIds = nonPresentInterestsIds,
|
|
|
|
),
|
|
|
|
),
|
|
|
@ -135,14 +136,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,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -176,14 +177,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,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -215,14 +216,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,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -232,12 +233,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),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -247,11 +250,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),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|