Remove FakeDataSource

Change-Id: I5e1486feeade67f0f7276458187694e684310ad3
pull/441/head
Miłosz Moczkowski 2 years ago
parent 3ca68d49ea
commit e653b738d2

@ -1,23 +0,0 @@
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.samples.apps.nowinandroid.core.network.fake
object FakeDataSource {
const val AUTHORS = "authors.json"
const val DATA = "data.json"
const val TOPICS = "topics.json"
}

@ -27,6 +27,7 @@ import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
@ -38,19 +39,29 @@ class FakeNiaNetworkDataSource @Inject constructor(
private val networkJson: Json,
private val assets: FakeAssetManager = JvmUnitTestFakeAssetManager,
) : NiaNetworkDataSource {
companion object {
private const val AUTHORS_ASSET = "authors.json"
private const val NEWS_ASSET = "news.json"
private const val TOPICS_ASSET = "topics.json"
}
@OptIn(ExperimentalSerializationApi::class)
override suspend fun getTopics(ids: List<String>?): List<NetworkTopic> =
withContext(ioDispatcher) {
assets.open(FakeDataSource.TOPICS).use(networkJson::decodeFromStream)
assets.open(TOPICS_ASSET).use(networkJson::decodeFromStream)
}
@OptIn(ExperimentalSerializationApi::class)
override suspend fun getNewsResources(ids: List<String>?): List<NetworkNewsResource> =
withContext(ioDispatcher) {
assets.open(FakeDataSource.DATA).use(networkJson::decodeFromStream)
assets.open(NEWS_ASSET).use(networkJson::decodeFromStream)
}
@OptIn(ExperimentalSerializationApi::class)
override suspend fun getAuthors(ids: List<String>?): List<NetworkAuthor> =
withContext(ioDispatcher) {
assets.open(FakeDataSource.AUTHORS).use(networkJson::decodeFromStream)
assets.open(AUTHORS_ASSET).use(networkJson::decodeFromStream)
}
override suspend fun getTopicChangeList(after: Int?): List<NetworkChangeList> =

Loading…
Cancel
Save