1 /*
2  * Copyright 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 android.adservices.ondevicepersonalization;
18 
19 import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
20 import static android.telephony.TelephonyManager.NETWORK_TYPE_LTE;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 
24 import static org.junit.Assert.assertEquals;
25 
26 import android.net.NetworkCapabilities;
27 
28 import androidx.test.ext.junit.runners.AndroidJUnit4;
29 import androidx.test.filters.SmallTest;
30 
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 
34 import java.time.Duration;
35 
36 /**
37  * Unit Tests of RemoteData API.
38  */
39 @SmallTest
40 @RunWith(AndroidJUnit4.class)
41 public class UserDataTest {
42     @Test
testUserData()43     public void testUserData() {
44         UserData data = new UserData.Builder()
45                 .setTimezoneUtcOffsetMins(120)
46                 .setOrientation(ORIENTATION_PORTRAIT)
47                 .setAvailableStorageBytes(1024)
48                 .setBatteryPercentage(50)
49                 .setCarrier("carrier")
50                 .setNetworkCapabilities(
51                     NetworkCapabilities.Builder.withoutDefaultCapabilities()
52                                 .setLinkDownstreamBandwidthKbps(100).build())
53                 .setDataNetworkType(NETWORK_TYPE_LTE)
54                 .build();
55 
56         assertEquals(Duration.ofMinutes(120), data.getTimezoneUtcOffset());
57         assertEquals(ORIENTATION_PORTRAIT, data.getOrientation());
58         assertEquals(1024, data.getAvailableStorageBytes());
59         assertEquals(50, data.getBatteryPercentage());
60         assertEquals("carrier", data.getCarrier());
61         assertEquals(100, data.getNetworkCapabilities().getLinkDownstreamBandwidthKbps());
62         assertEquals(NETWORK_TYPE_LTE, data.getDataNetworkType());
63         assertThat(data.getAppInfos()).isEmpty();
64     }
65 }
66