1 /*
2  * Copyright (C) 2020 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.datausage;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import androidx.test.ext.junit.runners.AndroidJUnit4;
22 
23 import com.android.settingslib.net.DataUsageController.DataUsageInfo;
24 
25 import org.junit.Before;
26 import org.junit.Ignore;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 
30 @RunWith(AndroidJUnit4.class)
31 @Ignore("b/340657656")
32 public class DataUsageInfoControllerTest {
33 
34     private static final int ZERO = 0;
35     private static final int POSITIVE_SMALL = 1;
36     private static final int POSITIVE_LARGE = 5;
37 
38     private DataUsageInfoController mInfoController;
39     private DataUsageInfo info;
40 
41     @Before
setUp()42     public void setUp()  {
43         mInfoController = new DataUsageInfoController();
44         info = new DataUsageInfo();
45     }
46 
47     @Test
getSummaryLimit_LowUsageLowWarning_LimitUsed()48     public void getSummaryLimit_LowUsageLowWarning_LimitUsed() {
49         info.warningLevel = POSITIVE_SMALL;
50         info.limitLevel = POSITIVE_LARGE;
51         info.usageLevel = POSITIVE_SMALL;
52 
53         assertThat(mInfoController.getSummaryLimit(info)).isEqualTo(info.limitLevel);
54     }
55 
56     @Test
getSummaryLimit_LowUsageEqualWarning_LimitUsed()57     public void getSummaryLimit_LowUsageEqualWarning_LimitUsed() {
58         info.warningLevel = POSITIVE_LARGE;
59         info.limitLevel = POSITIVE_LARGE;
60         info.usageLevel = POSITIVE_SMALL;
61 
62         assertThat(mInfoController.getSummaryLimit(info)).isEqualTo(info.limitLevel);
63     }
64 
65     @Test
getSummaryLimit_NoLimitNoUsage_WarningUsed()66     public void getSummaryLimit_NoLimitNoUsage_WarningUsed() {
67         info.warningLevel = POSITIVE_LARGE;
68         info.limitLevel = ZERO;
69         info.usageLevel = ZERO;
70 
71         assertThat(mInfoController.getSummaryLimit(info)).isEqualTo(info.warningLevel);
72     }
73 
74     @Test
getSummaryLimit_NoLimitLowUsage_WarningUsed()75     public void getSummaryLimit_NoLimitLowUsage_WarningUsed() {
76         info.warningLevel = POSITIVE_LARGE;
77         info.limitLevel = ZERO;
78         info.usageLevel = POSITIVE_SMALL;
79 
80         assertThat(mInfoController.getSummaryLimit(info)).isEqualTo(info.warningLevel);
81     }
82 
83     @Test
getSummaryLimit_LowWarningNoLimit_UsageUsed()84     public void getSummaryLimit_LowWarningNoLimit_UsageUsed() {
85         info.warningLevel = POSITIVE_SMALL;
86         info.limitLevel = ZERO;
87         info.usageLevel = POSITIVE_LARGE;
88 
89         assertThat(mInfoController.getSummaryLimit(info)).isEqualTo(info.usageLevel);
90     }
91 
92     @Test
getSummaryLimit_LowWarningLowLimit_UsageUsed()93     public void getSummaryLimit_LowWarningLowLimit_UsageUsed() {
94         info.warningLevel = POSITIVE_SMALL;
95         info.limitLevel = POSITIVE_SMALL;
96         info.usageLevel = POSITIVE_LARGE;
97 
98         assertThat(mInfoController.getSummaryLimit(info)).isEqualTo(info.usageLevel);
99     }
100 }
101