A small Reddit Android client developed using Kotlin
https://android.jlelse.eu/learn-kotlin-while-developing-an-android-app-introduction-567e21ff9664
- Retrofit 2.0
- Coroutines (previously with RxJava)
- Picasso
- Dagger 2
- Kotlin Android Extensions
Small Reddit Android client developed with Kotlin
A small Reddit Android client developed using Kotlin
https://android.jlelse.eu/learn-kotlin-while-developing-an-android-app-introduction-567e21ff9664
Hello. Thank you for your work.
The page http://www.andevcon.com/news/keddit-part-10-kotlin-dagger-2-dependency-injection with your article "Part 10: Adding Dagger 2" is not available. Where can I read this?
I used RxJava 2 in my code, to test it, I modify some code, it works.
package cn.anguiao.keddit
import cn.anguiao.keddit.api.*
import cn.anguiao.keddit.commons.RedditNews
import cn.anguiao.keddit.features.news.NewsManager
import io.reactivex.observers.TestObserver
import okhttp3.MediaType
import okhttp3.ResponseBody
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mockito
import org.mockito.Mockito.`when`
import retrofit2.Call
import retrofit2.Response
import java.util.*
class NewsManagerTest {
inline fun <reified T : Any> mock(): T = Mockito.mock(T::class.java)
var testObserver = TestObserver<RedditNews>()
var apiMock = mock<NewsApi>()
var callMock = mock<Call<RedditNewsResponse>>()
@Before
fun setup() {
testObserver = TestObserver<RedditNews>()
apiMock = mock<NewsApi>()
callMock = mock<Call<RedditNewsResponse>>()
`when`(apiMock.getNews(anyString(), anyString())).thenReturn(callMock)
}
@Test
fun testSuccess_basic() {
// prepare
val redditNewsResponse = RedditNewsResponse(RedditDataResponse(listOf(), null, null))
val response = Response.success(redditNewsResponse)
`when`(callMock.execute()).thenReturn(response)
// call
val newsManager = NewsManager(apiMock)
newsManager.getNews("").subscribe(testObserver)
// assert
testObserver.assertNoErrors()
testObserver.assertValueCount(1)
testObserver.assertComplete()
}
@Test
fun testSuccess_checkOneNews() {
// prepare
val newsData = RedditNewsDataResponse(
"author",
"title",
10,
Date().time,
"thumbnail",
"url",
"id"
)
val newsResponse = RedditChildrenResponse(newsData)
val redditNewsResponse = RedditNewsResponse(RedditDataResponse(listOf(newsResponse), null, null))
val response = Response.success(redditNewsResponse)
`when`(callMock.execute()).thenReturn(response)
// call
val newsManager = NewsManager(apiMock)
newsManager.getNews("").subscribe(testObserver)
// assert
testObserver.assertNoErrors()
testObserver.assertValueCount(1)
testObserver.assertComplete()
assert(testObserver.values()[0].news[0].author == newsData.author)
assert(testObserver.values()[0].news[0].title == newsData.title)
}
@Test
fun testError() {
// prepare
val responseError = Response.error<RedditNewsResponse>(500,
ResponseBody.create(MediaType.parse("application/json"), ""))
`when`(callMock.execute()).thenReturn(responseError)
// call
val newsManager = NewsManager(apiMock)
newsManager.getNews("").subscribe(testObserver)
// assert
assert(testObserver.errors().size == 1)
}
}
Sorry to open an issue here,
I cannot write a response under your article in Medium
I really enjoy reading your articles,
Can I translate them into Chinese?
I want publish them in my blog
Thanks for your great work.
Hi,
hope find you well with this cold call.
I am an author of mocking framework for Kotlin
I see you are using mockito-kotlin.
I just want you to be aware that there is solution that fully supports Kotlin and ask to try it in your new/current projects.
I can help you if you answer to this issue.
Thanks and please star it
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.