Home | History | Annotate | Download | only in shadows
      1 package org.robolectric.shadows;
      2 
      3 import static org.robolectric.shadow.api.Shadow.directlyOn;
      4 
      5 import android.bluetooth.BluetoothDevice;
      6 import android.bluetooth.IBluetooth;
      7 import org.robolectric.annotation.Implementation;
      8 import org.robolectric.annotation.Implements;
      9 
     10 @Implements(BluetoothDevice.class)
     11 public class ShadowBluetoothDevice {
     12 
     13   private String name;
     14 
     15   /**
     16    * Implements getService() in the same way the original method does, but ignores any Exceptions
     17    * from invoking {@link BluetoothAdapter#getBluetoothService}.
     18    */
     19   @Implementation
     20   public static IBluetooth getService() {
     21     // Attempt to call the underlying getService method, but ignore any Exceptions. This allows us
     22     // to easily create BluetoothDevices for testing purposes without having any actual Bluetooth
     23     // capability.
     24     try {
     25       return directlyOn(BluetoothDevice.class, "getService");
     26     } catch (Exception e) {
     27       // No-op.
     28     }
     29     return null;
     30   }
     31 
     32   public void setName(String name) {
     33     this.name = name;
     34   }
     35 
     36   @Implementation
     37   public String getName() {
     38     return name;
     39   }
     40 }
     41