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.datetime;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.view.LayoutInflater;
22 import android.view.ViewGroup;
23 
24 import com.android.settings.SettingsRobolectricTestRunner;
25 import com.android.settings.TestConfig;
26 import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
27 import com.android.settings.testutils.shadow.ShadowZoneGetter;
28 
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.robolectric.Robolectric;
33 import org.robolectric.annotation.Config;
34 import org.robolectric.util.ReflectionHelpers;
35 
36 import static org.mockito.Matchers.any;
37 import static org.mockito.Mockito.mock;
38 import static org.mockito.Mockito.spy;
39 import static org.mockito.Mockito.verify;
40 
41 @RunWith(SettingsRobolectricTestRunner.class)
42 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
43 public class ZonePickerTest {
44 
45     private Activity mActivity;
46     private ZonePicker mZonePicker;
47 
48     @Before
setUp()49     public void setUp() {
50         mActivity = Robolectric.setupActivity(Activity.class);
51         mZonePicker = spy(ZonePicker.class);
52         ReflectionHelpers.setField(mZonePicker, "mVisibilityLoggerMixin",
53                 mock(VisibilityLoggerMixin.class));
54     }
55 
56     @Test
57     @Config(shadows = ShadowZoneGetter.class)
testLaunch()58     public void testLaunch() {
59         // Shouldn't crash
60         mActivity.getFragmentManager()
61                 .beginTransaction()
62                 .add(mZonePicker, "test_tag")
63                 .commit();
64 
65         // Should render
66         verify(mZonePicker).onCreateView(
67                 any(LayoutInflater.class),
68                 any(ViewGroup.class),
69                 any(Bundle.class));
70     }
71 }
72