PageRenderTime 62ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/unit/src/com/android/settings/bluetooth/BluetoothDeviceDetailsRotationTest.java

https://gitlab.com/SkyDragon-OSP/platform_packages_apps_settings
Java | 105 lines | 76 code | 14 blank | 15 comment | 0 complexity | dea15e61180d05611fd7b90355c1a5d9 MD5 | raw file
  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. package com.android.settings.bluetooth;
  17. import static org.mockito.Mockito.when;
  18. import android.app.Instrumentation;
  19. import android.content.Context;
  20. import android.content.Intent;
  21. import android.os.Bundle;
  22. import android.os.RemoteException;
  23. import android.support.test.InstrumentationRegistry;
  24. import android.support.test.filters.SmallTest;
  25. import android.support.test.runner.AndroidJUnit4;
  26. import android.support.test.uiautomator.UiDevice;
  27. import com.android.settings.SettingsActivity;
  28. import com.android.settings.core.SubSettingLauncher;
  29. import com.android.settingslib.bluetooth.CachedBluetoothDevice;
  30. import com.android.settingslib.bluetooth.LocalBluetoothManager;
  31. import com.android.settingslib.core.instrumentation.Instrumentable;
  32. import org.junit.Before;
  33. import org.junit.Test;
  34. import org.junit.runner.RunWith;
  35. import org.mockito.Answers;
  36. import org.mockito.Mock;
  37. import org.mockito.MockitoAnnotations;
  38. @RunWith(AndroidJUnit4.class)
  39. @SmallTest
  40. public class BluetoothDeviceDetailsRotationTest {
  41. private Context mContext;
  42. private UiDevice mUiDevice;
  43. private Instrumentation mInstrumentation;
  44. @Mock(answer = Answers.RETURNS_DEEP_STUBS)
  45. private CachedBluetoothDevice mCachedDevice;
  46. @Mock(answer = Answers.RETURNS_DEEP_STUBS)
  47. private LocalBluetoothManager mBluetoothManager;
  48. private String mDeviceAddress;
  49. @Before
  50. public void setUp() throws Exception {
  51. MockitoAnnotations.initMocks(this);
  52. mContext = InstrumentationRegistry.getTargetContext();
  53. mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
  54. mInstrumentation = InstrumentationRegistry.getInstrumentation();
  55. mDeviceAddress = "AA:BB:CC:DD:EE:FF";
  56. when(mCachedDevice.getAddress()).thenReturn(mDeviceAddress);
  57. when(mCachedDevice.getName()).thenReturn("Mock Device");
  58. BluetoothDeviceDetailsFragment.sTestDataFactory =
  59. new BluetoothDeviceDetailsFragment.TestDataFactory() {
  60. @Override
  61. public CachedBluetoothDevice getDevice(String deviceAddress) {
  62. return mCachedDevice;
  63. }
  64. @Override
  65. public LocalBluetoothManager getManager(Context context) {
  66. return mBluetoothManager;
  67. }
  68. };
  69. }
  70. @Test
  71. public void rotation() {
  72. Intent intent = new Intent("android.settings.BLUETOOTH_SETTINGS");
  73. SettingsActivity activity = (SettingsActivity) mInstrumentation.startActivitySync(intent);
  74. Bundle args = new Bundle(1);
  75. args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, mDeviceAddress);
  76. new SubSettingLauncher(activity)
  77. .setDestination(BluetoothDeviceDetailsFragment.class.getName())
  78. .setTitle("test")
  79. .setArguments(args)
  80. .setSourceMetricsCategory(Instrumentable.METRICS_CATEGORY_UNKNOWN)
  81. .launch();
  82. try {
  83. mUiDevice.setOrientationLeft();
  84. mUiDevice.setOrientationNatural();
  85. mUiDevice.setOrientationRight();
  86. mUiDevice.setOrientationNatural();
  87. } catch (RemoteException e) {
  88. throw new RuntimeException(e);
  89. }
  90. }
  91. }