Home | History | Annotate | Download | only in robolectric
      1 /*
      2  * Copyright (C) 2018 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 package com.android.car.setupwizardlib.robolectric;
     17 
     18 import static com.google.common.truth.Truth.assertThat;
     19 
     20 import android.view.View;
     21 import android.widget.TextView;
     22 
     23 import org.mockito.Mockito;
     24 
     25 /**
     26  * Helper for commonly used assertions and mocks/spies.
     27  */
     28 public final class TestHelper {
     29     // View testing helpers.
     30     public static void assertViewVisible(View view) {
     31         assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
     32     }
     33 
     34     public static void assertViewNotVisible(View view) {
     35         assertThat(view.getVisibility()).isEqualTo(View.GONE);
     36     }
     37 
     38     public static void assertViewEnabled(View view) {
     39         assertThat(view.isEnabled()).isTrue();
     40     }
     41 
     42     public static void assertViewNotEnabled(View view) {
     43         assertThat(view.isEnabled()).isFalse();
     44     }
     45 
     46     public static void assertTextEqual(TextView view, String text) {
     47         assertThat(view.getText()).isEqualTo(text);
     48     }
     49 
     50     public static View.OnClickListener createSpyListener() {
     51         return Mockito.spy(new View.OnClickListener() {
     52             @Override
     53             public void onClick(View v) {
     54             }
     55         });
     56     }
     57 }
     58