-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into main
- Loading branch information
Showing
8 changed files
with
292 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...t/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCategoriesListUseCaseImplTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.hieuwu.groceriesstore.domain.usecases.impl | ||
|
||
import com.hieuwu.groceriesstore.data.repository.CategoryRepository | ||
import com.hieuwu.groceriesstore.domain.models.CategoryModel | ||
import com.hieuwu.groceriesstore.domain.usecases.GetCategoriesListUseCase | ||
import junit.framework.TestCase.assertEquals | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.MockitoJUnitRunner | ||
import org.mockito.kotlin.whenever | ||
|
||
@RunWith(MockitoJUnitRunner::class) | ||
|
||
class GetCategoriesListUseCaseImplTest { | ||
|
||
@Mock | ||
lateinit var mockedCategoryRepository: CategoryRepository | ||
|
||
private lateinit var testee: GetCategoriesListUseCaseImpl | ||
|
||
@Before | ||
fun setUp() { | ||
testee = GetCategoriesListUseCaseImpl( | ||
categoryRepository = mockedCategoryRepository | ||
) | ||
} | ||
|
||
@Test | ||
fun givenCategoriesAvailable_whenExecute_thenReturnCorrectValue() { | ||
val mockCategories = listOf( | ||
CategoryModel(id = "1", name = "Category 1", image = "image1.jpg"), | ||
CategoryModel(id = "2", name = "Category 2", image = "image2.jpg"), | ||
CategoryModel(id = "3", name = "Category 3", image = "image3.jpg"), | ||
CategoryModel(id = "4", name = "Category 4", image = "image4.jpg") | ||
) | ||
whenever(mockedCategoryRepository.getFromLocal()).thenReturn(flow { | ||
emit(mockCategories) | ||
}) | ||
runBlocking { | ||
val result = testee.execute(GetCategoriesListUseCase.Input()) | ||
|
||
result.result.collect { categories -> | ||
assertEquals(mockCategories[0], categories[0]) | ||
assertEquals(mockCategories[1], categories[1]) | ||
assertEquals(mockCategories[2], categories[2]) | ||
assertEquals(mockCategories[1].name, "Category 2") | ||
assertEquals(mockCategories[3].image, "image4.jpg") | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun givenCategoriesUnavailable_whenExecute_thenReturnCorrectValue() { | ||
whenever(mockedCategoryRepository.getFromLocal()).thenReturn(flow { | ||
emit(listOf()) | ||
}) | ||
runBlocking { | ||
val result = testee.execute(GetCategoriesListUseCase.Input()) | ||
result.result.collect { | ||
assertEquals(it.isEmpty(), true) | ||
} | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCurrentCartUseCaseImplTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.hieuwu.groceriesstore.domain.usecases.impl | ||
|
||
import com.hieuwu.groceriesstore.data.repository.OrderRepository | ||
import com.hieuwu.groceriesstore.domain.models.OrderModel | ||
import com.hieuwu.groceriesstore.domain.usecases.GetCurrentCartUseCase | ||
import com.hieuwu.groceriesstore.utilities.OrderStatus | ||
import junit.framework.TestCase.assertEquals | ||
import junit.framework.TestCase.assertNull | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.MockitoJUnitRunner | ||
import org.mockito.kotlin.whenever | ||
|
||
@RunWith(MockitoJUnitRunner::class) | ||
|
||
class GetCurrentCartUseCaseImplTest { | ||
|
||
@Mock | ||
lateinit var mockedOrderRepository: OrderRepository | ||
|
||
private lateinit var testee: GetCurrentCartUseCaseImpl | ||
|
||
@Before | ||
fun setUp() { | ||
testee = GetCurrentCartUseCaseImpl( | ||
orderRepository = mockedOrderRepository | ||
) | ||
} | ||
|
||
@Test | ||
fun givenCartNotEmpty_whenExecute_thenReturnOrdersInCart() { | ||
val mockOrder = OrderModel( | ||
id = "", | ||
status = OrderStatus.IN_CART.value, | ||
address = null, | ||
lineItemList = mutableListOf(), | ||
createdAt = "" | ||
) | ||
whenever(mockedOrderRepository.getOneOrderByStatus(OrderStatus.IN_CART)).thenReturn(flow { | ||
emit(mockOrder) | ||
}) | ||
runBlocking { | ||
val result = testee.execute(GetCurrentCartUseCase.Input()) | ||
|
||
result.result.collect { order -> | ||
assertEquals(order?.id, "") | ||
assertEquals(order?.status, "cart") | ||
assertEquals(order?.address, null) | ||
assertEquals(order?.lineItemList!!.isEmpty(), true) | ||
assertEquals(order.createdAt, "") | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun givenCartEmpty_whenExecute_thenReturnNull() { | ||
whenever(mockedOrderRepository.getOneOrderByStatus(OrderStatus.IN_CART)).thenReturn(flow { | ||
null | ||
}) | ||
runBlocking { | ||
val result = testee.execute(GetCurrentCartUseCase.Input()) | ||
result.result.collect { | ||
assertNull(it) | ||
} | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...est/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsListUseCaseImplTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.hieuwu.groceriesstore.domain.usecases.impl | ||
|
||
import com.hieuwu.groceriesstore.data.repository.ProductRepository | ||
import com.hieuwu.groceriesstore.domain.models.ProductModel | ||
import com.hieuwu.groceriesstore.domain.usecases.GetProductsListUseCase | ||
import junit.framework.TestCase.assertEquals | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.MockitoJUnitRunner | ||
import org.mockito.kotlin.whenever | ||
|
||
@RunWith(MockitoJUnitRunner::class) | ||
|
||
class GetProductsListUseCaseImplTest { | ||
|
||
@Mock | ||
lateinit var mockedProductsRepository: ProductRepository | ||
|
||
private lateinit var testee: GetProductsListUseCase | ||
|
||
@Before | ||
fun setUp() { | ||
testee = GetProductsListUseCaseImpl( | ||
productRepository = mockedProductsRepository | ||
) | ||
} | ||
|
||
@Test | ||
fun givenProductsAvailable_whenExecute_thenReturnCorrectValue() { | ||
val mockedProducts = listOf( | ||
ProductModel(id = "1", name = "Apple", price = 1.0, image = "image1.jpg", description = "Fruit", nutrition = "Healthy"), | ||
ProductModel(id = "2", name = "Fries", price = 5.0, image = "image2.jpg", description = "Junk food", nutrition = "Unhealthy"), | ||
ProductModel(id = "3", name = "Potato", price = 10.0, image = "image3.jpg", description = "Vegetable", nutrition = "Healthy"), | ||
) | ||
whenever(mockedProductsRepository.products).thenReturn(flow { | ||
emit(mockedProducts) | ||
}) | ||
runBlocking { | ||
val result = testee.execute(GetProductsListUseCase.Input()) | ||
|
||
result.result.collect { products -> | ||
assertEquals(mockedProducts[0], products[0]) | ||
assertEquals(mockedProducts[1], products[1]) | ||
assertEquals(mockedProducts[2], products[2]) | ||
assertEquals(mockedProducts[1].name, "Fries") | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun givenProductsUnavailable_whenExecute_thenReturnCorrectValue() { | ||
whenever(mockedProductsRepository.products).thenReturn(flow { | ||
emit(listOf()) | ||
}) | ||
|
||
runBlocking { | ||
val result = testee.execute(GetProductsListUseCase.Input()) | ||
result.result.collect { | ||
assertEquals(it.isEmpty(), true) | ||
} | ||
} | ||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
...src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProfileUseCaseImplTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.hieuwu.groceriesstore.domain.usecases.impl | ||
|
||
import com.hieuwu.groceriesstore.data.repository.UserRepository | ||
import com.hieuwu.groceriesstore.domain.models.UserModel | ||
import com.hieuwu.groceriesstore.domain.usecases.GetProfileUseCase | ||
import junit.framework.TestCase.assertEquals | ||
import junit.framework.TestCase.assertNotNull | ||
import junit.framework.TestCase.assertNull | ||
import junit.framework.TestCase.assertTrue | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.MockitoJUnitRunner | ||
import org.mockito.kotlin.whenever | ||
|
||
@RunWith(MockitoJUnitRunner::class) | ||
|
||
class GetProfileUseCaseImplTest { | ||
|
||
@Mock | ||
lateinit var mockedUserRepository: UserRepository | ||
|
||
private lateinit var testee: GetProfileUseCase | ||
|
||
@Before | ||
fun setUp() { | ||
testee = GetProfileUseCaseImpl( | ||
userRepository = mockedUserRepository | ||
) | ||
} | ||
|
||
@Test | ||
fun givenUserAvailable_whenExecute_thenReturnCorrectValue() { | ||
whenever(mockedUserRepository.getCurrentUser()).thenReturn(flow { | ||
UserModel( | ||
id = "", | ||
name = "", | ||
email = "", | ||
phone = "", | ||
address = "", | ||
isOrderCreatedNotiEnabled = true, | ||
isPromotionNotiEnabled = true, | ||
isDataRefreshedNotiEnabled = true | ||
) | ||
}) | ||
runBlocking { | ||
val result = testee.execute(GetProfileUseCase.Input()) | ||
|
||
result.result.collect { | ||
assertEquals("", it?.id) | ||
assertTrue(it!!.isDataRefreshedNotiEnabled) | ||
assertTrue(it.isOrderCreatedNotiEnabled) | ||
assertTrue(it.isPromotionNotiEnabled) | ||
} | ||
} | ||
} | ||
|
||
|
||
@Test | ||
fun givenUserUnavailable_whenExecute_thenReturnCorrectValue() { | ||
whenever(mockedUserRepository.getCurrentUser()).thenReturn(flow { | ||
null | ||
}) | ||
|
||
runBlocking { | ||
val result = testee.execute(GetProfileUseCase.Input()) | ||
result.result.collect { | ||
assertNull(it) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#Tue Oct 10 05:12:00 IST 2023 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters