From 3ad70e39e01907aa16a9dd5387b8c493f08784be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Moczkowski?= Date: Tue, 16 May 2023 11:24:08 +0200 Subject: [PATCH] Remove unused data-test module Change-Id: Id17d0316aa5db431448401a382e2a7629909b637 --- app/build.gradle.kts | 1 - .../data/test/AlwaysOnlineNetworkMonitor.kt | 26 ------- .../core/data/test/TestDataModule.kt | 71 ------------------ .../repository/fake/FakeNewsRepository.kt | 73 ------------------- .../fake/FakeRecentSearchRepository.kt | 35 --------- .../fake/FakeSearchContentsRepository.kt | 33 --------- .../repository/fake/FakeTopicsRepository.kt | 63 ---------------- .../repository/fake/FakeUserDataRepository.kt | 68 ----------------- settings.gradle.kts | 15 ++-- 9 files changed, 7 insertions(+), 378 deletions(-) delete mode 100644 core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/AlwaysOnlineNetworkMonitor.kt delete mode 100644 core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/TestDataModule.kt delete mode 100644 core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeNewsRepository.kt delete mode 100644 core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeRecentSearchRepository.kt delete mode 100644 core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeSearchContentsRepository.kt delete mode 100644 core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeTopicsRepository.kt delete mode 100644 core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeUserDataRepository.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0c6e3eeb9..e61862c6c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -98,7 +98,6 @@ dependencies { androidTestImplementation(project(":core:testing")) androidTestImplementation(project(":core:datastore-test")) - androidTestImplementation(project(":core:data-test")) androidTestImplementation(project(":core:network")) androidTestImplementation(libs.androidx.navigation.testing) androidTestImplementation(libs.accompanist.testharness) diff --git a/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/AlwaysOnlineNetworkMonitor.kt b/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/AlwaysOnlineNetworkMonitor.kt deleted file mode 100644 index c00c99ded..000000000 --- a/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/AlwaysOnlineNetworkMonitor.kt +++ /dev/null @@ -1,26 +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.test - -import com.google.samples.apps.nowinandroid.core.data.util.NetworkMonitor -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flowOf -import javax.inject.Inject - -class AlwaysOnlineNetworkMonitor @Inject constructor() : NetworkMonitor { - override val isOnline: Flow = flowOf(true) -} diff --git a/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/TestDataModule.kt b/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/TestDataModule.kt deleted file mode 100644 index 2ec2bcf9c..000000000 --- a/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/TestDataModule.kt +++ /dev/null @@ -1,71 +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.test - -import com.google.samples.apps.nowinandroid.core.data.di.DataModule -import com.google.samples.apps.nowinandroid.core.data.repository.NewsRepository -import com.google.samples.apps.nowinandroid.core.data.repository.RecentSearchRepository -import com.google.samples.apps.nowinandroid.core.data.repository.SearchContentsRepository -import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepository -import com.google.samples.apps.nowinandroid.core.data.repository.UserDataRepository -import com.google.samples.apps.nowinandroid.core.data.repository.fake.FakeNewsRepository -import com.google.samples.apps.nowinandroid.core.data.repository.fake.FakeRecentSearchRepository -import com.google.samples.apps.nowinandroid.core.data.repository.fake.FakeSearchContentsRepository -import com.google.samples.apps.nowinandroid.core.data.repository.fake.FakeTopicsRepository -import com.google.samples.apps.nowinandroid.core.data.repository.fake.FakeUserDataRepository -import com.google.samples.apps.nowinandroid.core.data.util.NetworkMonitor -import dagger.Binds -import dagger.Module -import dagger.hilt.components.SingletonComponent -import dagger.hilt.testing.TestInstallIn - -@Module -@TestInstallIn( - components = [SingletonComponent::class], - replaces = [DataModule::class], -) -interface TestDataModule { - @Binds - fun bindsTopicRepository( - fakeTopicsRepository: FakeTopicsRepository, - ): TopicsRepository - - @Binds - fun bindsNewsResourceRepository( - fakeNewsRepository: FakeNewsRepository, - ): NewsRepository - - @Binds - fun bindsUserDataRepository( - userDataRepository: FakeUserDataRepository, - ): UserDataRepository - - @Binds - fun bindsRecentSearchRepository( - recentSearchRepository: FakeRecentSearchRepository, - ): RecentSearchRepository - - @Binds - fun bindsSearchContentsRepository( - searchContentsRepository: FakeSearchContentsRepository, - ): SearchContentsRepository - - @Binds - fun bindsNetworkMonitor( - networkMonitor: AlwaysOnlineNetworkMonitor, - ): NetworkMonitor -} diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeNewsRepository.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeNewsRepository.kt deleted file mode 100644 index 39ad05d1e..000000000 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeNewsRepository.kt +++ /dev/null @@ -1,73 +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.repository.fake - -import com.google.samples.apps.nowinandroid.core.data.Synchronizer -import com.google.samples.apps.nowinandroid.core.data.model.asEntity -import com.google.samples.apps.nowinandroid.core.data.repository.NewsRepository -import com.google.samples.apps.nowinandroid.core.data.repository.NewsResourceQuery -import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceEntity -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.model.NetworkNewsResource -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.flow.flowOn -import javax.inject.Inject - -/** - * Fake implementation of the [NewsRepository] that retrieves the news resources from a JSON String. - * - * This allows us to run the app with fake data, without needing an internet connection or working - * backend. - */ -class FakeNewsRepository @Inject constructor( - @Dispatcher(IO) private val ioDispatcher: CoroutineDispatcher, - private val datasource: FakeNiaNetworkDataSource, -) : NewsRepository { - - override fun getNewsResources( - query: NewsResourceQuery, - ): Flow> = - flow { - emit( - datasource - .getNewsResources() - .filter { networkNewsResource -> - // Filter out any news resources which don't match the current query. - // If no query parameters (filterTopicIds or filterNewsIds) are specified - // then the news resource is returned. - listOfNotNull( - true, - query.filterNewsIds?.contains(networkNewsResource.id), - query.filterTopicIds?.let { filterTopicIds -> - networkNewsResource.topics.intersect(filterTopicIds).isNotEmpty() - }, - ) - .all(true::equals) - } - .map(NetworkNewsResource::asEntity) - .map(NewsResourceEntity::asExternalModel), - ) - }.flowOn(ioDispatcher) - - override suspend fun syncWith(synchronizer: Synchronizer) = true -} diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeRecentSearchRepository.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeRecentSearchRepository.kt deleted file mode 100644 index fc649f3ec..000000000 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeRecentSearchRepository.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2023 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.repository.fake - -import com.google.samples.apps.nowinandroid.core.data.model.RecentSearchQuery -import com.google.samples.apps.nowinandroid.core.data.repository.RecentSearchRepository -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flowOf -import javax.inject.Inject - -/** - * Fake implementation of the [RecentSearchRepository] - */ -class FakeRecentSearchRepository @Inject constructor() : RecentSearchRepository { - override suspend fun insertOrReplaceRecentSearch(searchQuery: String) { /* no-op */ } - - override fun getRecentSearchQueries(limit: Int): Flow> = - flowOf(emptyList()) - - override suspend fun clearRecentSearches() { /* no-op */ } -} diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeSearchContentsRepository.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeSearchContentsRepository.kt deleted file mode 100644 index d15890a10..000000000 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeSearchContentsRepository.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2023 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.repository.fake - -import com.google.samples.apps.nowinandroid.core.data.repository.SearchContentsRepository -import com.google.samples.apps.nowinandroid.core.model.data.SearchResult -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flowOf -import javax.inject.Inject - -/** - * Fake implementation of the [SearchContentsRepository] - */ -class FakeSearchContentsRepository @Inject constructor() : SearchContentsRepository { - - override suspend fun populateFtsData() { /* no-op */ } - override fun searchContents(searchQuery: String): Flow = flowOf() - override fun getSearchContentsCount(): Flow = flowOf(1) -} diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeTopicsRepository.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeTopicsRepository.kt deleted file mode 100644 index 1ab9c9353..000000000 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeTopicsRepository.kt +++ /dev/null @@ -1,63 +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.repository.fake - -import com.google.samples.apps.nowinandroid.core.data.Synchronizer -import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepository -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 kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.flow.flowOn -import kotlinx.coroutines.flow.map -import javax.inject.Inject - -/** - * Fake implementation of the [TopicsRepository] that retrieves the topics from a JSON String, and - * uses a local DataStore instance to save and retrieve followed topic ids. - * - * This allows us to run the app with fake data, without needing an internet connection or working - * backend. - */ -class FakeTopicsRepository @Inject constructor( - @Dispatcher(IO) private val ioDispatcher: CoroutineDispatcher, - private val datasource: FakeNiaNetworkDataSource, -) : TopicsRepository { - override fun getTopics(): Flow> = flow { - emit( - datasource.getTopics().map { - Topic( - id = it.id, - name = it.name, - shortDescription = it.shortDescription, - longDescription = it.longDescription, - url = it.url, - imageUrl = it.imageUrl, - ) - }, - ) - }.flowOn(ioDispatcher) - - override fun getTopic(id: String): Flow { - return getTopics().map { it.first { topic -> topic.id == id } } - } - - override suspend fun syncWith(synchronizer: Synchronizer) = true -} diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeUserDataRepository.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeUserDataRepository.kt deleted file mode 100644 index 74813389e..000000000 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeUserDataRepository.kt +++ /dev/null @@ -1,68 +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.repository.fake - -import com.google.samples.apps.nowinandroid.core.data.repository.UserDataRepository -import com.google.samples.apps.nowinandroid.core.datastore.NiaPreferencesDataSource -import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig -import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand -import com.google.samples.apps.nowinandroid.core.model.data.UserData -import kotlinx.coroutines.flow.Flow -import javax.inject.Inject - -/** - * Fake implementation of the [UserDataRepository] that returns hardcoded user data. - * - * This allows us to run the app with fake data, without needing an internet connection or working - * backend. - */ -class FakeUserDataRepository @Inject constructor( - private val niaPreferencesDataSource: NiaPreferencesDataSource, -) : UserDataRepository { - - override val userData: Flow = - niaPreferencesDataSource.userData - - override suspend fun setFollowedTopicIds(followedTopicIds: Set) = - niaPreferencesDataSource.setFollowedTopicIds(followedTopicIds) - - override suspend fun toggleFollowedTopicId(followedTopicId: String, followed: Boolean) = - niaPreferencesDataSource.toggleFollowedTopicId(followedTopicId, followed) - - override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) { - niaPreferencesDataSource.toggleNewsResourceBookmark(newsResourceId, bookmarked) - } - - override suspend fun setNewsResourceViewed(newsResourceId: String, viewed: Boolean) = - niaPreferencesDataSource.setNewsResourceViewed(newsResourceId, viewed) - - override suspend fun setThemeBrand(themeBrand: ThemeBrand) { - niaPreferencesDataSource.setThemeBrand(themeBrand) - } - - override suspend fun setDarkThemeConfig(darkThemeConfig: DarkThemeConfig) { - niaPreferencesDataSource.setDarkThemeConfig(darkThemeConfig) - } - - override suspend fun setDynamicColorPreference(useDynamicColor: Boolean) { - niaPreferencesDataSource.setDynamicColorPreference(useDynamicColor) - } - - override suspend fun setShouldHideOnboarding(shouldHideOnboarding: Boolean) { - niaPreferencesDataSource.setShouldHideOnboarding(shouldHideOnboarding) - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index d0c477b3d..41708bfcb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -31,12 +31,13 @@ dependencyResolutionManagement { } } rootProject.name = "nowinandroid" + include(":app") include(":app-nia-catalog") include(":benchmarks") +include(":core:analytics") include(":core:common") include(":core:data") -include(":core:data-test") include(":core:database") include(":core:datastore") include(":core:datastore-test") @@ -44,18 +45,16 @@ include(":core:designsystem") include(":core:domain") include(":core:model") include(":core:network") -include(":core:ui") -include(":core:testing") -include(":core:analytics") include(":core:notifications") - +include(":core:testing") +include(":core:ui") +include(":feature:bookmarks") include(":feature:foryou") include(":feature:interests") -include(":feature:bookmarks") -include(":feature:topic") include(":feature:search") include(":feature:settings") +include(":feature:topic") include(":lint") -include(":sync:work") include(":sync:sync-test") +include(":sync:work") include(":ui-test-hilt-manifest")