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