Home | History | Annotate | Download | only in conditional
      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.settings.dashboard.conditional;
     17 
     18 import static com.google.common.truth.Truth.assertThat;
     19 import static org.mockito.Mockito.spy;
     20 import static org.mockito.Mockito.verify;
     21 import static org.mockito.Mockito.when;
     22 
     23 import android.content.Context;
     24 import android.content.Intent;
     25 import android.util.FeatureFlagUtils;
     26 
     27 import com.android.settings.Settings;
     28 import com.android.settings.core.FeatureFlags;
     29 import com.android.settings.testutils.SettingsRobolectricTestRunner;
     30 
     31 import org.junit.Before;
     32 import org.junit.Test;
     33 import org.junit.runner.RunWith;
     34 import org.mockito.ArgumentCaptor;
     35 import org.mockito.Mock;
     36 import org.mockito.MockitoAnnotations;
     37 import org.robolectric.RuntimeEnvironment;
     38 
     39 @RunWith(SettingsRobolectricTestRunner.class)
     40 public class BackgroundDataConditionTest {
     41     @Mock
     42     private ConditionManager mConditionManager;
     43 
     44     private Context mContext;
     45 
     46     @Before
     47     public void setUp() {
     48         MockitoAnnotations.initMocks(this);
     49         mContext = spy(RuntimeEnvironment.application);
     50         when(mConditionManager.getContext()).thenReturn(mContext);
     51     }
     52 
     53     @Test
     54     public void onPrimaryClick_v2enabled_shouldReturn2SummaryActivity() {
     55         FeatureFlagUtils.setEnabled(mContext, FeatureFlags.DATA_USAGE_SETTINGS_V2, true);
     56 
     57         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
     58         BackgroundDataCondition backgroundDataCondition
     59                 = new BackgroundDataCondition(mConditionManager);
     60         backgroundDataCondition.onPrimaryClick();
     61         verify(mContext).startActivity(argumentCaptor.capture());
     62         Intent intent = argumentCaptor.getValue();
     63 
     64         assertThat(intent.getComponent().getClassName()).isEqualTo(
     65                 Settings.DataUsageSummaryActivity.class.getName());
     66     }
     67 
     68     @Test
     69     public void onPrimaryClick_v2disabled_shouldReturnLegacySummaryActivity() {
     70         FeatureFlagUtils.setEnabled(mContext, FeatureFlags.DATA_USAGE_SETTINGS_V2, false);
     71 
     72         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
     73         BackgroundDataCondition backgroundDataCondition
     74                 = new BackgroundDataCondition(mConditionManager);
     75         backgroundDataCondition.onPrimaryClick();
     76         verify(mContext).startActivity(argumentCaptor.capture());
     77         Intent intent = argumentCaptor.getValue();
     78 
     79         assertThat(intent.getComponent().getClassName()).isEqualTo(
     80                 Settings.DataUsageSummaryLegacyActivity.class.getName());
     81     }
     82 }
     83