@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); }
@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)); }
@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); }
@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)); }
@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)); }
@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()); }
@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()); }
@Before public void setUp() { shadowManager = (UpdateShadowAppWidgetManager) Shadow .extract(AppWidgetManager.getInstance(RuntimeEnvironment.application)); viewId = 1234; views = mock(RemoteViews.class); }
@Test public void testShouldDrawFirstFrameBeforeAnyFrameRead() { Canvas canvas = new Canvas(); drawable.draw(canvas); BitmapTrackingShadowCanvas shadowCanvas = (BitmapTrackingShadowCanvas) Shadow.extract(canvas); assertThat(shadowCanvas.getDrawnBitmaps()).containsExactly(firstFrame); }
@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)); }
@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)); }
@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)); }
@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); }
@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()); }
@SuppressWarnings("ResultOfMethodCallIgnored") @Test public void testShouldDrawFirstFrameBeforeAnyFrameRead() { Canvas canvas = new Canvas(); drawable.draw(canvas); BitmapTrackingShadowCanvas shadowCanvas = Shadow.extract(canvas); assertThat(shadowCanvas.getDrawnBitmaps()).containsExactly(firstFrame); }
@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)); }
@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)); }
@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); }
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; }
@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()); }
@Before public void setUp() { shadowManager = Shadow.extract(AppWidgetManager.getInstance(RuntimeEnvironment.application)); viewId = 1234; views = mock(RemoteViews.class); }
public ConnectivityHarness() { ConnectivityManager connectivityManager = (ConnectivityManager) RuntimeEnvironment.application .getSystemService(Context.CONNECTIVITY_SERVICE); shadowConnectivityManager = Shadow.extract(connectivityManager); }
public static JobParameters newInstance(JobStatus jobStatus) { JobParameters jobParameters = Shadow.newInstanceOf(JobParameters.class); ShadowJobParameters shadowJobParameters = Shadow.extract(jobParameters); shadowJobParameters.setJobStatus(jobStatus); return jobParameters; }