Java 类org.robolectric.internal.Shadow 实例源码

项目:GitHub    文件:MyShadowBitmap.java   
@Implementation
public static Bitmap createBitmap(int width, int height, Bitmap.Config config) {
  Bitmap bitmap = Shadow.newInstanceOf(Bitmap.class);
  MyShadowBitmap shadowBitmap = (MyShadowBitmap) ShadowExtractor.extract(bitmap);
  shadowBitmap.width = width;
  shadowBitmap.height = height;
  shadowBitmap.mPixels = new int[width * height];
  return bitmap;
}
项目:GitHub    文件:MyShadowBitmap.java   
@Implementation
public static Bitmap createBitmap(int colors[], int width, int height, Bitmap.Config config) {
  Bitmap bitmap = Shadow.newInstanceOf(Bitmap.class);
  MyShadowBitmap shadowBitmap = (MyShadowBitmap) ShadowExtractor.extract(bitmap);
  shadowBitmap.width = width;
  shadowBitmap.height = height;
  shadowBitmap.mPixels = new int[width * height];
  for (int i = 0; i < colors.length; i++) {
    shadowBitmap.mPixels[i] = colors[i];
  }
  return bitmap;
}
项目:fresco    文件:MyShadowBitmap.java   
@Implementation
public static Bitmap createBitmap(int width, int height, Bitmap.Config config) {
  Bitmap bitmap = Shadow.newInstanceOf(Bitmap.class);
  MyShadowBitmap shadowBitmap = (MyShadowBitmap) ShadowExtractor.extract(bitmap);
  shadowBitmap.width = width;
  shadowBitmap.height = height;
  shadowBitmap.mPixels = new int[width * height];
  return bitmap;
}
项目:fresco    文件:MyShadowBitmap.java   
@Implementation
public static Bitmap createBitmap(int colors[], int width, int height, Bitmap.Config config) {
  Bitmap bitmap = Shadow.newInstanceOf(Bitmap.class);
  MyShadowBitmap shadowBitmap = (MyShadowBitmap) ShadowExtractor.extract(bitmap);
  shadowBitmap.width = width;
  shadowBitmap.height = height;
  shadowBitmap.mPixels = new int[width * height];
  for (int i = 0; i < colors.length; i++) {
    shadowBitmap.mPixels[i] = colors[i];
  }
  return bitmap;
}
项目:BlueSTSDK_Android    文件:BluetoothDeviceShadow.java   
/**
 * open a connection with the device the returning connection is a shadow object that can be
 * queue with the mockito framework
 * @param c
 * @param b
 * @param callback
 * @return
 */
@Implementation
public BluetoothGatt connectGatt(Context c,boolean b,BluetoothGattCallback callback){
    mGattConnection = spy(Shadow.newInstanceOf(BluetoothGatt.class));
    BluetoothGattShadow shadowGatt =
            ((BluetoothGattShadow)ShadowExtractor.extract(mGattConnection));
    shadowGatt.setGattCallBack(callback);
    shadowGatt.setServices(mServices);
    mGattConnection.connect();
    return mGattConnection;
}
项目:BlueSTSDK_Android    文件:NodeTest.java   
@Test
public void connectEmptyNode(){

    BluetoothDevice device = spy(Shadow.newInstanceOf(BluetoothDevice.class));
    Node node = createNode(device);

    Assert.assertEquals(Node.State.Idle, node.getState());
    node.connect(RuntimeEnvironment.application);

    TestUtil.execAllAsyncTask();

    verify(device).connectGatt(eq(RuntimeEnvironment.application), eq(false),
            any(BluetoothGattCallback.class));
    Assert.assertEquals(Node.State.Dead, node.getState());
}
项目:BlueSTSDK_Android    文件:NodeTest.java   
@Test
public void connectNodeWithDebug(){

    BluetoothDevice device = spy(Shadow.newInstanceOf(BluetoothDevice.class));
    BluetoothDeviceShadow shadowDevice = (BluetoothDeviceShadow)ShadowExtractor.extract(device);

    BluetoothGattService debugService = new BluetoothGattService(BLENodeDefines.Services
            .Debug.DEBUG_SERVICE_UUID,BluetoothGattService.SERVICE_TYPE_PRIMARY);
    debugService.addCharacteristic(
            new BluetoothGattCharacteristic(BLENodeDefines.Services.Debug.DEBUG_STDERR_UUID,
                    BluetoothGattCharacteristic.PERMISSION_READ |
                            BluetoothGattCharacteristic.PERMISSION_WRITE,
                    BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic
                            .PROPERTY_NOTIFY));
    debugService.addCharacteristic(
            new BluetoothGattCharacteristic(BLENodeDefines.Services.Debug.DEBUG_TERM_UUID,
                    BluetoothGattCharacteristic.PERMISSION_READ |
                            BluetoothGattCharacteristic.PERMISSION_WRITE,
                    BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic
                            .PROPERTY_NOTIFY)
    );

    shadowDevice.addService(debugService);

    Node node = createNode(device);
    Assert.assertEquals(Node.State.Idle, node.getState());
    node.connect(RuntimeEnvironment.application);

    TestUtil.execAllAsyncTask();

    verify(device).connectGatt(eq(RuntimeEnvironment.application), eq(false),
            any(BluetoothGattCallback.class));
    Assert.assertEquals(Node.State.Connected, node.getState());
    Assert.assertTrue(node.getDebug()!=null);
}
项目:BlueSTSDK_Android    文件:NodeTest.java   
@Test
public void enableDisableNotificationForFeature(){
    SparseArray <Class <? extends Feature> > temp = new SparseArray<>();
    temp.append(0x01,FakeFeature.class);
    try {
        Manager.addFeatureToNode((byte)0x00,temp);
    } catch (InvalidFeatureBitMaskException e) {
        Assert.fail("Impossible add the FakeFeature");
    }

    BluetoothDevice device = spy(Shadow.newInstanceOf(BluetoothDevice.class));
    BluetoothDeviceShadow shadowDevice = (BluetoothDeviceShadow)ShadowExtractor.extract(device);
    BluetoothGattService dataService = new BluetoothGattService(
            UUID.randomUUID(),
            BluetoothGattService.SERVICE_TYPE_PRIMARY);
    dataService.addCharacteristic(createReadNotifyChar(
            UUID.fromString("000000001-"+BLENodeDefines.FeatureCharacteristics.COMMON_FEATURE_UUID)
    ));
    shadowDevice.addService(dataService);
    Node n = createNode(device);
    n.connect(RuntimeEnvironment.application);

    TestUtil.execAllAsyncTask();

    Feature f = n.getFeature(FakeFeature.class);
    Assert.assertFalse(n.isEnableNotification(f));
    Assert.assertTrue(n.enableNotification(f));
    Assert.assertTrue(n.isEnableNotification(f));
    Assert.assertTrue(n.disableNotification(f));
    Assert.assertFalse(n.isEnableNotification(f));
}
项目:BlueSTSDK_Android    文件:NodeTest.java   
@Test
public void updateFeature(){
    SparseArray <Class <? extends Feature> > temp = new SparseArray<>();
    temp.append(0x01,FakeFeature.class);
    try {
        Manager.addFeatureToNode((byte)0x00,temp);
    } catch (InvalidFeatureBitMaskException e) {
        Assert.fail("Impossible add the FakeFeature");
    }

    BluetoothDevice device = spy(Shadow.newInstanceOf(BluetoothDevice.class));
    BluetoothDeviceShadow shadowDevice = (BluetoothDeviceShadow)ShadowExtractor.extract(device);
    BluetoothGattService dataService = new BluetoothGattService(
            UUID.randomUUID(),
            BluetoothGattService.SERVICE_TYPE_PRIMARY);
    BluetoothGattCharacteristic dataChar = createReadNotifyChar(
            UUID.fromString("000000001-" + BLENodeDefines.FeatureCharacteristics.COMMON_FEATURE_UUID)
    );
    dataService.addCharacteristic(dataChar);
    shadowDevice.addService(dataService);
    Node n = createNode(device);
    n.connect(RuntimeEnvironment.application);

    TestUtil.execAllAsyncTask();

    BluetoothGatt gatt = shadowDevice.getGattConnection();
    Feature.FeatureListener emptyListener = mock(Feature.FeatureListener.class);
    FakeFeature f = n.getFeature(FakeFeature.class);
    Assert.assertTrue(f != null);
    f.addFeatureListener(emptyListener);
    Assert.assertTrue(n.enableNotification(f));

    TestUtil.execAllAsyncTask();
    f.execAllTask();

    verify(gatt).setCharacteristicNotification(dataChar, true);
    verify(emptyListener).onUpdate(eq(f), any(Feature.Sample.class));

    Assert.assertTrue(n.disableNotification(f));
    verify(gatt).setCharacteristicNotification(dataChar, false);
}
项目:stabbed-android    文件:StabbedIntentServiceTest.java   
@Before
public void setUp() throws Exception {
    mActivityController = Robolectric.buildActivity(TestStabbedActivity.class);
    mActivity = mActivityController.get();
    mTestStabbedIntentService = Shadow.newInstanceOf(TestStabbedIntentService.class);
}
项目:stabbed-android    文件:StabbedServiceTest.java   
@Before
public void setUp() throws Exception {
    mActivityController = Robolectric.buildActivity(TestStabbedActivity.class);
    mActivity = mActivityController.get();
    mTestStabbedService = Shadow.newInstanceOf(TestStabbedService.class);
}