From 0377fd8712ee159b0a48fdeaf89b26afe32d61ed Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Tue, 15 Aug 2023 11:04:19 +0200 Subject: [PATCH 1/8] Replace `NewsResourceType` enum with simpler String type See this discussion for rationale: https://github.com/android/nowinandroid/discussions/901 --- ...CompositeUserNewsResourceRepositoryTest.kt | 7 +- .../core/data/UserNewsResourceTest.kt | 3 +- .../core/data/model/NetworkEntityKtTest.kt | 9 +- .../model/PopulatedNewsResourceKtTest.kt | 5 +- .../util/NewsResourceTypeConverterTest.kt | 96 ---------------- .../core/database/dao/NewsResourceDaoTest.kt | 3 +- .../nowinandroid/core/database/NiaDatabase.kt | 2 - .../core/database/model/NewsResourceEntity.kt | 3 +- .../core/database/util/Converters.kt | 11 -- .../core/model/data/NewsResource.kt | 2 +- .../core/model/data/NewsResourceType.kt | 80 ------------- .../core/model/data/UserNewsResource.kt | 2 +- .../core/network/model/NetworkNewsResource.kt | 8 +- .../model/util/NewsResourceTypeSerializer.kt | 39 ------- .../fake/FakeNiaNetworkDataSourceTest.kt | 3 +- .../util/NewsResourceTypeSerializerTest.kt | 106 ------------------ .../testing/data/NewsResourcesTestData.kt | 11 +- .../testing/data/UserNewsResourcesTestData.kt | 11 +- .../nowinandroid/core/ui/NewsResourceCard.kt | 7 +- ...serNewsResourcePreviewParameterProvider.kt | 8 +- .../feature/foryou/ForYouViewModelTest.kt | 7 +- .../feature/topic/TopicViewModelTest.kt | 3 +- 22 files changed, 35 insertions(+), 391 deletions(-) delete mode 100644 core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/util/NewsResourceTypeConverterTest.kt delete mode 100644 core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt delete mode 100644 core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializer.kt delete mode 100644 core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializerTest.kt diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/CompositeUserNewsResourceRepositoryTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/CompositeUserNewsResourceRepositoryTest.kt index eb4241295..9ed85d427 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/CompositeUserNewsResourceRepositoryTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/CompositeUserNewsResourceRepositoryTest.kt @@ -19,7 +19,6 @@ package com.google.samples.apps.nowinandroid.core.data import com.google.samples.apps.nowinandroid.core.data.repository.CompositeUserNewsResourceRepository import com.google.samples.apps.nowinandroid.core.data.repository.NewsResourceQuery import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.model.data.mapToUserNewsResources import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository @@ -164,7 +163,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, + type = "Video", topics = listOf(sampleTopic1), ), NewsResource( @@ -176,7 +175,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = Video, + type = "Video", topics = listOf(sampleTopic1, sampleTopic2), ), NewsResource( @@ -186,7 +185,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/r5JgIyS3t3s", headerImageUrl = "https://i.ytimg.com/vi/r5JgIyS3t3s/maxresdefault.jpg", publishDate = Instant.parse("2021-11-08T00:00:00.000Z"), - type = Video, + type = "Video", topics = listOf(sampleTopic2), ), ) diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/UserNewsResourceTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/UserNewsResourceTest.kt index 004966ec9..9a6c00cda 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/UserNewsResourceTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/UserNewsResourceTest.kt @@ -19,7 +19,6 @@ package com.google.samples.apps.nowinandroid.core.data import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig.FOLLOW_SYSTEM import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Article import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand.DEFAULT import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.model.data.UserData @@ -45,7 +44,7 @@ class UserNewsResourceTest { url = "Test URL", headerImageUrl = "Test image URL", publishDate = Clock.System.now(), - type = Article, + type = "Article", topics = listOf( Topic( id = "T1", diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt index dbbb3a94e..f12f347b0 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt @@ -16,7 +16,6 @@ package com.google.samples.apps.nowinandroid.core.data.model -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Article 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 @@ -56,7 +55,7 @@ class NetworkEntityKtTest { url = "url", headerImageUrl = "headerImageUrl", publishDate = Instant.fromEpochMilliseconds(1), - type = Article, + type = "Article", ) val entity = networkModel.asEntity() @@ -66,7 +65,7 @@ class NetworkEntityKtTest { assertEquals("url", entity.url) assertEquals("headerImageUrl", entity.headerImageUrl) assertEquals(Instant.fromEpochMilliseconds(1), entity.publishDate) - assertEquals(Article, entity.type) + assertEquals("Article", entity.type) val expandedNetworkModel = NetworkNewsResourceExpanded( @@ -76,7 +75,7 @@ class NetworkEntityKtTest { url = "url", headerImageUrl = "headerImageUrl", publishDate = Instant.fromEpochMilliseconds(1), - type = Article, + type = "Article", ) val entityFromExpanded = expandedNetworkModel.asEntity() @@ -87,6 +86,6 @@ class NetworkEntityKtTest { assertEquals("url", entityFromExpanded.url) assertEquals("headerImageUrl", entityFromExpanded.headerImageUrl) assertEquals(Instant.fromEpochMilliseconds(1), entityFromExpanded.publishDate) - assertEquals(Article, entityFromExpanded.type) + assertEquals("Article", entityFromExpanded.type) } } diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt index 83158f6cd..95e13c5ec 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt @@ -17,7 +17,6 @@ package com.google.samples.apps.nowinandroid.core.database.model import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.Topic import kotlinx.datetime.Instant import org.junit.Test @@ -33,7 +32,7 @@ class PopulatedNewsResourceKtTest { content = "Hilt", url = "url", headerImageUrl = "headerImageUrl", - type = Video, + type = "Video", publishDate = Instant.fromEpochMilliseconds(1), ), topics = listOf( @@ -56,7 +55,7 @@ class PopulatedNewsResourceKtTest { content = "Hilt", url = "url", headerImageUrl = "headerImageUrl", - type = Video, + type = "Video", publishDate = Instant.fromEpochMilliseconds(1), topics = listOf( Topic( diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/util/NewsResourceTypeConverterTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/util/NewsResourceTypeConverterTest.kt deleted file mode 100644 index 77a09819b..000000000 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/util/NewsResourceTypeConverterTest.kt +++ /dev/null @@ -1,96 +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.database.util - -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import org.junit.Test -import kotlin.test.assertEquals - -class NewsResourceTypeConverterTest { - - @Test - fun test_room_news_resource_type_converter_for_video() { - assertEquals( - NewsResourceType.Video, - NewsResourceTypeConverter().stringToNewsResourceType("Video 📺"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_article() { - assertEquals( - NewsResourceType.Article, - NewsResourceTypeConverter().stringToNewsResourceType("Article 📚"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_api_change() { - assertEquals( - NewsResourceType.APIChange, - NewsResourceTypeConverter().stringToNewsResourceType("API change"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_codelab() { - assertEquals( - NewsResourceType.Codelab, - NewsResourceTypeConverter().stringToNewsResourceType("Codelab"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_podcast() { - assertEquals( - NewsResourceType.Podcast, - NewsResourceTypeConverter().stringToNewsResourceType("Podcast 🎙"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_docs() { - assertEquals( - NewsResourceType.Docs, - NewsResourceTypeConverter().stringToNewsResourceType("Docs 📑"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_event() { - assertEquals( - NewsResourceType.Event, - NewsResourceTypeConverter().stringToNewsResourceType("Event 📆"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_dac() { - assertEquals( - NewsResourceType.DAC, - NewsResourceTypeConverter().stringToNewsResourceType("DAC"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_umm() { - assertEquals( - NewsResourceType.Unknown, - NewsResourceTypeConverter().stringToNewsResourceType("umm"), - ) - } -} diff --git a/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt b/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt index 83dc3c2e6..f02865fe9 100644 --- a/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt +++ b/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt @@ -24,7 +24,6 @@ import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceEnti import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceTopicCrossRef 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.model.data.NewsResourceType import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import kotlinx.datetime.Instant @@ -305,5 +304,5 @@ private fun testNewsResource( url = "", headerImageUrl = "", publishDate = Instant.fromEpochMilliseconds(millisSinceEpoch), - type = NewsResourceType.DAC, + type = "DAC", ) diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiaDatabase.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiaDatabase.kt index 96714f9a9..fd6b75e49 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiaDatabase.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiaDatabase.kt @@ -32,7 +32,6 @@ import com.google.samples.apps.nowinandroid.core.database.model.RecentSearchQuer import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity import com.google.samples.apps.nowinandroid.core.database.model.TopicFtsEntity import com.google.samples.apps.nowinandroid.core.database.util.InstantConverter -import com.google.samples.apps.nowinandroid.core.database.util.NewsResourceTypeConverter @Database( entities = [ @@ -63,7 +62,6 @@ import com.google.samples.apps.nowinandroid.core.database.util.NewsResourceTypeC ) @TypeConverters( InstantConverter::class, - NewsResourceTypeConverter::class, ) abstract class NiaDatabase : RoomDatabase() { abstract fun topicDao(): TopicDao diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceEntity.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceEntity.kt index a571d8f94..9450a24ad 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceEntity.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceEntity.kt @@ -20,7 +20,6 @@ import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType import kotlinx.datetime.Instant /** @@ -39,7 +38,7 @@ data class NewsResourceEntity( val headerImageUrl: String?, @ColumnInfo(name = "publish_date") val publishDate: Instant, - val type: NewsResourceType, + val type: String, ) fun NewsResourceEntity.asExternalModel() = NewsResource( diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt index eff1742ee..723c81062 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt @@ -17,8 +17,6 @@ package com.google.samples.apps.nowinandroid.core.database.util import androidx.room.TypeConverter -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import com.google.samples.apps.nowinandroid.core.model.data.asNewsResourceType import kotlinx.datetime.Instant class InstantConverter { @@ -31,12 +29,3 @@ class InstantConverter { instant?.toEpochMilliseconds() } -class NewsResourceTypeConverter { - @TypeConverter - fun newsResourceTypeToString(value: NewsResourceType?): String? = - value?.let(NewsResourceType::serializedName) - - @TypeConverter - fun stringToNewsResourceType(serializedName: String?): NewsResourceType = - serializedName.asNewsResourceType() -} diff --git a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt index a1d4deb65..996851ff3 100644 --- a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt +++ b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt @@ -28,6 +28,6 @@ data class NewsResource( val url: String, val headerImageUrl: String?, val publishDate: Instant, - val type: NewsResourceType, + val type: String, val topics: List, ) diff --git a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt deleted file mode 100644 index bb00f8620..000000000 --- a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt +++ /dev/null @@ -1,80 +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.model.data - -/** - * Type for [NewsResource] - */ -enum class NewsResourceType( - val serializedName: String, - val displayText: String, - // TODO: descriptions should probably be string resources - val description: String, -) { - Video( - serializedName = "Video 📺", - displayText = "Video 📺", - description = "A video published on YouTube", - ), - APIChange( - serializedName = "API change", - displayText = "API change", - description = "An addition, deprecation or change to the Android platform APIs.", - ), - Article( - serializedName = "Article 📚", - displayText = "Article 📚", - description = "An article, typically on Medium or the official Android blog", - ), - Codelab( - serializedName = "Codelab", - displayText = "Codelab", - description = "A new or updated codelab", - ), - Podcast( - serializedName = "Podcast 🎙", - displayText = "Podcast 🎙", - description = "A podcast", - ), - Docs( - serializedName = "Docs 📑", - displayText = "Docs 📑", - description = "A new or updated piece of documentation", - ), - Event( - serializedName = "Event 📆", - displayText = "Event 📆", - description = "Information about a developer event e.g. Android Developer Summit", - ), - DAC( - serializedName = "DAC", - displayText = "DAC", - description = "Android version features - Information about features in an Android", - ), - Unknown( - serializedName = "Unknown", - displayText = "Unknown", - description = "Unknown", - ), -} - -fun String?.asNewsResourceType() = when (this) { - null -> NewsResourceType.Unknown - else -> NewsResourceType.values() - .firstOrNull { type -> type.serializedName == this } - ?: NewsResourceType.Unknown -} diff --git a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/UserNewsResource.kt b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/UserNewsResource.kt index 251911930..4ea830022 100644 --- a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/UserNewsResource.kt +++ b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/UserNewsResource.kt @@ -29,7 +29,7 @@ data class UserNewsResource internal constructor( val url: String, val headerImageUrl: String?, val publishDate: Instant, - val type: NewsResourceType, + val type: String, val followableTopics: List, val isSaved: Boolean, val hasBeenViewed: Boolean, diff --git a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/NetworkNewsResource.kt b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/NetworkNewsResource.kt index 99fa67a52..42fbfa826 100644 --- a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/NetworkNewsResource.kt +++ b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/NetworkNewsResource.kt @@ -17,9 +17,7 @@ package com.google.samples.apps.nowinandroid.core.network.model import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType import com.google.samples.apps.nowinandroid.core.network.model.util.InstantSerializer -import com.google.samples.apps.nowinandroid.core.network.model.util.NewsResourceTypeSerializer import kotlinx.datetime.Instant import kotlinx.serialization.Serializable @@ -35,8 +33,7 @@ data class NetworkNewsResource( val headerImageUrl: String, @Serializable(InstantSerializer::class) val publishDate: Instant, - @Serializable(NewsResourceTypeSerializer::class) - val type: NewsResourceType, + val type: String, val topics: List = listOf(), ) @@ -52,7 +49,6 @@ data class NetworkNewsResourceExpanded( val headerImageUrl: String, @Serializable(InstantSerializer::class) val publishDate: Instant, - @Serializable(NewsResourceTypeSerializer::class) - val type: NewsResourceType, + val type: String, val topics: List = listOf(), ) diff --git a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializer.kt b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializer.kt deleted file mode 100644 index ac40d6182..000000000 --- a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializer.kt +++ /dev/null @@ -1,39 +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.network.model.util - -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import com.google.samples.apps.nowinandroid.core.model.data.asNewsResourceType -import kotlinx.serialization.KSerializer -import kotlinx.serialization.descriptors.PrimitiveKind.STRING -import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor -import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder - -object NewsResourceTypeSerializer : KSerializer { - override fun deserialize(decoder: Decoder): NewsResourceType = - decoder.decodeString().asNewsResourceType() - - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( - serialName = "type", - kind = STRING, - ) - - override fun serialize(encoder: Encoder, value: NewsResourceType) = - encoder.encodeString(value.serializedName) -} diff --git a/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt b/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt index f54351750..76c2accf2 100644 --- a/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt +++ b/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt @@ -17,7 +17,6 @@ package com.google.samples.apps.nowinandroid.core.network.fake import JvmUnitTestFakeAssetManager -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Codelab import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic import kotlinx.coroutines.test.StandardTestDispatcher @@ -81,7 +80,7 @@ class FakeNiaNetworkDataSourceTest { second = 0, nanosecond = 0, ).toInstant(TimeZone.UTC), - type = Codelab, + type = "Codelab", topics = listOf("2", "3", "10"), ), /* ktlint-enable max-line-length */ diff --git a/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializerTest.kt b/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializerTest.kt deleted file mode 100644 index 16ac7df26..000000000 --- a/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializerTest.kt +++ /dev/null @@ -1,106 +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.network.model.util - -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import kotlinx.serialization.json.Json -import org.junit.Test -import kotlin.test.assertEquals - -class NewsResourceTypeSerializerTest { - - @Test - fun test_news_resource_serializer_video() { - assertEquals( - NewsResourceType.Video, - Json.decodeFromString(NewsResourceTypeSerializer, """"Video 📺""""), - ) - } - - @Test - fun test_news_resource_serializer_article() { - assertEquals( - NewsResourceType.Article, - Json.decodeFromString(NewsResourceTypeSerializer, """"Article 📚""""), - ) - } - - @Test - fun test_news_resource_serializer_api_change() { - assertEquals( - NewsResourceType.APIChange, - Json.decodeFromString(NewsResourceTypeSerializer, """"API change""""), - ) - } - - @Test - fun test_news_resource_serializer_codelab() { - assertEquals( - NewsResourceType.Codelab, - Json.decodeFromString(NewsResourceTypeSerializer, """"Codelab""""), - ) - } - - @Test - fun test_news_resource_serializer_podcast() { - assertEquals( - NewsResourceType.Podcast, - Json.decodeFromString(NewsResourceTypeSerializer, """"Podcast 🎙""""), - ) - } - - @Test - fun test_news_resource_serializer_docs() { - assertEquals( - NewsResourceType.Docs, - Json.decodeFromString(NewsResourceTypeSerializer, """"Docs 📑""""), - ) - } - - @Test - fun test_news_resource_serializer_event() { - assertEquals( - NewsResourceType.Event, - Json.decodeFromString(NewsResourceTypeSerializer, """"Event 📆""""), - ) - } - - @Test - fun test_news_resource_serializer_dac() { - assertEquals( - NewsResourceType.DAC, - Json.decodeFromString(NewsResourceTypeSerializer, """"DAC""""), - ) - } - - @Test - fun test_news_resource_serializer_unknown() { - assertEquals( - NewsResourceType.Unknown, - Json.decodeFromString(NewsResourceTypeSerializer, """"umm""""), - ) - } - - @Test - fun test_serialize_and_deserialize() { - val json = Json.encodeToString(NewsResourceTypeSerializer, NewsResourceType.Video) - assertEquals( - NewsResourceType.Video, - Json.decodeFromString(NewsResourceTypeSerializer, json), - ) - } -} diff --git a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt index bffa7cb79..b4b3a6104 100644 --- a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt +++ b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt @@ -17,9 +17,6 @@ package com.google.samples.apps.nowinandroid.core.testing.data import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Codelab -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Unknown -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import kotlinx.datetime.Instant /* ktlint-disable max-line-length */ @@ -31,7 +28,7 @@ val newsResourcesTestData: List = listOf( url = "https://android-developers.googleblog.com/2022/05/new-android-basics-with-compose-course.html", headerImageUrl = "https://developer.android.com/images/hero-assets/android-basics-compose.svg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Codelab, + type = "Codelab", topics = listOf(topicsTestData[1]), ), NewsResource( @@ -44,7 +41,7 @@ val newsResourcesTestData: List = listOf( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, + type = "Video", topics = listOf(topicsTestData[0], topicsTestData[1]), ), NewsResource( @@ -57,7 +54,7 @@ val newsResourcesTestData: List = listOf( url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = Video, + type = "Video", topics = listOf(topicsTestData[2]), ), NewsResource( @@ -68,7 +65,7 @@ val newsResourcesTestData: List = listOf( url = "https://developer.android.com/jetpack/androidx/versions/all-channel", headerImageUrl = "", publishDate = Instant.parse("2022-10-01T00:00:00.000Z"), - type = Unknown, + type = "Unknown", topics = listOf(topicsTestData[2]), ), ) diff --git a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt index 987b48b57..a3c5ec63c 100644 --- a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt +++ b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt @@ -18,9 +18,6 @@ package com.google.samples.apps.nowinandroid.core.testing.data import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Codelab -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Unknown -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand import com.google.samples.apps.nowinandroid.core.model.data.UserData import com.google.samples.apps.nowinandroid.core.model.data.UserNewsResource @@ -56,7 +53,7 @@ val userNewsResourcesTestData: List = UserData( second = 0, nanosecond = 0, ).toInstant(TimeZone.UTC), - type = Codelab, + type = "Codelab", topics = listOf(topicsTestData[2]), ), userData = userData, @@ -72,7 +69,7 @@ val userNewsResourcesTestData: List = UserData( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, + type = "Video", topics = topicsTestData.take(2), ), userData = userData, @@ -88,7 +85,7 @@ val userNewsResourcesTestData: List = UserData( url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = Video, + type = "Video", topics = listOf(topicsTestData[2]), ), userData = userData, @@ -102,7 +99,7 @@ val userNewsResourcesTestData: List = UserData( url = "https://developer.android.com/jetpack/androidx/versions/all-channel", headerImageUrl = "", publishDate = Instant.parse("2022-10-01T00:00:00.000Z"), - type = Unknown, + type = "Unknown", topics = listOf(topicsTestData[2]), ), userData = userData, diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt index 4ed583b66..936f4c6f3 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt @@ -68,7 +68,6 @@ import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType import com.google.samples.apps.nowinandroid.core.model.data.UserNewsResource import kotlinx.datetime.Instant import kotlinx.datetime.toJavaInstant @@ -264,12 +263,12 @@ fun dateFormatted(publishDate: Instant): String { @Composable fun NewsResourceMetaData( publishDate: Instant, - resourceType: NewsResourceType, + resourceType: String, ) { val formattedDate = dateFormatted(publishDate) Text( - if (resourceType != NewsResourceType.Unknown) { - stringResource(R.string.card_meta_data_text, formattedDate, resourceType.displayText) + if (resourceType.isNotEmpty()) { + stringResource(R.string.card_meta_data_text, formattedDate, resourceType) } else { formattedDate }, diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/UserNewsResourcePreviewParameterProvider.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/UserNewsResourcePreviewParameterProvider.kt index cc78e2e78..979ec2321 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/UserNewsResourcePreviewParameterProvider.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/UserNewsResourcePreviewParameterProvider.kt @@ -19,8 +19,6 @@ package com.google.samples.apps.nowinandroid.core.ui import androidx.compose.ui.tooling.preview.PreviewParameterProvider import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.model.data.UserData @@ -97,7 +95,7 @@ object PreviewParameterData { second = 0, nanosecond = 0, ).toInstant(TimeZone.UTC), - type = NewsResourceType.Codelab, + type = "Codelab", topics = listOf(topics[2]), ), userData = userData, @@ -113,7 +111,7 @@ object PreviewParameterData { url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, + type = "Video", topics = topics.take(2), ), userData = userData, @@ -129,7 +127,7 @@ object PreviewParameterData { url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = Video, + type = "Video", topics = listOf(topics[2]), ), userData = userData, diff --git a/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt b/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt index d1f2f69b7..7fb672fca 100644 --- a/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt +++ b/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt @@ -23,7 +23,6 @@ import com.google.samples.apps.nowinandroid.core.data.repository.CompositeUserNe import com.google.samples.apps.nowinandroid.core.domain.GetFollowableTopicsUseCase import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.model.data.UserNewsResource import com.google.samples.apps.nowinandroid.core.model.data.mapToUserNewsResources @@ -545,7 +544,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, + type = "Video", topics = listOf( Topic( id = "0", @@ -566,7 +565,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = Video, + type = "Video", topics = listOf( Topic( id = "1", @@ -585,7 +584,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/r5JgIyS3t3s", headerImageUrl = "https://i.ytimg.com/vi/r5JgIyS3t3s/maxresdefault.jpg", publishDate = Instant.parse("2021-11-08T00:00:00.000Z"), - type = Video, + type = "Video", topics = listOf( Topic( id = "1", diff --git a/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt b/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt index d365232d7..878e86189 100644 --- a/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt +++ b/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt @@ -20,7 +20,6 @@ import androidx.lifecycle.SavedStateHandle import com.google.samples.apps.nowinandroid.core.data.repository.CompositeUserNewsResourceRepository import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRepository @@ -258,7 +257,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, + type = "Video", topics = listOf( Topic( id = "0", From 553b01fcb670d3207556301ff5edab16187e84ce Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Tue, 15 Aug 2023 11:12:10 +0200 Subject: [PATCH 2/8] spotlessApply --- .../core/database/util/{Converters.kt => InstantConverter.kt} | 1 - 1 file changed, 1 deletion(-) rename core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/{Converters.kt => InstantConverter.kt} (99%) diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/InstantConverter.kt similarity index 99% rename from core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt rename to core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/InstantConverter.kt index 723c81062..4e880886c 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/InstantConverter.kt @@ -28,4 +28,3 @@ class InstantConverter { fun instantToLong(instant: Instant?): Long? = instant?.toEpochMilliseconds() } - From 480d8e7d7c8fb654bbcf96f923e2737b52e61a0d Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Tue, 15 Aug 2023 12:02:23 +0200 Subject: [PATCH 3/8] Fix missing removal --- .../samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt index a495a6266..3f3d70aae 100644 --- a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt +++ b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt @@ -54,7 +54,7 @@ class NewsResourceCardTest { composeTestRule.activity.getString( R.string.card_meta_data_text, dateFormatted, - newsWithKnownResourceType.type.displayText, + newsWithKnownResourceType.type, ), ) .assertExists() From daa222813206bc6a758663675c83c2e2247c3c91 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Wed, 16 Aug 2023 08:07:15 +0200 Subject: [PATCH 4/8] Restore original `type` labels --- .../core/data/CompositeUserNewsResourceRepositoryTest.kt | 6 +++--- .../apps/nowinandroid/core/data/UserNewsResourceTest.kt | 2 +- .../nowinandroid/core/data/model/NetworkEntityKtTest.kt | 8 ++++---- .../core/database/model/PopulatedNewsResourceKtTest.kt | 4 ++-- .../nowinandroid/core/database/dao/NewsResourceDaoTest.kt | 2 +- .../core/testing/data/NewsResourcesTestData.kt | 4 ++-- .../core/testing/data/UserNewsResourcesTestData.kt | 4 ++-- .../core/ui/UserNewsResourcePreviewParameterProvider.kt | 4 ++-- .../nowinandroid/feature/foryou/ForYouViewModelTest.kt | 6 +++--- .../apps/nowinandroid/feature/topic/TopicViewModelTest.kt | 2 +- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/CompositeUserNewsResourceRepositoryTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/CompositeUserNewsResourceRepositoryTest.kt index 9ed85d427..743fb7e5c 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/CompositeUserNewsResourceRepositoryTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/CompositeUserNewsResourceRepositoryTest.kt @@ -163,7 +163,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = listOf(sampleTopic1), ), NewsResource( @@ -175,7 +175,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = listOf(sampleTopic1, sampleTopic2), ), NewsResource( @@ -185,7 +185,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/r5JgIyS3t3s", headerImageUrl = "https://i.ytimg.com/vi/r5JgIyS3t3s/maxresdefault.jpg", publishDate = Instant.parse("2021-11-08T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = listOf(sampleTopic2), ), ) diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/UserNewsResourceTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/UserNewsResourceTest.kt index 9a6c00cda..a21dee863 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/UserNewsResourceTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/UserNewsResourceTest.kt @@ -44,7 +44,7 @@ class UserNewsResourceTest { url = "Test URL", headerImageUrl = "Test image URL", publishDate = Clock.System.now(), - type = "Article", + type = "Article 📚", topics = listOf( Topic( id = "T1", diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt index f12f347b0..7dd251a99 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt @@ -55,7 +55,7 @@ class NetworkEntityKtTest { url = "url", headerImageUrl = "headerImageUrl", publishDate = Instant.fromEpochMilliseconds(1), - type = "Article", + type = "Article 📚", ) val entity = networkModel.asEntity() @@ -65,7 +65,7 @@ class NetworkEntityKtTest { assertEquals("url", entity.url) assertEquals("headerImageUrl", entity.headerImageUrl) assertEquals(Instant.fromEpochMilliseconds(1), entity.publishDate) - assertEquals("Article", entity.type) + assertEquals("Article 📚", entity.type) val expandedNetworkModel = NetworkNewsResourceExpanded( @@ -75,7 +75,7 @@ class NetworkEntityKtTest { url = "url", headerImageUrl = "headerImageUrl", publishDate = Instant.fromEpochMilliseconds(1), - type = "Article", + type = "Article 📚", ) val entityFromExpanded = expandedNetworkModel.asEntity() @@ -86,6 +86,6 @@ class NetworkEntityKtTest { assertEquals("url", entityFromExpanded.url) assertEquals("headerImageUrl", entityFromExpanded.headerImageUrl) assertEquals(Instant.fromEpochMilliseconds(1), entityFromExpanded.publishDate) - assertEquals("Article", entityFromExpanded.type) + assertEquals("Article 📚", entityFromExpanded.type) } } diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt index 95e13c5ec..a1b72c52f 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt @@ -32,7 +32,7 @@ class PopulatedNewsResourceKtTest { content = "Hilt", url = "url", headerImageUrl = "headerImageUrl", - type = "Video", + type = "Video 📺", publishDate = Instant.fromEpochMilliseconds(1), ), topics = listOf( @@ -55,7 +55,7 @@ class PopulatedNewsResourceKtTest { content = "Hilt", url = "url", headerImageUrl = "headerImageUrl", - type = "Video", + type = "Video 📺", publishDate = Instant.fromEpochMilliseconds(1), topics = listOf( Topic( diff --git a/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt b/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt index f02865fe9..55e817618 100644 --- a/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt +++ b/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt @@ -304,5 +304,5 @@ private fun testNewsResource( url = "", headerImageUrl = "", publishDate = Instant.fromEpochMilliseconds(millisSinceEpoch), - type = "DAC", + type = "Article 📚", ) diff --git a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt index b4b3a6104..1e31c320f 100644 --- a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt +++ b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt @@ -41,7 +41,7 @@ val newsResourcesTestData: List = listOf( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = listOf(topicsTestData[0], topicsTestData[1]), ), NewsResource( @@ -54,7 +54,7 @@ val newsResourcesTestData: List = listOf( url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = listOf(topicsTestData[2]), ), NewsResource( diff --git a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt index a3c5ec63c..ab6574f6a 100644 --- a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt +++ b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt @@ -69,7 +69,7 @@ val userNewsResourcesTestData: List = UserData( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = topicsTestData.take(2), ), userData = userData, @@ -85,7 +85,7 @@ val userNewsResourcesTestData: List = UserData( url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = listOf(topicsTestData[2]), ), userData = userData, diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/UserNewsResourcePreviewParameterProvider.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/UserNewsResourcePreviewParameterProvider.kt index 979ec2321..493788314 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/UserNewsResourcePreviewParameterProvider.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/UserNewsResourcePreviewParameterProvider.kt @@ -111,7 +111,7 @@ object PreviewParameterData { url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = topics.take(2), ), userData = userData, @@ -127,7 +127,7 @@ object PreviewParameterData { url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = listOf(topics[2]), ), userData = userData, diff --git a/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt b/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt index 7fb672fca..b75573975 100644 --- a/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt +++ b/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt @@ -544,7 +544,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = listOf( Topic( id = "0", @@ -565,7 +565,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = listOf( Topic( id = "1", @@ -584,7 +584,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/r5JgIyS3t3s", headerImageUrl = "https://i.ytimg.com/vi/r5JgIyS3t3s/maxresdefault.jpg", publishDate = Instant.parse("2021-11-08T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = listOf( Topic( id = "1", diff --git a/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt b/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt index 878e86189..8c6253d60 100644 --- a/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt +++ b/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt @@ -257,7 +257,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = "Video", + type = "Video 📺", topics = listOf( Topic( id = "0", From c831dc673c36af7fd7b874069e8f63053ed901a2 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Wed, 16 Aug 2023 10:07:42 +0200 Subject: [PATCH 5/8] Fix broken text --- .../samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt index 3f3d70aae..f40bf1f33 100644 --- a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt +++ b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt @@ -79,7 +79,7 @@ class NewsResourceCardTest { } composeTestRule - .onNodeWithText(dateFormatted) + .onNodeWithText(dateFormatted, substring = true) .assertIsDisplayed() } From f1bc6f1226fa396c00def380c9b6e968a3d42b42 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Wed, 16 Aug 2023 19:10:44 +0200 Subject: [PATCH 6/8] Restore `Unknown` type as empty `String` --- .../core/testing/data/NewsResourcesTestData.kt | 2 +- .../core/testing/data/UserNewsResourcesTestData.kt | 2 +- .../apps/nowinandroid/core/ui/NewsResourceCardTest.kt | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt index 1e31c320f..ef845dc58 100644 --- a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt +++ b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt @@ -65,7 +65,7 @@ val newsResourcesTestData: List = listOf( url = "https://developer.android.com/jetpack/androidx/versions/all-channel", headerImageUrl = "", publishDate = Instant.parse("2022-10-01T00:00:00.000Z"), - type = "Unknown", + type = "", topics = listOf(topicsTestData[2]), ), ) diff --git a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt index ab6574f6a..97acad088 100644 --- a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt +++ b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt @@ -99,7 +99,7 @@ val userNewsResourcesTestData: List = UserData( url = "https://developer.android.com/jetpack/androidx/versions/all-channel", headerImageUrl = "", publishDate = Instant.parse("2022-10-01T00:00:00.000Z"), - type = "Unknown", + type = "", topics = listOf(topicsTestData[2]), ), userData = userData, diff --git a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt index f40bf1f33..9f5f46099 100644 --- a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt +++ b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt @@ -61,13 +61,13 @@ class NewsResourceCardTest { } @Test - fun testMetaDataDisplay_withUnknownResource() { - val newsWithUnknownResourceType = userNewsResourcesTestData[3] + fun testMetaDataDisplay_withEmptyResourceType() { + val newsWithEmptyResourceType = userNewsResourcesTestData[3] var dateFormatted = "" composeTestRule.setContent { NewsResourceCardExpanded( - userNewsResource = newsWithUnknownResourceType, + userNewsResource = newsWithEmptyResourceType, isBookmarked = false, hasBeenViewed = false, onToggleBookmark = {}, @@ -75,11 +75,11 @@ class NewsResourceCardTest { onTopicClick = {}, ) - dateFormatted = dateFormatted(publishDate = newsWithUnknownResourceType.publishDate) + dateFormatted = dateFormatted(publishDate = newsWithEmptyResourceType.publishDate) } composeTestRule - .onNodeWithText(dateFormatted, substring = true) + .onNodeWithText(dateFormatted) .assertIsDisplayed() } From 4a5ec5bd82ac11c80f04e87474322d7a12b4ebeb Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Wed, 16 Aug 2023 19:11:27 +0200 Subject: [PATCH 7/8] Update `var` with fake default value to the more "correct" `lateinit var` --- .../samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt index 9f5f46099..a2fdbaee1 100644 --- a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt +++ b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt @@ -34,7 +34,7 @@ class NewsResourceCardTest { @Test fun testMetaDataDisplay_withCodelabResource() { val newsWithKnownResourceType = userNewsResourcesTestData[0] - var dateFormatted = "" + lateinit var dateFormatted: String composeTestRule.setContent { NewsResourceCardExpanded( @@ -63,7 +63,7 @@ class NewsResourceCardTest { @Test fun testMetaDataDisplay_withEmptyResourceType() { val newsWithEmptyResourceType = userNewsResourcesTestData[3] - var dateFormatted = "" + lateinit var dateFormatted: String composeTestRule.setContent { NewsResourceCardExpanded( From 0ced769999741fd86e7cb06fd67785e3f8d45d99 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Wed, 16 Aug 2023 19:19:06 +0200 Subject: [PATCH 8/8] Widen `isNotEmpty` with `isNotBlank` to potentially catch blank values --- .../samples/apps/nowinandroid/core/ui/NewsResourceCard.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt index 936f4c6f3..908e3352c 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt @@ -267,7 +267,7 @@ fun NewsResourceMetaData( ) { val formattedDate = dateFormatted(publishDate) Text( - if (resourceType.isNotEmpty()) { + if (resourceType.isNotBlank()) { stringResource(R.string.card_meta_data_text, formattedDate, resourceType) } else { formattedDate