1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.wallpaper.util.converter.category
18 
19 import android.content.Context
20 import androidx.test.core.app.ApplicationProvider
21 import com.android.wallpaper.model.ImageCategory
22 import com.android.wallpaper.model.PlaceholderCategory
23 import com.android.wallpaper.picker.data.category.CategoryModel
24 import com.android.wallpaper.util.converter.WallpaperModelFactory
25 import dagger.hilt.android.testing.HiltAndroidRule
26 import dagger.hilt.android.testing.HiltAndroidTest
27 import dagger.hilt.android.testing.HiltTestApplication
28 import javax.inject.Inject
29 import junit.framework.Assert.assertEquals
30 import org.junit.Before
31 import org.junit.Rule
32 import org.junit.Test
33 import org.junit.runner.RunWith
34 import org.robolectric.RobolectricTestRunner
35 
36 @HiltAndroidTest
37 @RunWith(RobolectricTestRunner::class)
38 class DefaultCategoryFactoryTest {
39 
40     @get:Rule var hiltRule = HiltAndroidRule(this)
41 
42     private lateinit var context: Context
43 
44     @Inject lateinit var wallpaperModelFactory: WallpaperModelFactory
45 
46     private lateinit var mCategoryFactory: CategoryFactory
47 
48     @Before
setUpnull49     fun setUp() {
50         hiltRule.inject()
51         context = ApplicationProvider.getApplicationContext<HiltTestApplication>()
52         mCategoryFactory = DefaultCategoryFactory(context, wallpaperModelFactory)
53     }
54 
55     @Test
testGetCategoryModelnull56     fun testGetCategoryModel() {
57         val placeholderCategory = PlaceholderCategory(TEST_TITLE, TEST_COLLECTIONID, TEST_PRIORITY)
58 
59         val result = mCategoryFactory.getCategoryModel(placeholderCategory)
60 
61         validateCommonCategoryData(result)
62         assertEquals(result.collectionCategoryData, null)
63         assertEquals(result.imageCategoryData, null)
64         assertEquals(result.thirdPartyCategoryData, null)
65     }
66 
67     @Test
testGetImageCategoryModelnull68     fun testGetImageCategoryModel() {
69         val imageCategory = ImageCategory(TEST_TITLE, TEST_COLLECTIONID, TEST_PRIORITY)
70         val result = mCategoryFactory.getCategoryModel(imageCategory)
71         validateCommonCategoryData(result)
72     }
73 
validateCommonCategoryDatanull74     private fun validateCommonCategoryData(result: CategoryModel) {
75         assertEquals(TEST_TITLE, result.commonCategoryData.title)
76         assertEquals(TEST_COLLECTIONID, result.commonCategoryData.collectionId)
77         assertEquals(TEST_PRIORITY, result.commonCategoryData.priority)
78     }
79 
80     companion object {
81         const val TEST_TITLE = "Test-Title"
82         const val TEST_COLLECTIONID = "Test-Collection-Id"
83         const val TEST_PRIORITY = 1
84     }
85 }
86