Home | History | Annotate | Download | only in anomaly
      1 /*
      2  * Copyright (C) 2017 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.fuelgauge.anomaly;
     18 
     19 import static com.google.common.truth.Truth.assertThat;
     20 
     21 import android.os.Build;
     22 
     23 import com.android.settings.testutils.SettingsRobolectricTestRunner;
     24 import com.android.settings.TestConfig;
     25 
     26 import org.junit.Before;
     27 import org.junit.Test;
     28 import org.junit.runner.RunWith;
     29 import org.robolectric.annotation.Config;
     30 
     31 @RunWith(SettingsRobolectricTestRunner.class)
     32 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
     33 public class AnomalyTest {
     34     private static int TYPE = Anomaly.AnomalyType.WAKE_LOCK;
     35     private static int UID = 111;
     36     private static int SDK_VERSION = Build.VERSION_CODES.L;
     37     private static long WAKE_LOCK_TIME_MS = 1500;
     38     private static String PACKAGE_NAME = "com.android.settings";
     39     private static String DISPLAY_NAME = "settings";
     40     private static long BLUETOOTH_TIME_MS = 2555555;
     41     private static int WAKEUP_ALARM_COUNT = 100;
     42 
     43     private Anomaly mAnomaly;
     44 
     45     @Before
     46     public void setUp() {
     47         mAnomaly = new Anomaly.Builder()
     48                 .setType(TYPE)
     49                 .setUid(UID)
     50                 .setWakeLockTimeMs(WAKE_LOCK_TIME_MS)
     51                 .setPackageName(PACKAGE_NAME)
     52                 .setDisplayName(DISPLAY_NAME)
     53                 .setTargetSdkVersion(SDK_VERSION)
     54                 .setBackgroundRestrictionEnabled(true)
     55                 .setBluetoothScanningTimeMs(BLUETOOTH_TIME_MS)
     56                 .setWakeupAlarmCount(WAKEUP_ALARM_COUNT)
     57                 .build();
     58     }
     59 
     60     @Test
     61     public void testBuilder_buildCorrectly() {
     62         assertThat(mAnomaly.type).isEqualTo(TYPE);
     63         assertThat(mAnomaly.uid).isEqualTo(UID);
     64         assertThat(mAnomaly.wakelockTimeMs).isEqualTo(WAKE_LOCK_TIME_MS);
     65         assertThat(mAnomaly.packageName).isEqualTo(PACKAGE_NAME);
     66         assertThat(mAnomaly.displayName).isEqualTo(DISPLAY_NAME);
     67         assertThat(mAnomaly.targetSdkVersion).isEqualTo(SDK_VERSION);
     68         assertThat(mAnomaly.backgroundRestrictionEnabled).isTrue();
     69         assertThat(mAnomaly.wakeupAlarmCount).isEqualTo(WAKEUP_ALARM_COUNT);
     70         assertThat(mAnomaly.bluetoothScanningTimeMs).isEqualTo(BLUETOOTH_TIME_MS);
     71     }
     72 
     73     @Test
     74     public void testToString() {
     75         assertThat(mAnomaly.toString()).isEqualTo(
     76                 "type=wakelock uid=111 package=com.android.settings displayName=settings"
     77                         + " wakelockTimeMs=1500 wakeupAlarmCount=100 bluetoothTimeMs=2555555");
     78     }
     79 }
     80