1 /*
2  * Copyright (C) 2022 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.ons;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.assertTrue;
23 
24 import com.android.ons.ONSProfileActivator.Result;
25 import com.android.ons.ONSProfileDownloader.DownloadRetryResultCode;
26 
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.junit.runners.JUnit4;
30 
31 @RunWith(JUnit4.class)
32 public class ONSStatsInfoTest {
33 
34     @Test
testProvisioningResult()35     public void testProvisioningResult() {
36         ONSStatsInfo info;
37         info = new ONSStatsInfo().setProvisioningResult(Result.ERR_AUTO_PROVISIONING_DISABLED);
38         assertEquals(Result.ERR_AUTO_PROVISIONING_DISABLED, info.getProvisioningResult());
39         assertNull(info.getDownloadResult());
40         assertTrue(info.isProvisioningResultUpdated());
41     }
42 
43     @Test
testDownloadResult()44     public void testDownloadResult() {
45         ONSStatsInfo info;
46         info = new ONSStatsInfo().setDownloadResult(DownloadRetryResultCode.ERR_MEMORY_FULL);
47         assertEquals(DownloadRetryResultCode.ERR_MEMORY_FULL, info.getDownloadResult());
48         assertNull(info.getProvisioningResult());
49         assertFalse(info.isProvisioningResultUpdated());
50     }
51 
52     @Test
testPrimarySimSubId()53     public void testPrimarySimSubId() {
54         ONSStatsInfo info;
55         info = new ONSStatsInfo().setPrimarySimSubId(1);
56         assertEquals(1, info.getPrimarySimSubId());
57     }
58 
59     @Test
testOppSimCarrierId()60     public void testOppSimCarrierId() {
61         ONSStatsInfo info;
62         info = new ONSStatsInfo().setOppSimCarrierId(1221);
63         assertEquals(1221, info.getOppSimCarrierId());
64     }
65 
66     @Test
testRetryCount()67     public void testRetryCount() {
68         ONSStatsInfo info;
69         info = new ONSStatsInfo().setRetryCount(3);
70         assertEquals(3, info.getRetryCount());
71     }
72 
73     @Test
testDetailedErrCode()74     public void testDetailedErrCode() {
75         ONSStatsInfo info;
76         info = new ONSStatsInfo().setDetailedErrCode(1000);
77         assertEquals(1000, info.getDetailedErrCode());
78     }
79 
80     @Test
testIsWifiConnected()81     public void testIsWifiConnected() {
82         ONSStatsInfo info;
83         info = new ONSStatsInfo().setWifiConnected(true);
84         assertTrue(info.isWifiConnected());
85     }
86 
87     @Test
testIsProvisioningResultUpdated()88     public void testIsProvisioningResultUpdated() {
89         ONSStatsInfo info;
90         info = new ONSStatsInfo().setProvisioningResult(Result.ERR_ESIM_NOT_SUPPORTED);
91         assertTrue(info.isProvisioningResultUpdated());
92 
93         info.setDownloadResult(DownloadRetryResultCode.ERR_MEMORY_FULL);
94         assertFalse(info.isProvisioningResultUpdated());
95     }
96 }
97