Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 112 KiB |
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 260 KiB After Width: | Height: | Size: 251 KiB |
Before Width: | Height: | Size: 139 KiB After Width: | Height: | Size: 139 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 193 KiB After Width: | Height: | Size: 197 KiB |
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 78 KiB |
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 59 KiB |
Before Width: | Height: | Size: 173 KiB After Width: | Height: | Size: 162 KiB |
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 103 KiB |
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 211 KiB After Width: | Height: | Size: 211 KiB |
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 94 KiB |
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2022 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.data.model
|
|
||||||
|
|
||||||
import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource
|
|
||||||
import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResourceExpanded
|
|
||||||
import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic
|
|
||||||
import kotlinx.datetime.Instant
|
|
||||||
import org.junit.Test
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
class NetworkEntityKtTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun network_topic_can_be_mapped_to_topic_entity() {
|
|
||||||
val networkModel = NetworkTopic(
|
|
||||||
id = "0",
|
|
||||||
name = "Test",
|
|
||||||
shortDescription = "short description",
|
|
||||||
longDescription = "long description",
|
|
||||||
url = "URL",
|
|
||||||
imageUrl = "image URL",
|
|
||||||
)
|
|
||||||
val entity = networkModel.asEntity()
|
|
||||||
|
|
||||||
assertEquals("0", entity.id)
|
|
||||||
assertEquals("Test", entity.name)
|
|
||||||
assertEquals("short description", entity.shortDescription)
|
|
||||||
assertEquals("long description", entity.longDescription)
|
|
||||||
assertEquals("URL", entity.url)
|
|
||||||
assertEquals("image URL", entity.imageUrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun network_news_resource_can_be_mapped_to_news_resource_entity() {
|
|
||||||
val networkModel =
|
|
||||||
NetworkNewsResource(
|
|
||||||
id = "0",
|
|
||||||
title = "title",
|
|
||||||
content = "content",
|
|
||||||
url = "url",
|
|
||||||
headerImageUrl = "headerImageUrl",
|
|
||||||
publishDate = Instant.fromEpochMilliseconds(1),
|
|
||||||
type = "Article 📚",
|
|
||||||
)
|
|
||||||
val entity = networkModel.asEntity()
|
|
||||||
|
|
||||||
assertEquals("0", entity.id)
|
|
||||||
assertEquals("title", entity.title)
|
|
||||||
assertEquals("content", entity.content)
|
|
||||||
assertEquals("url", entity.url)
|
|
||||||
assertEquals("headerImageUrl", entity.headerImageUrl)
|
|
||||||
assertEquals(Instant.fromEpochMilliseconds(1), entity.publishDate)
|
|
||||||
assertEquals("Article 📚", entity.type)
|
|
||||||
|
|
||||||
val expandedNetworkModel =
|
|
||||||
NetworkNewsResourceExpanded(
|
|
||||||
id = "0",
|
|
||||||
title = "title",
|
|
||||||
content = "content",
|
|
||||||
url = "url",
|
|
||||||
headerImageUrl = "headerImageUrl",
|
|
||||||
publishDate = Instant.fromEpochMilliseconds(1),
|
|
||||||
type = "Article 📚",
|
|
||||||
)
|
|
||||||
|
|
||||||
val entityFromExpanded = expandedNetworkModel.asEntity()
|
|
||||||
|
|
||||||
assertEquals("0", entityFromExpanded.id)
|
|
||||||
assertEquals("title", entityFromExpanded.title)
|
|
||||||
assertEquals("content", entityFromExpanded.content)
|
|
||||||
assertEquals("url", entityFromExpanded.url)
|
|
||||||
assertEquals("headerImageUrl", entityFromExpanded.headerImageUrl)
|
|
||||||
assertEquals(Instant.fromEpochMilliseconds(1), entityFromExpanded.publishDate)
|
|
||||||
assertEquals("Article 📚", entityFromExpanded.type)
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 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.data.model
|
||||||
|
|
||||||
|
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
|
||||||
|
import com.google.samples.apps.nowinandroid.core.model.data.Topic
|
||||||
|
import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource
|
||||||
|
import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic
|
||||||
|
import com.google.samples.apps.nowinandroid.core.network.model.asExternalModel
|
||||||
|
import kotlinx.datetime.Instant
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class NetworkEntityTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun networkTopicMapsToDatabaseModel() {
|
||||||
|
val networkModel = NetworkTopic(
|
||||||
|
id = "0",
|
||||||
|
name = "Test",
|
||||||
|
shortDescription = "short description",
|
||||||
|
longDescription = "long description",
|
||||||
|
url = "URL",
|
||||||
|
imageUrl = "image URL",
|
||||||
|
)
|
||||||
|
val entity = networkModel.asEntity()
|
||||||
|
|
||||||
|
assertEquals("0", entity.id)
|
||||||
|
assertEquals("Test", entity.name)
|
||||||
|
assertEquals("short description", entity.shortDescription)
|
||||||
|
assertEquals("long description", entity.longDescription)
|
||||||
|
assertEquals("URL", entity.url)
|
||||||
|
assertEquals("image URL", entity.imageUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun networkNewsResourceMapsToDatabaseModel() {
|
||||||
|
val networkModel =
|
||||||
|
NetworkNewsResource(
|
||||||
|
id = "0",
|
||||||
|
title = "title",
|
||||||
|
content = "content",
|
||||||
|
url = "url",
|
||||||
|
headerImageUrl = "headerImageUrl",
|
||||||
|
publishDate = Instant.fromEpochMilliseconds(1),
|
||||||
|
type = "Article 📚",
|
||||||
|
)
|
||||||
|
val entity = networkModel.asEntity()
|
||||||
|
|
||||||
|
assertEquals("0", entity.id)
|
||||||
|
assertEquals("title", entity.title)
|
||||||
|
assertEquals("content", entity.content)
|
||||||
|
assertEquals("url", entity.url)
|
||||||
|
assertEquals("headerImageUrl", entity.headerImageUrl)
|
||||||
|
assertEquals(Instant.fromEpochMilliseconds(1), entity.publishDate)
|
||||||
|
assertEquals("Article 📚", entity.type)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun networkTopicMapsToExternalModel() {
|
||||||
|
val networkTopic = NetworkTopic(
|
||||||
|
id = "0",
|
||||||
|
name = "Test",
|
||||||
|
shortDescription = "short description",
|
||||||
|
longDescription = "long description",
|
||||||
|
url = "URL",
|
||||||
|
imageUrl = "imageUrl",
|
||||||
|
)
|
||||||
|
|
||||||
|
val expected = Topic(
|
||||||
|
id = "0",
|
||||||
|
name = "Test",
|
||||||
|
shortDescription = "short description",
|
||||||
|
longDescription = "long description",
|
||||||
|
url = "URL",
|
||||||
|
imageUrl = "imageUrl",
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(expected, networkTopic.asExternalModel())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun networkNewsResourceMapsToExternalModel() {
|
||||||
|
val networkNewsResource = NetworkNewsResource(
|
||||||
|
id = "0",
|
||||||
|
title = "title",
|
||||||
|
content = "content",
|
||||||
|
url = "url",
|
||||||
|
headerImageUrl = "headerImageUrl",
|
||||||
|
publishDate = Instant.fromEpochMilliseconds(1),
|
||||||
|
type = "Article 📚",
|
||||||
|
topics = listOf("1", "2"),
|
||||||
|
)
|
||||||
|
|
||||||
|
val networkTopics = listOf(
|
||||||
|
NetworkTopic(
|
||||||
|
id = "1",
|
||||||
|
name = "Test 1",
|
||||||
|
shortDescription = "short description 1",
|
||||||
|
longDescription = "long description 1",
|
||||||
|
url = "url 1",
|
||||||
|
imageUrl = "imageUrl 1",
|
||||||
|
),
|
||||||
|
NetworkTopic(
|
||||||
|
id = "2",
|
||||||
|
name = "Test 2",
|
||||||
|
shortDescription = "short description 2",
|
||||||
|
longDescription = "long description 2",
|
||||||
|
url = "url 2",
|
||||||
|
imageUrl = "imageUrl 2",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
val expected = NewsResource(
|
||||||
|
id = "0",
|
||||||
|
title = "title",
|
||||||
|
content = "content",
|
||||||
|
url = "url",
|
||||||
|
headerImageUrl = "headerImageUrl",
|
||||||
|
publishDate = Instant.fromEpochMilliseconds(1),
|
||||||
|
type = "Article 📚",
|
||||||
|
topics = networkTopics.map(NetworkTopic::asExternalModel),
|
||||||
|
)
|
||||||
|
assertEquals(expected, networkNewsResource.asExternalModel(networkTopics))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2024 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.datastore.test
|
||||||
|
|
||||||
|
import androidx.datastore.core.DataStore
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.updateAndGet
|
||||||
|
|
||||||
|
class InMemoryDataStore<T>(initialValue: T) : DataStore<T> {
|
||||||
|
override val data = MutableStateFlow(initialValue)
|
||||||
|
override suspend fun updateData(
|
||||||
|
transform: suspend (it: T) -> T,
|
||||||
|
) = data.updateAndGet { transform(it) }
|
||||||
|
}
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 527 B After Width: | Height: | Size: 575 B |
Before Width: | Height: | Size: 527 B After Width: | Height: | Size: 575 B |
Before Width: | Height: | Size: 527 B After Width: | Height: | Size: 575 B |
Before Width: | Height: | Size: 527 B After Width: | Height: | Size: 575 B |
Before Width: | Height: | Size: 527 B After Width: | Height: | Size: 575 B |