OSDN Git Service

Merge "Fix Robolectric Bluetooth tests" am: 01c9c0e4ba
authorHansong Zhang <hsz@google.com>
Tue, 31 Oct 2017 02:50:44 +0000 (02:50 +0000)
committerandroid-build-merger <android-build-merger@google.com>
Tue, 31 Oct 2017 02:50:44 +0000 (02:50 +0000)
am: 2f1cb548ba

Change-Id: Ifded4e54edd53242a40d3f8e123f614cd6e44d84

1  2 
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java

@@@ -158,52 -149,7 +158,52 @@@ public class CachedBluetoothDeviceTest 
                  com.android.settingslib.Utils.formatPercentage(mBatteryLevel)));
  
          // Disconnect all profiles and test connection state summary
-         mCachedDevice.onProfileStateChanged(mHidProfile, BluetoothProfile.STATE_DISCONNECTED);
+         mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
          assertThat(mCachedDevice.getConnectionSummary()).isNull();
      }
 +
 +    @Test
 +    public void testDeviceName_testAliasNameAvailable() {
 +        when(mDevice.getAliasName()).thenReturn(DEVICE_ALIAS);
 +        when(mDevice.getName()).thenReturn(DEVICE_NAME);
 +        CachedBluetoothDevice cachedBluetoothDevice =
 +                new CachedBluetoothDevice(mContext, mAdapter, mProfileManager, mDevice);
 +        // Verify alias is returned on getName
 +        assertThat(cachedBluetoothDevice.getName()).isEqualTo(DEVICE_ALIAS);
 +        // Verify device is visible
 +        assertThat(cachedBluetoothDevice.hasHumanReadableName()).isTrue();
 +    }
 +
 +    @Test
 +    public void testDeviceName_testNameNotAvailable() {
 +        CachedBluetoothDevice cachedBluetoothDevice =
 +                new CachedBluetoothDevice(mContext, mAdapter, mProfileManager, mDevice);
 +        // Verify device address is returned on getName
 +        assertThat(cachedBluetoothDevice.getName()).isEqualTo(DEVICE_ADDRESS);
 +        // Verify device is not visible
 +        assertThat(cachedBluetoothDevice.hasHumanReadableName()).isFalse();
 +    }
 +
 +    @Test
 +    public void testDeviceName_testRenameDevice() {
 +        final String[] alias = {DEVICE_ALIAS};
 +        doAnswer(invocation -> alias[0]).when(mDevice).getAliasName();
 +        doAnswer(invocation -> {
 +            alias[0] = (String) invocation.getArguments()[0];
 +            return true;
 +        }).when(mDevice).setAlias(anyString());
 +        when(mDevice.getName()).thenReturn(DEVICE_NAME);
 +        CachedBluetoothDevice cachedBluetoothDevice =
 +                new CachedBluetoothDevice(mContext, mAdapter, mProfileManager, mDevice);
 +        // Verify alias is returned on getName
 +        assertThat(cachedBluetoothDevice.getName()).isEqualTo(DEVICE_ALIAS);
 +        // Verify null name does not get set
 +        cachedBluetoothDevice.setName(null);
 +        verify(mDevice, never()).setAlias(any());
 +        // Verify new name is set properly
 +        cachedBluetoothDevice.setName(DEVICE_ALIAS_NEW);
 +        verify(mDevice).setAlias(DEVICE_ALIAS_NEW);
 +        // Verify new alias is returned on getName
 +        assertThat(cachedBluetoothDevice.getName()).isEqualTo(DEVICE_ALIAS_NEW);
 +    }
  }