Skip to content

Commit 3c9e296

Browse files
Merge pull request velmurugan-murugesan#8 from velmurugan-murugesan/mvvm-testing
updated test cases
2 parents 11871b1 + f8f6bc1 commit 3c9e296

22 files changed

Lines changed: 341 additions & 24 deletions

File tree

MVVMwithKotlinCoroutinesandRetrofit/.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MVVMwithKotlinCoroutinesandRetrofit/.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MVVMwithKotlinCoroutinesandRetrofit/.idea/compiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MVVMwithKotlinCoroutinesandRetrofit/.idea/gradle.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MVVMwithKotlinCoroutinesandRetrofit/.idea/jarRepositories.xml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MVVMwithKotlinCoroutinesandRetrofit/.idea/misc.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MVVMwithKotlinCoroutinesandRetrofit/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MVVMwithKotlinCoroutinesandRetrofit/app/build.gradle

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ android {
3737
viewBinding = true
3838
}
3939

40+
packagingOptions {
41+
exclude 'META-INF/*'
42+
}
43+
4044
}
4145

4246
dependencies {
@@ -49,7 +53,11 @@ dependencies {
4953
testImplementation 'junit:junit:4.+'
5054
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
5155
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
52-
56+
testImplementation 'org.mockito:mockito-core:2.28.2'
57+
androidTestImplementation 'org.mockito:mockito-android:2.24.5'
58+
implementation 'androidx.arch.core:core-testing:2.0.1'
59+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.0'
60+
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.0'
5361
// Networking
5462
implementation "com.squareup.retrofit2:retrofit:2.9.0"
5563
implementation "com.squareup.okhttp3:okhttp:4.7.2"
@@ -67,4 +75,6 @@ dependencies {
6775
//Glide
6876
implementation 'com.github.bumptech.glide:glide:4.12.0'
6977
kapt 'com.github.bumptech.glide:compiler:4.12.0'
78+
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.0'
79+
7080
}

MVVMwithKotlinCoroutinesandRetrofit/app/src/main/java/com/velmurugan/mvvmwithkotlincoroutinesandretrofit/MainViewModel.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ class MainViewModel constructor(private val mainRepository: MainRepository) : Vi
99
val errorMessage = MutableLiveData<String>()
1010
val movieList = MutableLiveData<List<Movie>>()
1111
var job: Job? = null
12-
val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
12+
private val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
1313
onError("Exception handled: ${throwable.localizedMessage}")
1414
}
1515
val loading = MutableLiveData<Boolean>()
1616

1717
fun getAllMovies() {
18+
1819
job = CoroutineScope(Dispatchers.IO + exceptionHandler).launch {
20+
loading.postValue(true)
1921
val response = mainRepository.getAllMovies()
2022
withContext(Dispatchers.Main) {
2123
if (response.isSuccessful) {

MVVMwithKotlinCoroutinesandRetrofit/app/src/main/java/com/velmurugan/mvvmwithkotlincoroutinesandretrofit/MovieAdapter.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ class MovieAdapter : RecyclerView.Adapter<MainViewHolder>() {
2525
override fun onBindViewHolder(holder: MainViewHolder, position: Int) {
2626

2727
val movie = movieList[position]
28-
holder.binding.name.text = movie.name
29-
Glide.with(holder.itemView.context).load(movie.imageUrl).into(holder.binding.imageview)
28+
if (ValidationUtil.validateMovie(movie)) {
29+
holder.binding.name.text = movie.name
30+
Glide.with(holder.itemView.context).load(movie.imageUrl).into(holder.binding.imageview)
31+
}
3032
}
3133

3234
override fun getItemCount(): Int {

0 commit comments

Comments
 (0)