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 */
16package com.android.settings.wifi.details;
17
18import static org.mockito.Mockito.verify;
19import static org.mockito.Mockito.when;
20
21import android.app.ActionBar;
22import android.app.Activity;
23import android.content.Context;
24import android.os.Bundle;
25import com.android.settings.R;
26import com.android.settings.TestConfig;
27import com.android.settings.testutils.SettingsRobolectricTestRunner;
28import com.android.settingslib.core.lifecycle.Lifecycle;
29import org.junit.Before;
30import org.junit.Test;
31import org.junit.runner.RunWith;
32import org.mockito.Mock;
33import org.mockito.MockitoAnnotations;
34import org.robolectric.RuntimeEnvironment;
35import org.robolectric.annotation.Config;
36
37@RunWith(SettingsRobolectricTestRunner.class)
38@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
39public class WifiDetailActionBarObserverTest {
40
41    @Mock private Bundle mockBundle;
42    @Mock private Activity mockActivity;
43    @Mock private ActionBar mockActionBar;
44    @Mock private WifiNetworkDetailsFragment mockFragment;
45
46    private Context mContext = RuntimeEnvironment.application;
47    private Lifecycle mLifecycle;
48    private WifiDetailActionBarObserver mObserver;
49
50    @Before
51    public void setUp() {
52        MockitoAnnotations.initMocks(this);
53
54        mLifecycle = new Lifecycle();
55
56        when(mockFragment.getActivity()).thenReturn(mockActivity);
57        when(mockActivity.getActionBar()).thenReturn(mockActionBar);
58
59        mObserver = new WifiDetailActionBarObserver(mContext, mockFragment);
60        mLifecycle.addObserver(mObserver);
61    }
62
63    @Test
64    public void actionBarIsSetToNetworkInfo() {
65        mLifecycle.onCreate(mockBundle);
66
67        verify(mockActionBar).setTitle(mContext.getString(R.string.wifi_details_title));
68    }
69}
70