Skip to content

Commit e9a0d75

Browse files
committed
Fix compilation issues in unit tests
1 parent d246f22 commit e9a0d75

File tree

7 files changed

+131
-190
lines changed

7 files changed

+131
-190
lines changed

WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/common/data/searchbyidentifier/WooPosSearchByIdentifierGlobalUniqueSearchTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.woocommerce.android.ui.woopos.common.data.searchbyidentifier
33
import com.woocommerce.android.model.toAppModel
44
import com.woocommerce.android.tools.SelectedSite
55
import com.woocommerce.android.ui.products.ProductTestUtils
6+
import com.woocommerce.android.ui.woopos.common.data.models.WCProductToWooPosProductModelMapper
67
import com.woocommerce.android.ui.woopos.common.util.WooPosLogWrapper
78
import kotlinx.coroutines.test.runTest
89
import org.junit.Assert.assertEquals
@@ -25,10 +26,12 @@ class WooPosSearchByIdentifierGlobalUniqueSearchTest {
2526
private val productStore: WCProductStore = mock()
2627
private val site: SiteModel = mock()
2728
private val wooPosLogWrapper: WooPosLogWrapper = mock()
29+
private val posProductMapper: WCProductToWooPosProductModelMapper = mock()
2830

2931
@Before
3032
fun setup() {
31-
sut = WooPosSearchByIdentifierGlobalUniqueSearch(selectedSite, productStore, wooPosLogWrapper)
33+
sut = WooPosSearchByIdentifierGlobalUniqueSearch(selectedSite, productStore,
34+
wooPosLogWrapper, posProductMapper)
3235
whenever(selectedSite.get()).thenReturn(site)
3336
}
3437

WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/common/data/searchbyidentifier/WooPosSearchByIdentifierLocalTest.kt

Lines changed: 11 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
package com.woocommerce.android.ui.woopos.common.data.searchbyidentifier
22

3-
import com.woocommerce.android.model.Product
4-
import com.woocommerce.android.model.toAppModel
5-
import com.woocommerce.android.ui.products.ProductBackorderStatus
6-
import com.woocommerce.android.ui.products.ProductStatus
7-
import com.woocommerce.android.ui.products.ProductStockStatus
8-
import com.woocommerce.android.ui.products.ProductTaxStatus
9-
import com.woocommerce.android.ui.products.ProductTestUtils
10-
import com.woocommerce.android.ui.products.ProductType
11-
import com.woocommerce.android.ui.products.settings.ProductCatalogVisibility
123
import com.woocommerce.android.ui.woopos.common.data.WooPosProductsCache
134
import com.woocommerce.android.ui.woopos.common.data.WooPosVariation
5+
import com.woocommerce.android.ui.woopos.common.data.models.WooPosProductModel
146
import com.woocommerce.android.ui.woopos.home.items.variations.WooPosVariationsLRUCache
7+
import com.woocommerce.android.ui.woopos.util.generateWooPosProduct
158
import kotlinx.coroutines.test.runTest
169
import org.junit.Assert.assertEquals
1710
import org.junit.Before
@@ -20,14 +13,13 @@ import org.mockito.kotlin.any
2013
import org.mockito.kotlin.mock
2114
import org.mockito.kotlin.whenever
2215
import java.math.BigDecimal
23-
import java.util.Date
2416
import kotlin.test.assertTrue
2517

2618
class WooPosSearchByIdentifierLocalTest {
2719

2820
private lateinit var sut: WooPosSearchByIdentifierLocal
2921
private val productsCache: WooPosProductsCache = mock {
30-
onBlocking { getProductById(any()) }.thenReturn(ProductTestUtils.generateWCProductModel().toAppModel())
22+
onBlocking { getProductById(any()) }.thenReturn(generateWooPosProduct())
3123
}
3224
private val variationsCache: WooPosVariationsLRUCache = mock()
3325

@@ -40,7 +32,7 @@ class WooPosSearchByIdentifierLocalTest {
4032
fun `given product with matching global unique id, when search called, then return product`() = runTest {
4133
// GIVEN
4234
val identifier = "1234567890123"
43-
val product = createProduct(globalUniqueId = identifier)
35+
val product = generateWooPosProduct(globalUniqueId = identifier)
4436
whenever(productsCache.getAll()).thenReturn(listOf(product))
4537
whenever(variationsCache.getAll()).thenReturn(emptyList())
4638

@@ -69,7 +61,7 @@ class WooPosSearchByIdentifierLocalTest {
6961
fun `given product with lowercase global unique id, when search with uppercase, then return product`() = runTest {
7062
// GIVEN
7163
val identifier = "ABC123"
72-
val product = createProduct(globalUniqueId = "abc123")
64+
val product = generateWooPosProduct(globalUniqueId = "abc123")
7365
whenever(productsCache.getAll()).thenReturn(listOf(product))
7466
whenever(variationsCache.getAll()).thenReturn(emptyList())
7567

@@ -86,7 +78,8 @@ class WooPosSearchByIdentifierLocalTest {
8678
val identifier = "VAR123456"
8779
val productId = 1L
8880
val variationId = 10L
89-
val product = createProduct(remoteId = productId).copy(type = ProductType.VARIABLE.value)
81+
val product =
82+
generateWooPosProduct(productId = productId, productType = WooPosProductModel.WooPosProductType.VARIABLE)
9083
val variation = WooPosVariation(
9184
remoteVariationId = variationId,
9285
remoteProductId = productId,
@@ -115,7 +108,8 @@ class WooPosSearchByIdentifierLocalTest {
115108
// GIVEN
116109
val identifier = "MATCH-VAR"
117110
val productId = 1L
118-
val product = createProduct(remoteId = productId).copy(type = ProductType.VARIABLE.value)
111+
val product =
112+
generateWooPosProduct(productId = productId, productType = WooPosProductModel.WooPosProductType.VARIABLE)
119113
val variation1 = WooPosVariation(
120114
remoteVariationId = 10L,
121115
remoteProductId = productId,
@@ -154,7 +148,8 @@ class WooPosSearchByIdentifierLocalTest {
154148
// GIVEN
155149
val identifier = "VAR-UPPER"
156150
val productId = 1L
157-
val product = createProduct(remoteId = productId).copy(type = ProductType.VARIABLE.value)
151+
val product =
152+
generateWooPosProduct(productId = productId, productType = WooPosProductModel.WooPosProductType.VARIABLE)
158153
val variation = WooPosVariation(
159154
remoteVariationId = 10L,
160155
remoteProductId = productId,
@@ -205,80 +200,4 @@ class WooPosSearchByIdentifierLocalTest {
205200
assertTrue(result is WooPosSearchByIdentifierResult.Failure)
206201
assertEquals(WooPosSearchByIdentifierResult.Error.NotFound, result.error)
207202
}
208-
209-
@Suppress("LongMethod")
210-
private fun createProduct(
211-
remoteId: Long = 1,
212-
name: String = "Test Product",
213-
sku: String = "",
214-
globalUniqueId: String = ""
215-
) = Product(
216-
remoteId = remoteId,
217-
parentId = 0,
218-
name = name,
219-
description = "",
220-
shortDescription = "",
221-
slug = "",
222-
type = ProductType.SIMPLE.value,
223-
status = ProductStatus.PUBLISH,
224-
catalogVisibility = ProductCatalogVisibility.VISIBLE,
225-
isFeatured = false,
226-
stockStatus = ProductStockStatus.InStock,
227-
backorderStatus = ProductBackorderStatus.No,
228-
dateCreated = Date(),
229-
firstImageUrl = null,
230-
totalSales = 0,
231-
reviewsAllowed = true,
232-
isVirtual = false,
233-
ratingCount = 0,
234-
averageRating = 0f,
235-
permalink = "",
236-
externalUrl = "",
237-
buttonText = "",
238-
price = BigDecimal.TEN,
239-
salePrice = null,
240-
regularPrice = BigDecimal.TEN,
241-
taxClass = Product.TAX_CLASS_DEFAULT,
242-
isStockManaged = false,
243-
stockQuantity = 0.0,
244-
sku = sku,
245-
globalUniqueId = globalUniqueId,
246-
shippingClass = "",
247-
shippingClassId = 0,
248-
isDownloadable = false,
249-
downloads = emptyList(),
250-
downloadLimit = 0,
251-
downloadExpiry = 0,
252-
purchaseNote = "",
253-
numVariations = 0,
254-
images = emptyList(),
255-
attributes = emptyList(),
256-
saleEndDateGmt = null,
257-
saleStartDateGmt = null,
258-
isSoldIndividually = false,
259-
taxStatus = ProductTaxStatus.Taxable,
260-
isSaleScheduled = false,
261-
isPurchasable = true,
262-
menuOrder = 0,
263-
categories = emptyList(),
264-
tags = emptyList(),
265-
groupedProductIds = emptyList(),
266-
crossSellProductIds = emptyList(),
267-
upsellProductIds = emptyList(),
268-
variationIds = emptyList(),
269-
length = 0f,
270-
width = 0f,
271-
height = 0f,
272-
weight = 0f,
273-
isSampleProduct = false,
274-
specialStockStatus = null,
275-
isConfigurable = false,
276-
minAllowedQuantity = null,
277-
maxAllowedQuantity = null,
278-
bundleMinSize = null,
279-
bundleMaxSize = null,
280-
groupOfQuantity = null,
281-
combineVariationQuantities = null,
282-
password = null
283-
)
284203
}

WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/common/data/searchbyidentifier/WooPosSearchByIdentifierRemoteTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.woocommerce.android.ui.woopos.common.data.searchbyidentifier
22

3-
import com.woocommerce.android.ui.products.ProductTestUtils
43
import com.woocommerce.android.ui.woopos.util.WooPosCoroutineTestRule
4+
import com.woocommerce.android.ui.woopos.util.generateWooPosProduct
55
import kotlinx.coroutines.ExperimentalCoroutinesApi
66
import kotlinx.coroutines.test.UnconfinedTestDispatcher
77
import kotlinx.coroutines.test.runTest
@@ -25,7 +25,7 @@ class WooPosSearchByIdentifierRemoteTest {
2525
private val globalUniqueIdSearch: WooPosSearchByIdentifierGlobalUniqueSearch = mock()
2626
private val resultConverter: WooPosSearchByIdentifierResultConverter = mock()
2727

28-
private val testProduct = ProductTestUtils.generateProduct()
28+
private val testProduct = generateWooPosProduct()
2929

3030
@Before
3131
fun setup() {

WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsListCacheTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.woocommerce.android.ui.woopos.home.items.products
22

3-
import com.woocommerce.android.model.Product
43
import com.woocommerce.android.ui.woopos.common.data.WooPosProductsCache
4+
import com.woocommerce.android.ui.woopos.util.generateWooPosProduct
55
import kotlinx.coroutines.ExperimentalCoroutinesApi
66
import kotlinx.coroutines.test.runTest
77
import org.junit.Assert.assertEquals
@@ -36,8 +36,8 @@ class WooPosProductsListCacheTest {
3636

3737
@Test
3838
fun `when products are stored, getProductList returns products from cache`() = runTest {
39-
val product1 = mock<Product>()
40-
val product2 = mock<Product>()
39+
val product1 = generateWooPosProduct()
40+
val product2 = generateWooPosProduct()
4141

4242
whenever(productsCache.getProductById(1L)).thenReturn(product1)
4343
whenever(productsCache.getProductById(2L)).thenReturn(product2)
@@ -50,9 +50,9 @@ class WooPosProductsListCacheTest {
5050

5151
@Test
5252
fun `when adding more products, duplicates are removed`() = runTest {
53-
val product1 = mock<Product>()
54-
val product2 = mock<Product>()
55-
val product3 = mock<Product>()
53+
val product1 = generateWooPosProduct()
54+
val product2 = generateWooPosProduct()
55+
val product3 = generateWooPosProduct()
5656

5757
whenever(productsCache.getProductById(1L)).thenReturn(product1)
5858
whenever(productsCache.getProductById(2L)).thenReturn(product2)
@@ -74,7 +74,7 @@ class WooPosProductsListCacheTest {
7474

7575
@Test
7676
fun `when cache is cleared, getProductList returns empty list`() = runTest {
77-
val product1 = mock<Product>()
77+
val product1 = generateWooPosProduct()
7878
whenever(productsCache.getProductById(1L)).thenReturn(product1)
7979

8080
productListIndex.storeProductList(listOf(1L))

WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsRepositoryTest.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import com.woocommerce.android.model.OrderMapper
55
import com.woocommerce.android.tools.SelectedSite
66
import com.woocommerce.android.ui.orders.creation.OrderCreateEditRepository
77
import com.woocommerce.android.ui.orders.creation.OrderCreationSource
8-
import com.woocommerce.android.ui.products.ProductHelper
9-
import com.woocommerce.android.ui.products.ProductType
108
import com.woocommerce.android.ui.woopos.common.data.WooPosGetProductById
119
import com.woocommerce.android.ui.woopos.common.data.WooPosGetVariationById
1210
import com.woocommerce.android.ui.woopos.common.data.WooPosVariationMapper
1311
import com.woocommerce.android.ui.woopos.home.items.WooPosItemsViewModel
12+
import com.woocommerce.android.ui.woopos.util.generateWooPosProduct
1413
import com.woocommerce.android.util.DateUtils
1514
import com.woocommerce.android.viewmodel.ResourceProvider
1615
import kotlinx.coroutines.test.runTest
@@ -38,10 +37,7 @@ class WooPosTotalsRepositoryTest {
3837

3938
private lateinit var repository: WooPosTotalsRepository
4039

41-
private val product1 = ProductHelper.getDefaultNewProduct(
42-
productType = ProductType.SIMPLE,
43-
isVirtual = false
44-
).copy(remoteId = 1L)
40+
private val product1 = generateWooPosProduct(productId = 1L)
4541

4642
@Test
4743
fun `given empty product list, when createOrderFromCartItems called, then return error`() = runTest {

0 commit comments

Comments
 (0)