Rename episode to NewsResource, add episode to NewsResource, add mockk and unit test, address comments

Change-Id: I473cb22cfed2ba33664296183da8136d41b37a63
pull/2/head
Adetunji Dahunsi 3 years ago
parent 42fa0e3a55
commit 12cff2074c

@ -60,6 +60,11 @@ android {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
}
dependencies {
@ -88,6 +93,10 @@ dependencies {
debugImplementation libs.androidx.compose.ui.testManifest
testImplementation libs.junit4
testImplementation libs.mockk
testImplementation libs.androidx.test.core
androidTestImplementation libs.junit4
androidTestImplementation libs.androidx.test.core
androidTestImplementation libs.androidx.test.espresso.core

@ -0,0 +1,44 @@
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.samples.apps.nowinandroid.data.news
import java.util.Date
/**
* Item representing a summary of a noteworthy item from a Now In Android episode
*/
data class NewsResource(
val episode: Int,
val title: String,
val content: String,
val url: String,
val authorName: String,
// TODO: Replace this with a type from kotlinx-datetime or similar in row al0AcTYbwbU6lyRWL5dOQ1
val publishDate: Date,
val type: String,
val topics: List<String>,
val alternateVideo: VideoInfo?
)
/**
* Data class summarizing video metadata
*/
data class VideoInfo(
val url: String,
val startTimestamp: String,
val endTimestamp: String,
)

@ -0,0 +1,29 @@
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.samples.apps.nowinandroid.data.news
import kotlinx.coroutines.flow.Flow
/**
* Data layer implementation for [NewsResource]
*/
interface NewsResourceRepository {
/**
* Fetches available news resources
*/
fun monitor(): Flow<List<NewsResource>>
}

@ -0,0 +1,35 @@
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.samples.apps.nowinandroid.data.news.fake
import android.content.Context
import com.google.samples.apps.nowinandroid.R
import com.google.samples.apps.nowinandroid.data.news.NewsResource
import com.google.samples.apps.nowinandroid.data.news.NewsResourceRepository
import kotlinx.coroutines.flow.Flow
/**
* [NewsResourceRepository] implementation that provides static news resources to aid development
*/
class FakeNewsResourceRepository(
private val context: Context
) : NewsResourceRepository {
override fun monitor(): Flow<List<NewsResource>> {
context.resources.openRawResource(R.raw.data)
TODO("Deserialize json and return news resources")
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,69 @@
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.samples.apps.nowinandroid.data.news.fake
import android.content.Context
import android.content.res.Resources
import com.google.samples.apps.nowinandroid.R
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.runBlocking
import org.junit.Before
class FakeNewsResourceRepositoryTest {
private lateinit var subject: FakeNewsResourceRepository
@Before
fun setup() {
val context = mockk<Context>()
val resources = mockk<Resources>()
every { resources.openRawResource(R.raw.data) } returns testResourcesJson.byteInputStream()
every { context.resources } returns resources
subject = FakeNewsResourceRepository(context)
}
@org.junit.Test
fun newsResources() = runBlocking {
// TODO: Implement this
// assertEquals(listOf<NewsResource>(), subject.monitor().first())
}
}
private val testResourcesJson = """
[
{
"episode": 52,
"title": "MAD Skills: Paging Q&A",
"content": "In this live session, TJ and Dustin answered your questions in the usual live Q&A format.",
"URL": "https://youtu.be/8i6vrlbIVCc",
"authorName": "",
"publishDate": "2021-11-11T00:00:00.000Z",
"type": "Video 📺",
"topics": [
"MAD Skills",
"Paging"
],
"alternateVideo": {
"URL": "",
"startTimestamp": "",
"endTimestamp": ""
}
}
]
""".trimIndent()

@ -17,6 +17,7 @@ kotlin = "1.6.0"
kotlinxCoroutines = "1.5.2"
ktlint = "0.43.0"
material3 = "1.5.0-alpha05"
mockk = "1.12.1"
spotless = "6.0.0"
[libraries]
@ -46,6 +47,7 @@ junit4 = { group = "junit", name = "junit", version.ref = "junit4" }
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinxCoroutines" }
material3 = { group = "com.google.android.material", name = "material", version.ref = "material3" }
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
[plugins]
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }

Loading…
Cancel
Save