1 /*
<lambda>null2  * 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.settings.system.reset
18 
19 import android.content.Context
20 import android.view.LayoutInflater
21 import android.widget.TextView
22 import androidx.fragment.app.testing.launchFragment
23 import androidx.test.core.app.ApplicationProvider
24 import androidx.test.ext.junit.runners.AndroidJUnit4
25 import com.android.settings.R
26 import com.android.settings.ResetNetworkRequest
27 import com.google.common.truth.Truth.assertThat
28 import kotlinx.coroutines.runBlocking
29 import org.junit.Test
30 import org.junit.runner.RunWith
31 import org.mockito.kotlin.any
32 import org.mockito.kotlin.never
33 import org.mockito.kotlin.spy
34 import org.mockito.kotlin.verify
35 
36 @RunWith(AndroidJUnit4::class)
37 class ResetNetworkConfirmTest {
38     private val context: Context = spy(ApplicationProvider.getApplicationContext()) {}
39 
40     private val scenario = launchFragment<ResetNetworkConfirm>()
41 
42     @Test
43     fun resetNetworkData_notResetEsim() {
44         scenario.recreate().onFragment { fragment ->
45             fragment.resetNetworkRequest = ResetNetworkRequest(ResetNetworkRequest.RESET_NONE)
46 
47             runBlocking { fragment.onResetClicked() }
48 
49             verify(context, never()).getSystemService(any())
50         }
51     }
52 
53     @Test
54     fun setSubtitle_eraseEsim() {
55         scenario.onFragment { fragment ->
56             fragment.resetNetworkRequest =
57                 ResetNetworkRequest(ResetNetworkRequest.RESET_NONE).apply {
58                     setResetEsim(context.packageName)
59                 }
60 
61             val view = fragment.onCreateView(LayoutInflater.from(context), null, null)
62 
63             assertThat(view.requireViewById<TextView>(R.id.reset_network_confirm).text)
64                 .isEqualTo(context.getString(R.string.reset_network_final_desc_esim))
65         }
66     }
67 
68     @Test
69     fun setSubtitle_notEraseEsim() {
70         scenario.onFragment { fragment ->
71             fragment.resetNetworkRequest = ResetNetworkRequest(ResetNetworkRequest.RESET_NONE)
72 
73             val view = fragment.onCreateView(LayoutInflater.from(context), null, null)
74 
75             assertThat(view.requireViewById<TextView>(R.id.reset_network_confirm).text)
76                 .isEqualTo(context.getString(R.string.reset_network_final_desc))
77         }
78     }
79 }
80