Search in sources :

Example 61 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project android_packages_apps_Settings by omnirom.

the class ProviderModelSliceTest method setUp.

@Before
@UiThreadTest
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(ApplicationProvider.getApplicationContext());
    mFeatureFactory = FakeFeatureFactory.setupForTest();
    when(mFeatureFactory.wifiTrackerLibProvider.createWifiPickerTracker(any(), any(), any(), any(), any(), anyLong(), anyLong(), any())).thenReturn(mWifiPickerTracker);
    when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
    when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
    when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
    when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
    when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
    when(mWifiManager.isWifiEnabled()).thenReturn(true);
    // Set-up specs for SliceMetadata.
    SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
    mMockNetworkProviderWorker = spy(new MockNetworkProviderWorker(mContext, PROVIDER_MODEL_SLICE_URI));
    mMockProviderModelSlice = spy(new MockProviderModelSlice(mContext, mMockNetworkProviderWorker));
    mMockAlertDialog = new AlertDialog.Builder(mContext).setTitle("").create();
    mMockAlertDialog = spy(mMockAlertDialog);
    mMockProviderModelSlice.setMobileDataDisableDialog(mMockAlertDialog);
    mListBuilder = spy(new ListBuilder(mContext, PROVIDER_MODEL_SLICE_URI, ListBuilder.INFINITY).setAccentColor(-1));
    when(mProviderModelSliceHelper.createListBuilder(PROVIDER_MODEL_SLICE_URI)).thenReturn(mListBuilder);
    when(mProviderModelSliceHelper.getSubscriptionManager()).thenReturn(mSubscriptionManager);
    mWifiList = new ArrayList<>();
    mMockNetworkProviderWorker.updateSelfResults(mWifiList);
    mockBuilder();
}
Also used : AlertDialog(android.app.AlertDialog) ListBuilder(androidx.slice.builders.ListBuilder) Before(org.junit.Before) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 62 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project android_packages_apps_Settings by omnirom.

the class ProviderModelSliceTest method getSlice_haveEthernetAndCarrierAndConnectedWifiAndDisconnectedWifi_getSixRow.

@Test
@UiThreadTest
public void getSlice_haveEthernetAndCarrierAndConnectedWifiAndDisconnectedWifi_getSixRow() {
    mWifiList.clear();
    mockWifiItemCondition(mMockWifiSliceItem1, "wifi1", "wifi1", WifiEntry.CONNECTED_STATE_CONNECTED, "wifi1_key", true);
    mWifiList.add(mMockWifiSliceItem1);
    mockWifiItemCondition(mMockWifiSliceItem2, "wifi2", "wifi2", WifiEntry.CONNECTED_STATE_DISCONNECTED, "wifi2_key", true);
    mWifiList.add(mMockWifiSliceItem2);
    mMockNetworkProviderWorker.updateSelfResults(mWifiList);
    mockHelperCondition(false, true, true, mWifiList.get(0));
    when(mMockNetworkProviderWorker.getInternetType()).thenReturn(InternetUpdater.INTERNET_ETHERNET);
    final Slice slice = mMockProviderModelSlice.getSlice();
    assertThat(slice).isNotNull();
    assertThat(mMockProviderModelSlice.hasCreateEthernetRow()).isTrue();
    verify(mListBuilder, times(1)).addRow(mMockCarrierRowBuild);
    verify(mListBuilder, times(6)).addRow(any(ListBuilder.RowBuilder.class));
    assertThat(mMockProviderModelSlice.hasSeeAllRow()).isTrue();
}
Also used : Slice(androidx.slice.Slice) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 63 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project android_packages_apps_Settings by omnirom.

the class ProviderModelSliceTest method getSlice_noWifiAndNoCarrier_oneCarrier.

@Test
@UiThreadTest
public void getSlice_noWifiAndNoCarrier_oneCarrier() {
    mWifiList.clear();
    mMockProviderModelSlice = new MockProviderModelSlice(mContext, null);
    mockHelperCondition(false, true, true, null);
    final Slice slice = mMockProviderModelSlice.getSlice();
    assertThat(slice).isNotNull();
    verify(mListBuilder, times(1)).addRow(mMockCarrierRowBuild);
    assertThat(mMockProviderModelSlice.hasSeeAllRow()).isFalse();
}
Also used : Slice(androidx.slice.Slice) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 64 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project android_packages_apps_Settings by omnirom.

the class ProviderModelSliceTest method getSlice_noWifiAndHasCarrierNoData_oneCarrier.

@Test
@UiThreadTest
public void getSlice_noWifiAndHasCarrierNoData_oneCarrier() {
    mWifiList.clear();
    mMockNetworkProviderWorker.updateSelfResults(null);
    mockHelperCondition(false, true, false, null);
    final Slice slice = mMockProviderModelSlice.getSlice();
    assertThat(slice).isNotNull();
    verify(mListBuilder, times(1)).addRow(mMockCarrierRowBuild);
    assertThat(mMockProviderModelSlice.hasSeeAllRow()).isFalse();
}
Also used : Slice(androidx.slice.Slice) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 65 with UiThreadTest

use of androidx.test.annotation.UiThreadTest in project android_packages_apps_Settings by omnirom.

the class ProviderModelSliceTest method onNotifyChange_FirstTimeDisableToggleState_showDialog.

@Test
@UiThreadTest
public void onNotifyChange_FirstTimeDisableToggleState_showDialog() {
    final Intent intent = new Intent();
    intent.putExtra(EXTRA_TOGGLE_STATE, false);
    SharedPreferences sharedPref = mMockProviderModelSlice.getSharedPreference();
    when(mProviderModelSliceHelper.getMobileTitle()).thenReturn("mockRow");
    if (sharedPref != null) {
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putBoolean(PREF_HAS_TURNED_OFF_MOBILE_DATA, true);
        editor.apply();
    }
    mMockProviderModelSlice.onNotifyChange(intent);
    verify(mMockAlertDialog).show();
}
Also used : SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

UiThreadTest (androidx.test.annotation.UiThreadTest)136 Test (org.junit.Test)129 View (android.view.View)41 Unbinder (butterknife.Unbinder)31 Context (android.content.Context)23 AdapterView (android.widget.AdapterView)18 TextView (android.widget.TextView)15 RecordingObserver (com.jakewharton.rxbinding4.RecordingObserver)15 MediumTest (androidx.test.filters.MediumTest)14 Intent (android.content.Intent)10 SubscriptionInfo (android.telephony.SubscriptionInfo)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 LocalPSMP (de.danoeh.antennapod.core.service.playback.LocalPSMP)9 PlaybackServiceMediaPlayer (de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer)9 Slice (androidx.slice.Slice)8 Playable (de.danoeh.antennapod.model.playback.Playable)8 AssertionFailedError (junit.framework.AssertionFailedError)8 Before (org.junit.Before)7 ViewGroup (android.view.ViewGroup)6 FrameLayout (android.widget.FrameLayout)6