Home | History | Annotate | Download | only in datetime
      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.TestConfig;
     31 import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
     32 import com.android.settings.testutils.shadow.ShadowZoneGetter;
     33 
     34 import org.junit.Before;
     35 import org.junit.Test;
     36 import org.junit.runner.RunWith;
     37 import org.robolectric.Robolectric;
     38 import org.robolectric.annotation.Config;
     39 import org.robolectric.util.ReflectionHelpers;
     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
     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)
     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                 nullable(LayoutInflater.class),
     68                 nullable(ViewGroup.class),
     69                 nullable(Bundle.class));
     70     }
     71 }
     72