Skip to content
Permalink
Browse files

unit test

  • Loading branch information...
imuhao committed Nov 9, 2017
1 parent 8d127bd commit 69a7a0591973dc4ffc5fd0885f61d649c6bf61c5
@@ -44,4 +44,9 @@ dependencies {
kapt 'com.google.dagger:dagger-compiler:2.11'
provided 'org.glassfish:javax.annotation:10.0-b28'

testCompile "org.mockito:mockito-core:2.+"
testCompile 'junit:junit:4.12'
testCompile 'com.nhaarman:mockito-kotlin:0.7.0'
testCompile 'org.jetbrains.spek:spek:1.0.25'

}
@@ -0,0 +1,12 @@
package com.caimuhao.kedditbysteps.api

import retrofit2.Call

/**
* @author Smile
* @time 2017/11/9 16:40
* @desc ${TODD}
*/
interface NewsApi {
fun getNews(after: String, limit: Int): Call<RedditNewsResponse>
}
@@ -10,7 +10,7 @@ import retrofit2.converter.moshi.MoshiConverterFactory
* @desc ${TODD}
*/

class RestApi {
class RestApi : NewsApi {
private val redditApi: RedditApi

init {
@@ -21,7 +21,7 @@ class RestApi {
redditApi = retrofit.create(RedditApi::class.java)
}

fun getNews(after: String, limit: Int): Call<RedditNewsResponse> {
override fun getNews(after: String, limit: Int): Call<RedditNewsResponse> {
return redditApi.getTop(after, limit)
}

@@ -31,6 +31,7 @@ fun ImageView.loadImg(imageUrl: String) {
}
}


fun Fragment.showToast(message: String, duration: Int = Toast.LENGTH_SHORT) {
Toast.makeText(context, message, duration).show()
}
@@ -76,5 +76,7 @@ class NewsFragment : BaseFragment() {
showSnackbar(news_list, error.message ?: "")
})
subscriptions.add(subscribe)


}
}
@@ -1,5 +1,6 @@
package com.caimuhao.kedditbysteps.fatures.news

import com.caimuhao.kedditbysteps.api.NewsApi
import com.caimuhao.kedditbysteps.api.RestApi
import com.caimuhao.kedditbysteps.bean.RedditNews
import com.caimuhao.kedditbysteps.bean.RedditNewsItem
@@ -10,9 +11,9 @@ import rx.Observable
* @time 2017/11/6 14:45
* @desc ${TODD}
*/
class NewsManager(private val api: RestApi = RestApi()) {
class NewsManager(private val api: NewsApi = RestApi()) {

fun getNews(after: String, limit: Int): Observable<RedditNews> {
fun getNews(after: String, limit: Int = 10): Observable<RedditNews> {
return Observable.create { subscriber ->
val execute = api.getNews(after, limit).execute()
var response = execute.body().data
@@ -19,6 +19,9 @@ allprojects {
repositories {
google()
jcenter()
maven {
url "http://repository.jetbrains.com/all"
}
}
}

0 comments on commit 69a7a05

Please sign in to comment.
You can’t perform that action at this time.