Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[small]feature/82 #86

Merged
merged 7 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "com.josdem.fruitypedia"
minSdk 21
targetSdk 34
versionCode 7
versionName "1.1.3"
versionCode 8
versionName "1.2.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -65,6 +65,7 @@ dependencies {
implementation 'com.google.firebase:firebase-analytics'
testImplementation 'junit:junit:4.13.2'
testImplementation 'io.mockk:mockk:1.13.8'
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1"
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
//TODO: Remove debugImplementation since it is a temporal fix to this Junit issue:
//https://github.com/android/android-test/issues/1755
Expand Down
84 changes: 84 additions & 0 deletions app/src/test/java/com/josdem/fruitypedia/FruityServiceTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright 2024 Jose Morales [email protected]

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

http://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.josdem.fruitypedia

import com.josdem.fruitypedia.model.Beverage
import com.josdem.fruitypedia.model.Category
import com.josdem.fruitypedia.service.FruityService
import com.josdem.fruitypedia.service.RetrofitHelper
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.test.runTest
import org.junit.Test
import retrofit2.Response

const val LANGUAGE = "en"
const val CATEGORY = 5
const val BEVERAGE = 85

class FruityServiceTest {
private val fruityService: FruityService =
RetrofitHelper.getInstance().create(FruityService::class.java)

private suspend fun getCategories(): Response<List<Category>> {
return fruityService.getCategories(LANGUAGE)
}

private suspend fun getBeverages(): Response<List<Beverage>> {
return fruityService.getBeverages(CATEGORY)
}

private suspend fun getBeverage(): Response<Beverage> {
return fruityService.getBeverage(BEVERAGE)
}

@Test
fun shouldGetCategories() =
runTest {
val response = getCategories()
val categories: List<Category>? = response.body()
assertTrue(response.isSuccessful)
assertEquals(4, categories?.size)
}

@Test
fun shouldGetBeverages() =
runTest {
val response = getBeverages()
val beverages: List<Beverage>? = response.body()
assertTrue(response.isSuccessful)
assertEquals(14, beverages?.size)
}

@Test
fun shouldGetBeverage() =
runTest {
val response = getBeverage()
val beverage: Beverage? = response.body()
assertTrue(response.isSuccessful)
assertEquals("Anti-constipation Smoothie", beverage?.name)
assertEquals("https://storage.googleapis.com/jugoterapia/85.jpg", beverage?.image)
assertEquals("1 Apple,1 Pear", beverage?.ingredients)
assertEquals(
"Start your day with apple and pear without peel getting juice as much as you can utilizing juice extractor" +
" or using just a blender. Apple juice contains sorbitol, " +
"natural sugar which helps to our body to avoid persistent constipation",
beverage?.recipe,
)
}
}
Loading