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.content.Context;
     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.mockito.MockitoAnnotations;
     30 import org.robolectric.RuntimeEnvironment;
     31 import org.robolectric.annotation.Config;
     32 
     33 @RunWith(SettingsRobolectricTestRunner.class)
     34 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
     35 public class AnomalyPreferenceTest {
     36     @Anomaly.AnomalyType
     37     private static final int ANOMALY_TYPE = Anomaly.AnomalyType.WAKE_LOCK;
     38     private static final String PACKAGE_NAME = "com.android.app";
     39     private static final String DISPLAY_NAME = "app";
     40     private static final int UID = 111;
     41 
     42     private Context mContext;
     43     private Anomaly mAnomaly;
     44     private AnomalyPreference mAnomalyPreference;
     45 
     46     @Before
     47     public void setUp() {
     48         MockitoAnnotations.initMocks(this);
     49 
     50         mContext = RuntimeEnvironment.application;
     51 
     52         mAnomaly = new Anomaly.Builder()
     53                 .setType(ANOMALY_TYPE)
     54                 .setPackageName(PACKAGE_NAME)
     55                 .setDisplayName(DISPLAY_NAME)
     56                 .setUid(UID)
     57                 .build();
     58     }
     59 
     60     @Test
     61     public void testAnomalyPreference_containsCorrectData() {
     62         mAnomalyPreference = new AnomalyPreference(mContext, mAnomaly);
     63 
     64         assertThat(mAnomalyPreference.getTitle()).isEqualTo(DISPLAY_NAME);
     65     }
     66 }
     67