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
17package com.android.settings.fuelgauge.anomaly;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import android.content.Context;
22
23import com.android.settings.testutils.SettingsRobolectricTestRunner;
24
25import org.junit.Before;
26import org.junit.Test;
27import org.junit.runner.RunWith;
28import org.mockito.MockitoAnnotations;
29import org.robolectric.RuntimeEnvironment;
30
31@RunWith(SettingsRobolectricTestRunner.class)
32public class AnomalyPreferenceTest {
33
34    @Anomaly.AnomalyType
35    private static final int ANOMALY_TYPE = Anomaly.AnomalyType.WAKE_LOCK;
36    private static final String PACKAGE_NAME = "com.android.app";
37    private static final String DISPLAY_NAME = "app";
38    private static final int UID = 111;
39
40    private Context mContext;
41    private Anomaly mAnomaly;
42    private AnomalyPreference mAnomalyPreference;
43
44    @Before
45    public void setUp() {
46        MockitoAnnotations.initMocks(this);
47
48        mContext = RuntimeEnvironment.application;
49
50        mAnomaly = new Anomaly.Builder()
51                .setType(ANOMALY_TYPE)
52                .setPackageName(PACKAGE_NAME)
53                .setDisplayName(DISPLAY_NAME)
54                .setUid(UID)
55                .build();
56    }
57
58    @Test
59    public void testAnomalyPreference_containsCorrectData() {
60        mAnomalyPreference = new AnomalyPreference(mContext, mAnomaly);
61
62        assertThat(mAnomalyPreference.getTitle()).isEqualTo(DISPLAY_NAME);
63    }
64}
65