Rename episode to NewsResource, add episode to NewsResource, add mockk and unit test, address comments
Change-Id: I473cb22cfed2ba33664296183da8136d41b37a63pull/2/head
parent
42fa0e3a55
commit
12cff2074c
@ -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()
|
Loading…
Reference in new issue