From 27ca860745f0d3070119a64fde668ab68f518bbc Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Sat, 16 Mar 2024 21:35:20 +0900 Subject: [PATCH 1/6] Rename fake to demo. Change-Id: I5b1d7963e623832a766900aa74ef1085aac0cacc --- .../data/test/repository/FakeNewsRepository.kt | 4 ++-- .../data/test/repository/FakeTopicsRepository.kt | 4 ++-- .../data/testdoubles/TestNiaNetworkDataSource.kt | 4 ++-- .../core/network/di/FlavoredNetworkModule.kt | 4 ++-- ...etManager.kt => JvmUnitTestDemoAssetManager.kt} | 4 ++-- .../DemoAssetManager.kt} | 6 +++--- .../DemoNiaNetworkDataSource.kt} | 10 +++++----- .../nowinandroid/core/network/di/NetworkModule.kt | 4 ++-- .../DemoNiaNetworkDataSourceTest.kt} | 14 +++++++------- 9 files changed, 27 insertions(+), 27 deletions(-) rename core/network/src/main/kotlin/{JvmUnitTestFakeAssetManager.kt => JvmUnitTestDemoAssetManager.kt} (92%) rename core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/{fake/FakeAssetManager.kt => demo/DemoAssetManager.kt} (81%) rename core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/{fake/FakeNiaNetworkDataSource.kt => demo/DemoNiaNetworkDataSource.kt} (91%) rename core/network/src/test/kotlin/com/google/samples/apps/nowinandroid/core/network/{fake/FakeNiaNetworkDataSourceTest.kt => demo/DemoNiaNetworkDataSourceTest.kt} (90%) diff --git a/core/data-test/src/main/kotlin/com/google/samples/apps/nowinandroid/core/data/test/repository/FakeNewsRepository.kt b/core/data-test/src/main/kotlin/com/google/samples/apps/nowinandroid/core/data/test/repository/FakeNewsRepository.kt index 5ceff4dd0..070c7ed38 100644 --- a/core/data-test/src/main/kotlin/com/google/samples/apps/nowinandroid/core/data/test/repository/FakeNewsRepository.kt +++ b/core/data-test/src/main/kotlin/com/google/samples/apps/nowinandroid/core/data/test/repository/FakeNewsRepository.kt @@ -25,7 +25,7 @@ import com.google.samples.apps.nowinandroid.core.database.model.asExternalModel import com.google.samples.apps.nowinandroid.core.model.data.NewsResource import com.google.samples.apps.nowinandroid.core.network.Dispatcher import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.IO -import com.google.samples.apps.nowinandroid.core.network.fake.FakeNiaNetworkDataSource +import com.google.samples.apps.nowinandroid.core.network.demo.DemoNiaNetworkDataSource import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.Flow @@ -41,7 +41,7 @@ import javax.inject.Inject */ internal class FakeNewsRepository @Inject constructor( @Dispatcher(IO) private val ioDispatcher: CoroutineDispatcher, - private val datasource: FakeNiaNetworkDataSource, + private val datasource: DemoNiaNetworkDataSource, ) : NewsRepository { override fun getNewsResources( diff --git a/core/data-test/src/main/kotlin/com/google/samples/apps/nowinandroid/core/data/test/repository/FakeTopicsRepository.kt b/core/data-test/src/main/kotlin/com/google/samples/apps/nowinandroid/core/data/test/repository/FakeTopicsRepository.kt index f8ebca29e..0b81dd309 100644 --- a/core/data-test/src/main/kotlin/com/google/samples/apps/nowinandroid/core/data/test/repository/FakeTopicsRepository.kt +++ b/core/data-test/src/main/kotlin/com/google/samples/apps/nowinandroid/core/data/test/repository/FakeTopicsRepository.kt @@ -21,7 +21,7 @@ import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepositor import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.network.Dispatcher import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.IO -import com.google.samples.apps.nowinandroid.core.network.fake.FakeNiaNetworkDataSource +import com.google.samples.apps.nowinandroid.core.network.demo.DemoNiaNetworkDataSource import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -38,7 +38,7 @@ import javax.inject.Inject */ internal class FakeTopicsRepository @Inject constructor( @Dispatcher(IO) private val ioDispatcher: CoroutineDispatcher, - private val datasource: FakeNiaNetworkDataSource, + private val datasource: DemoNiaNetworkDataSource, ) : TopicsRepository { override fun getTopics(): Flow> = flow { emit( diff --git a/core/data/src/test/kotlin/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNiaNetworkDataSource.kt b/core/data/src/test/kotlin/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNiaNetworkDataSource.kt index 7f9a69959..7675af7e9 100644 --- a/core/data/src/test/kotlin/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNiaNetworkDataSource.kt +++ b/core/data/src/test/kotlin/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNiaNetworkDataSource.kt @@ -17,7 +17,7 @@ package com.google.samples.apps.nowinandroid.core.data.testdoubles import com.google.samples.apps.nowinandroid.core.network.NiaNetworkDataSource -import com.google.samples.apps.nowinandroid.core.network.fake.FakeNiaNetworkDataSource +import com.google.samples.apps.nowinandroid.core.network.demo.DemoNiaNetworkDataSource import com.google.samples.apps.nowinandroid.core.network.model.NetworkChangeList import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic @@ -35,7 +35,7 @@ enum class CollectionType { */ class TestNiaNetworkDataSource : NiaNetworkDataSource { - private val source = FakeNiaNetworkDataSource( + private val source = DemoNiaNetworkDataSource( UnconfinedTestDispatcher(), Json { ignoreUnknownKeys = true }, ) diff --git a/core/network/src/demo/kotlin/com/google/samples/apps/nowinandroid/core/network/di/FlavoredNetworkModule.kt b/core/network/src/demo/kotlin/com/google/samples/apps/nowinandroid/core/network/di/FlavoredNetworkModule.kt index 850b00201..42c2ffe8f 100644 --- a/core/network/src/demo/kotlin/com/google/samples/apps/nowinandroid/core/network/di/FlavoredNetworkModule.kt +++ b/core/network/src/demo/kotlin/com/google/samples/apps/nowinandroid/core/network/di/FlavoredNetworkModule.kt @@ -17,7 +17,7 @@ package com.google.samples.apps.nowinandroid.core.network.di import com.google.samples.apps.nowinandroid.core.network.NiaNetworkDataSource -import com.google.samples.apps.nowinandroid.core.network.fake.FakeNiaNetworkDataSource +import com.google.samples.apps.nowinandroid.core.network.demo.DemoNiaNetworkDataSource import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -28,5 +28,5 @@ import dagger.hilt.components.SingletonComponent internal interface FlavoredNetworkModule { @Binds - fun binds(impl: FakeNiaNetworkDataSource): NiaNetworkDataSource + fun binds(impl: DemoNiaNetworkDataSource): NiaNetworkDataSource } diff --git a/core/network/src/main/kotlin/JvmUnitTestFakeAssetManager.kt b/core/network/src/main/kotlin/JvmUnitTestDemoAssetManager.kt similarity index 92% rename from core/network/src/main/kotlin/JvmUnitTestFakeAssetManager.kt rename to core/network/src/main/kotlin/JvmUnitTestDemoAssetManager.kt index 79370d5a8..9c86a5c2e 100644 --- a/core/network/src/main/kotlin/JvmUnitTestFakeAssetManager.kt +++ b/core/network/src/main/kotlin/JvmUnitTestDemoAssetManager.kt @@ -15,7 +15,7 @@ */ import androidx.annotation.VisibleForTesting -import com.google.samples.apps.nowinandroid.core.network.fake.FakeAssetManager +import com.google.samples.apps.nowinandroid.core.network.demo.DemoAssetManager import java.io.File import java.io.InputStream import java.util.Properties @@ -26,7 +26,7 @@ import java.util.Properties * @see UnitTestOptions */ @VisibleForTesting -internal object JvmUnitTestFakeAssetManager : FakeAssetManager { +internal object JvmUnitTestDemoAssetManager : DemoAssetManager { private val config = requireNotNull(javaClass.getResource("com/android/tools/test_config.properties")) { """ diff --git a/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeAssetManager.kt b/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt similarity index 81% rename from core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeAssetManager.kt rename to core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt index 53ad7d48d..e5fb07bb3 100644 --- a/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeAssetManager.kt +++ b/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt @@ -1,5 +1,5 @@ /* - * Copyright 2022 The Android Open Source Project + * 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. @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.core.network.fake +package com.google.samples.apps.nowinandroid.core.network.demo import java.io.InputStream -fun interface FakeAssetManager { +fun interface DemoAssetManager { fun open(fileName: String): InputStream } diff --git a/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSource.kt b/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt similarity index 91% rename from core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSource.kt rename to core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt index 6ef90ecff..b7c912c00 100644 --- a/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSource.kt +++ b/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt @@ -1,5 +1,5 @@ /* - * Copyright 2022 The Android Open Source Project + * 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. @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.core.network.fake +package com.google.samples.apps.nowinandroid.core.network.demo -import JvmUnitTestFakeAssetManager +import JvmUnitTestDemoAssetManager import com.google.samples.apps.nowinandroid.core.network.Dispatcher import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.IO import com.google.samples.apps.nowinandroid.core.network.NiaNetworkDataSource @@ -33,10 +33,10 @@ import javax.inject.Inject /** * [NiaNetworkDataSource] implementation that provides static news resources to aid development */ -class FakeNiaNetworkDataSource @Inject constructor( +class DemoNiaNetworkDataSource @Inject constructor( @Dispatcher(IO) private val ioDispatcher: CoroutineDispatcher, private val networkJson: Json, - private val assets: FakeAssetManager = JvmUnitTestFakeAssetManager, + private val assets: DemoAssetManager = JvmUnitTestDemoAssetManager, ) : NiaNetworkDataSource { @OptIn(ExperimentalSerializationApi::class) diff --git a/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt b/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt index a68683c7c..a99464304 100644 --- a/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt +++ b/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt @@ -22,7 +22,7 @@ import coil.ImageLoader import coil.decode.SvgDecoder import coil.util.DebugLogger import com.google.samples.apps.nowinandroid.core.network.BuildConfig -import com.google.samples.apps.nowinandroid.core.network.fake.FakeAssetManager +import com.google.samples.apps.nowinandroid.core.network.demo.DemoAssetManager import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -48,7 +48,7 @@ internal object NetworkModule { @Singleton fun providesFakeAssetManager( @ApplicationContext context: Context, - ): FakeAssetManager = FakeAssetManager(context.assets::open) + ): DemoAssetManager = DemoAssetManager(context.assets::open) @Provides @Singleton diff --git a/core/network/src/test/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt b/core/network/src/test/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSourceTest.kt similarity index 90% rename from core/network/src/test/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt rename to core/network/src/test/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSourceTest.kt index a0c60fdcb..e60cfeb3e 100644 --- a/core/network/src/test/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt +++ b/core/network/src/test/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSourceTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2022 The Android Open Source Project + * 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. @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.core.network.fake +package com.google.samples.apps.nowinandroid.core.network.demo -import JvmUnitTestFakeAssetManager +import JvmUnitTestDemoAssetManager 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 @@ -29,18 +29,18 @@ import org.junit.Before import org.junit.Test import kotlin.test.assertEquals -class FakeNiaNetworkDataSourceTest { +class DemoNiaNetworkDataSourceTest { - private lateinit var subject: FakeNiaNetworkDataSource + private lateinit var subject: DemoNiaNetworkDataSource private val testDispatcher = StandardTestDispatcher() @Before fun setUp() { - subject = FakeNiaNetworkDataSource( + subject = DemoNiaNetworkDataSource( ioDispatcher = testDispatcher, networkJson = Json { ignoreUnknownKeys = true }, - assets = JvmUnitTestFakeAssetManager, + assets = JvmUnitTestDemoAssetManager, ) } From 5d99f381e934f471187aa80ec46a310ff91e6738 Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Sat, 16 Mar 2024 21:37:45 +0900 Subject: [PATCH 2/6] Remove VisibleForTesting. Change-Id: Icd7005ec38495a1a4bc6f1594f70a2c1228538ab --- core/network/src/main/kotlin/JvmUnitTestDemoAssetManager.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/network/src/main/kotlin/JvmUnitTestDemoAssetManager.kt b/core/network/src/main/kotlin/JvmUnitTestDemoAssetManager.kt index 9c86a5c2e..2ef418517 100644 --- a/core/network/src/main/kotlin/JvmUnitTestDemoAssetManager.kt +++ b/core/network/src/main/kotlin/JvmUnitTestDemoAssetManager.kt @@ -14,7 +14,6 @@ * limitations under the License. */ -import androidx.annotation.VisibleForTesting import com.google.samples.apps.nowinandroid.core.network.demo.DemoAssetManager import java.io.File import java.io.InputStream @@ -25,7 +24,7 @@ import java.util.Properties * It must remain on the root package for an easier [Class.getResource] with relative paths. * @see UnitTestOptions */ -@VisibleForTesting + internal object JvmUnitTestDemoAssetManager : DemoAssetManager { private val config = requireNotNull(javaClass.getResource("com/android/tools/test_config.properties")) { From a5be299e3d7d237ae9bf0e1611b8fefbb7398e25 Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Sat, 16 Mar 2024 22:30:41 +0900 Subject: [PATCH 3/6] Move main to demo. Change-Id: I48bb3c26ef02d6302cb7caabcaa17d5b4659031a --- .../apps/nowinandroid/core/network/demo/DemoAssetManager.kt | 0 .../nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename core/network/src/{main => demo}/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt (100%) rename core/network/src/{main => demo}/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt (100%) diff --git a/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt b/core/network/src/demo/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt similarity index 100% rename from core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt rename to core/network/src/demo/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt diff --git a/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt b/core/network/src/demo/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt similarity index 100% rename from core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt rename to core/network/src/demo/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt From 2739168e33b475b5ed1b8c021667c018aea5eb43 Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Sat, 16 Mar 2024 22:54:49 +0900 Subject: [PATCH 4/6] Revert "Move main to demo." This reverts commit a5be299e3d7d237ae9bf0e1611b8fefbb7398e25. --- .../apps/nowinandroid/core/network/demo/DemoAssetManager.kt | 0 .../nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename core/network/src/{demo => main}/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt (100%) rename core/network/src/{demo => main}/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt (100%) diff --git a/core/network/src/demo/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt b/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt similarity index 100% rename from core/network/src/demo/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt rename to core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoAssetManager.kt diff --git a/core/network/src/demo/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt b/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt similarity index 100% rename from core/network/src/demo/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt rename to core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/demo/DemoNiaNetworkDataSource.kt From cd294a8654cff748f1b2114ae7b126be27581fa3 Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Sun, 17 Mar 2024 11:37:32 +0900 Subject: [PATCH 5/6] Change lint ignore name in lint.xml. Change-Id: I3b1e19dedd238ec96bd8debee5fcbcc91bc25094 --- core/network/lint.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/network/lint.xml b/core/network/lint.xml index 59fd50bd5..07c0cae9e 100644 --- a/core/network/lint.xml +++ b/core/network/lint.xml @@ -20,6 +20,6 @@ java.lang.IllegalStateException: () -> kotlin.String at org.jetbrains.kotlin.asJava.classes.KtLightClassForFacadeImpl$Companion.createForFacadeNoCache --> - + From 3c70183ce61d4f0e6b5856a3dc406c3c89cf047d Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Mon, 18 Mar 2024 19:28:06 +0900 Subject: [PATCH 6/6] Change name Fake to Demo. Change-Id: Ife321dd95238227bfdfc1f13f6832472bd699b6f --- .../samples/apps/nowinandroid/core/network/di/NetworkModule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt b/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt index a99464304..a97540f2b 100644 --- a/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt +++ b/core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt @@ -46,7 +46,7 @@ internal object NetworkModule { @Provides @Singleton - fun providesFakeAssetManager( + fun providesDemoAssetManager( @ApplicationContext context: Context, ): DemoAssetManager = DemoAssetManager(context.assets::open)