Java 类org.robolectric.shadow.api.Shadow 实例源码

项目:GitHub    文件:NotificationTargetTest.java   
@Before
public void setUp() {
  NotificationManager notificationManager = (NotificationManager) RuntimeEnvironment.application
      .getSystemService(Context.NOTIFICATION_SERVICE);
  shadowManager = (UpdateShadowNotificationManager) Shadow.extract(notificationManager);

  remoteViews = mock(RemoteViews.class);
  viewId = 123;
  notification = mock(Notification.class);
  notificationId = 456;
  notificationTag = "tag";


  target =
      new NotificationTarget(RuntimeEnvironment.application, 100 /*width*/, 100 /*height*/,
          viewId, remoteViews, notification, notificationId, notificationTag);
}
项目:GitHub    文件:FileDescriptorLocalUriFetcherTest.java   
@Test
public void testLoadResource_returnsFileDescriptor() throws Exception {
  Context context = RuntimeEnvironment.application;
  Uri uri = Uri.parse("file://nothing");

  ContentResolver contentResolver = context.getContentResolver();
  ContentResolverShadow shadow = (ContentResolverShadow) Shadow.extract(contentResolver);

  AssetFileDescriptor assetFileDescriptor = mock(AssetFileDescriptor.class);
  ParcelFileDescriptor parcelFileDescriptor = mock(ParcelFileDescriptor.class);
  when(assetFileDescriptor.getParcelFileDescriptor()).thenReturn(parcelFileDescriptor);
  shadow.registerFileDescriptor(uri, assetFileDescriptor);

  FileDescriptorLocalUriFetcher fetcher =
      new FileDescriptorLocalUriFetcher(context.getContentResolver(), uri);
  fetcher.loadData(Priority.NORMAL, callback);
  verify(callback).onDataReady(eq(parcelFileDescriptor));
}
项目:GitHub    文件:NotificationTargetTest.java   
@Before
public void setUp() {
  NotificationManager notificationManager =
      (NotificationManager)
          RuntimeEnvironment.application.getSystemService(Context.NOTIFICATION_SERVICE);
  shadowManager = Shadow.extract(notificationManager);

  remoteViews = mock(RemoteViews.class);
  viewId = 123;
  notification = mock(Notification.class);
  notificationId = 456;
  notificationTag = "tag";


  target =
      new NotificationTarget(RuntimeEnvironment.application, 100 /*width*/, 100 /*height*/,
          viewId, remoteViews, notification, notificationId, notificationTag);
}
项目:GitHub    文件:FileDescriptorLocalUriFetcherTest.java   
@Test
public void testLoadResource_returnsFileDescriptor() throws Exception {
  Context context = RuntimeEnvironment.application;
  Uri uri = Uri.parse("file://nothing");

  ContentResolver contentResolver = context.getContentResolver();
  ContentResolverShadow shadow = Shadow.extract(contentResolver);

  AssetFileDescriptor assetFileDescriptor = mock(AssetFileDescriptor.class);
  ParcelFileDescriptor parcelFileDescriptor = mock(ParcelFileDescriptor.class);
  when(assetFileDescriptor.getParcelFileDescriptor()).thenReturn(parcelFileDescriptor);
  shadow.registerFileDescriptor(uri, assetFileDescriptor);

  FileDescriptorLocalUriFetcher fetcher =
      new FileDescriptorLocalUriFetcher(context.getContentResolver(), uri);
  fetcher.loadData(Priority.NORMAL, callback);
  verify(callback).onDataReady(eq(parcelFileDescriptor));
}
项目:GitHub    文件:FileDescriptorLocalUriFetcherTest.java   
@Test
public void testLoadResource_withNullFileDescriptor_callsLoadFailed() {
  Context context = RuntimeEnvironment.application;
  Uri uri = Uri.parse("file://nothing");

  ContentResolver contentResolver = context.getContentResolver();
  ContentResolverShadow shadow = Shadow.extract(contentResolver);
  shadow.registerFileDescriptor(uri, null /*fileDescriptor*/);

  FileDescriptorLocalUriFetcher fetcher =
      new FileDescriptorLocalUriFetcher(context.getContentResolver(), uri);
  fetcher.loadData(Priority.NORMAL, callback);
  verify(callback).onLoadFailed(isA(FileNotFoundException.class));
}
项目:simple-view-behavior    文件:AnimationViewBehaviorTest.java   
@Test
public void animations() {
    ScaleAnimation animation = new ScaleAnimation(1f, 0f, 1f, 0f);
    AnimationViewBehavior behavior = new AnimationViewBehavior.Builder()
            .dependsOn(firstView.getId(), SimpleViewBehavior.DEPEND_TYPE_Y)
            .targetValue(100)
            .animation(animation)
            .build();

    CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(320, 200);
    params.setBehavior(behavior);
    secondView.setLayoutParams(params);

    ShadowAnimation shadowAnimation = Shadow.extract(animation);

    firstView.setY(50);
    coordinatorLayout.requestLayout();
    assertEquals(500L, shadowAnimation.getLastTimeGetTransform());

    firstView.setY(100);
    coordinatorLayout.requestLayout();
    assertEquals(1000L, shadowAnimation.getLastTimeGetTransform());
}
项目:GitHub    文件:ViewTargetTest.java   
@Before
public void setUp() {
  sdkVersion = Build.VERSION.SDK_INT;
  MockitoAnnotations.initMocks(this);
  view = new View(RuntimeEnvironment.application);
  target = new TestViewTarget(view);

  shadowView = Shadow.extract(view);
  shadowObserver = Shadow.extract(view.getViewTreeObserver());
}
项目:GitHub    文件:AppWidgetTargetTest.java   
@Before
public void setUp() {
  shadowManager = (UpdateShadowAppWidgetManager) Shadow
      .extract(AppWidgetManager.getInstance(RuntimeEnvironment.application));
  viewId = 1234;
  views = mock(RemoteViews.class);
}
项目:GitHub    文件:GifDrawableTest.java   
@Test
public void testShouldDrawFirstFrameBeforeAnyFrameRead() {
  Canvas canvas = new Canvas();
  drawable.draw(canvas);

  BitmapTrackingShadowCanvas shadowCanvas =
      (BitmapTrackingShadowCanvas) Shadow.extract(canvas);
  assertThat(shadowCanvas.getDrawnBitmaps()).containsExactly(firstFrame);
}
项目:GitHub    文件:StreamLocalUriFetcherTest.java   
@Test
public void testLoadResource_returnsInputStream() throws Exception {
  Context context = RuntimeEnvironment.application;
  Uri uri = Uri.parse("file://nothing");

  ContentResolver contentResolver = context.getContentResolver();
  ContentResolverShadow shadow = (ContentResolverShadow) Shadow.extract(contentResolver);
  shadow.registerInputStream(uri, new ByteArrayInputStream(new byte[0]));

  StreamLocalUriFetcher fetcher = new StreamLocalUriFetcher(context.getContentResolver(), uri);
  fetcher.loadData(Priority.NORMAL, callback);
  verify(callback).onDataReady(isNotNull(InputStream.class));
}
项目:GitHub    文件:StreamLocalUriFetcherTest.java   
@Test
public void testLoadResource_withNullInputStream_callsLoadFailed() {
  Context context = RuntimeEnvironment.application;
  Uri uri = Uri.parse("file://nothing");

  ContentResolver contentResolver = context.getContentResolver();
  ContentResolverShadow shadow = (ContentResolverShadow) Shadow.extract(contentResolver);

  shadow.registerInputStream(uri, null /*inputStream*/);

  StreamLocalUriFetcher fetcher = new StreamLocalUriFetcher(context.getContentResolver(), uri);
  fetcher.loadData(Priority.LOW, callback);

  verify(callback).onLoadFailed(isA(FileNotFoundException.class));
}
项目:GitHub    文件:FileDescriptorLocalUriFetcherTest.java   
@Test
public void testLoadResource_withNullFileDescriptor_callsLoadFailed() {
  Context context = RuntimeEnvironment.application;
  Uri uri = Uri.parse("file://nothing");

  ContentResolver contentResolver = context.getContentResolver();
  ContentResolverShadow shadow = (ContentResolverShadow) Shadow.extract(contentResolver);
  shadow.registerFileDescriptor(uri, null /*fileDescriptor*/);

  FileDescriptorLocalUriFetcher fetcher =
      new FileDescriptorLocalUriFetcher(context.getContentResolver(), uri);
  fetcher.loadData(Priority.NORMAL, callback);
  verify(callback).onLoadFailed(isA(FileNotFoundException.class));
}
项目:GitHub    文件:MemorySizeCalculatorTest.java   
@Test
public void testByteArrayPoolSize_withLowRamDevice_isHalfTheSpecifiedBytes() {
  LowRamActivityManager activityManager =
      (LowRamActivityManager) Shadow.extract(harness.activityManager);
  Util.setSdkVersionInt(19);
  activityManager.setMemoryClass(getLargeEnoughMemoryClass());
  activityManager.setIsLowRam(true);

  int byteArrayPoolSize = harness.getCalculator().getArrayPoolSizeInBytes();
  assertThat(byteArrayPoolSize).isEqualTo(harness.byteArrayPoolSizeBytes / 2);
}
项目:GitHub    文件:ViewTargetTest.java   
@Before
public void setUp() {
  sdkVersion = Build.VERSION.SDK_INT;
  MockitoAnnotations.initMocks(this);
  view = new View(RuntimeEnvironment.application);
  target = new TestViewTarget(view);
  attachStateTarget = new AttachStateTarget(view);

  shadowView = Shadow.extract(view);
  shadowObserver = Shadow.extract(view.getViewTreeObserver());
}
项目:GitHub    文件:GifDrawableTest.java   
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void testShouldDrawFirstFrameBeforeAnyFrameRead() {
  Canvas canvas = new Canvas();
  drawable.draw(canvas);

  BitmapTrackingShadowCanvas shadowCanvas = Shadow.extract(canvas);
  assertThat(shadowCanvas.getDrawnBitmaps()).containsExactly(firstFrame);
}
项目:GitHub    文件:StreamLocalUriFetcherTest.java   
@Test
public void testLoadResource_returnsInputStream() throws Exception {
  Context context = RuntimeEnvironment.application;
  Uri uri = Uri.parse("file://nothing");

  ContentResolver contentResolver = context.getContentResolver();
  ContentResolverShadow shadow = Shadow.extract(contentResolver);
  shadow.registerInputStream(uri, new ByteArrayInputStream(new byte[0]));

  StreamLocalUriFetcher fetcher = new StreamLocalUriFetcher(context.getContentResolver(), uri);
  fetcher.loadData(Priority.NORMAL, callback);
  verify(callback).onDataReady(isNotNull(InputStream.class));
}
项目:GitHub    文件:StreamLocalUriFetcherTest.java   
@Test
public void testLoadResource_withNullInputStream_callsLoadFailed() {
  Context context = RuntimeEnvironment.application;
  Uri uri = Uri.parse("file://nothing");

  ContentResolver contentResolver = context.getContentResolver();
  ContentResolverShadow shadow = Shadow.extract(contentResolver);

  shadow.registerInputStream(uri, null /*inputStream*/);

  StreamLocalUriFetcher fetcher = new StreamLocalUriFetcher(context.getContentResolver(), uri);
  fetcher.loadData(Priority.LOW, callback);

  verify(callback).onLoadFailed(isA(FileNotFoundException.class));
}
项目:GitHub    文件:MemorySizeCalculatorTest.java   
@Test
public void testByteArrayPoolSize_withLowRamDevice_isHalfTheSpecifiedBytes() {
  LowRamActivityManager activityManager = Shadow.extract(harness.activityManager);
  Util.setSdkVersionInt(19);
  activityManager.setMemoryClass(getLargeEnoughMemoryClass());
  activityManager.setIsLowRam();

  int byteArrayPoolSize = harness.getCalculator().getArrayPoolSizeInBytes();
  assertThat(byteArrayPoolSize).isEqualTo(harness.byteArrayPoolSizeBytes / 2);
}
项目:RxNetwork    文件:ShadowNetworkCapabilities.java   
public static NetworkCapabilities newInstance(long networkCapabilities, long transportTypes,
    int linkUpBandwidthKbps, int linkDownBandwidthKbps, String networkSpecifier,
    int signalStrength) {

  NetworkCapabilities nc = Shadow.newInstanceOf(NetworkCapabilities.class);
  final ShadowNetworkCapabilities capabilities = Shadow.extract(nc);

  capabilities.mNetworkCapabilities = networkCapabilities;
  capabilities.mTransportTypes = transportTypes;
  capabilities.mLinkUpBandwidthKbps = linkUpBandwidthKbps;
  capabilities.mLinkDownBandwidthKbps = linkDownBandwidthKbps;
  capabilities.mNetworkSpecifier = networkSpecifier;
  capabilities.mSignalStrength = signalStrength;
  return nc;
}
项目:pusher-websocket-android    文件:PushNotificationRegistrationTest.java   
@Test
public void testRegisterGCMStartsBroadcastManagerAndIntentService() throws ManifestValidator.InvalidManifestException {
    registration.registerGCM(context, "senderId", registrationListener);
    Intent expectedIntent = new Intent(context, GCMRegistrationIntentService.class);
    Intent startedIntent = shadowOf(RuntimeEnvironment.application).getNextStartedService();
    assertThat(startedIntent.getComponent(), equalTo(expectedIntent.getComponent()));
    Bundle extras = startedIntent.getExtras();
    assertEquals("senderId", extras.getString("gcm_defaultSenderId"));
    ShadowLocalBroadcastManager localBroadcastManager = (ShadowLocalBroadcastManager)   Shadow.extract(LocalBroadcastManager.getInstance(context));
    List<ShadowLocalBroadcastManager.Wrapper> receivers = localBroadcastManager.getRegisteredBroadcastReceivers();
    assertEquals(1, receivers.size());
}
项目:GitHub    文件:AppWidgetTargetTest.java   
@Before
public void setUp() {
  shadowManager = Shadow.extract(AppWidgetManager.getInstance(RuntimeEnvironment.application));
  viewId = 1234;
  views = mock(RemoteViews.class);
}
项目:GitHub    文件:DefaultConnectivityMonitorTest.java   
public ConnectivityHarness() {
  ConnectivityManager connectivityManager = (ConnectivityManager) RuntimeEnvironment.application
      .getSystemService(Context.CONNECTIVITY_SERVICE);
  shadowConnectivityManager = Shadow.extract(connectivityManager);
}
项目:JobSchedulerCompat    文件:ShadowJobParameters.java   
public static JobParameters newInstance(JobStatus jobStatus) {
    JobParameters jobParameters = Shadow.newInstanceOf(JobParameters.class);
    ShadowJobParameters shadowJobParameters = Shadow.extract(jobParameters);
    shadowJobParameters.setJobStatus(jobStatus);
    return jobParameters;
}