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.widget; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.ArgumentMatchers.any; 22 import static org.mockito.ArgumentMatchers.anyLong; 23 import static org.mockito.Mockito.mock; 24 import static org.mockito.Mockito.verify; 25 26 import android.content.Context; 27 import android.os.Handler; 28 import android.view.View; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.robolectric.RobolectricTestRunner; 34 import org.robolectric.RuntimeEnvironment; 35 import org.robolectric.util.ReflectionHelpers; 36 37 @RunWith(RobolectricTestRunner.class) 38 public class LoadingViewControllerTest { 39 40 private Context mContext; 41 private View mLoadingView; 42 private View mContentView; 43 44 private LoadingViewController mController; 45 46 @Before setUp()47 public void setUp() { 48 mContext = RuntimeEnvironment.application; 49 mLoadingView = new View(mContext); 50 mContentView = new View(mContext); 51 52 mController = new LoadingViewController(mLoadingView, mContentView); 53 } 54 55 @Test showContent_shouldSetContentVisible()56 public void showContent_shouldSetContentVisible() { 57 mController.showContent(false /* animate */); 58 59 assertThat(mContentView.getVisibility()).isEqualTo(View.VISIBLE); 60 } 61 62 @Test showLoadingViewDelayed_shouldPostRunnable()63 public void showLoadingViewDelayed_shouldPostRunnable() { 64 final Handler handler = mock(Handler.class); 65 ReflectionHelpers.setField(mController, "mFgHandler", handler); 66 mController.showLoadingViewDelayed(); 67 68 verify(handler).postDelayed(any(Runnable.class), anyLong()); 69 } 70 } 71