private static void assertBuffer(byte[] expected, int expectedStart, int expectedLength) { for (int i = 0; i < expectedLength; i++) { assertThat(BUFFER[i]).isEqualTo(expected[i + expectedStart]); } }
@Test @Config(minSdk = M) public void setAndAllowWhileIdle_shouldRegisterAlarm() { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); alarmManager.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME, 0, PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0)); assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNotNull(); }
@Test public void testSetAdUriBeforeAdCount() { state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1, TEST_URI); state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2); assertThat(state.adGroups[0].uris[0]).isNull(); assertThat(state.adGroups[0].states[0]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE); assertThat(state.adGroups[0].uris[1]).isSameAs(TEST_URI); assertThat(state.adGroups[0].states[1]).isEqualTo(AdPlaybackState.AD_STATE_AVAILABLE); }
@Test public void getConstructor_withTwoClassParams() { Constructors a = new Constructors(PARAM1, PARAM2); ShadowConstructors sa = shadowOf(a); assertThat(a.param21).isNull(); assertThat(a.param22).isNull(); assertThat(sa.shadowParam21).isEqualTo(PARAM1); assertThat(sa.shadowParam22).isEqualTo(PARAM2); Shadow.invokeConstructor(Constructors.class, a, ClassParameter.from(String.class, PARAM1), ClassParameter.from(Byte.class, PARAM2)); assertThat(a.param21).isEqualTo(PARAM1); assertThat(a.param22).isEqualTo(PARAM2); }
private void assertCacheSpan(String key, long offset, long lastAccessTimestamp) throws IOException { int id = index.assignIdForKey(key); File cacheFile = createCacheSpanFile(cacheDir, id, offset, 1, lastAccessTimestamp); SimpleCacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(cacheFile, index); String message = cacheFile.toString(); assertWithMessage(message).that(cacheSpan).isNotNull(); assertWithMessage(message).that(cacheFile.getParentFile()).isEqualTo(cacheDir); assertWithMessage(message).that(cacheSpan.key).isEqualTo(key); assertWithMessage(message).that(cacheSpan.position).isEqualTo(offset); assertWithMessage(message).that(cacheSpan.length).isEqualTo(1); assertWithMessage(message).that(cacheSpan.isCached).isTrue(); assertWithMessage(message).that(cacheSpan.file).isEqualTo(cacheFile); assertWithMessage(message).that(cacheSpan.lastAccessTimestamp).isEqualTo(lastAccessTimestamp); }
@Test @Config(minSdk = LOLLIPOP) public void getProfileOwnerShouldReturnNullWhenThereIsNoProfileOwner() { // WHEN DevicePolicyManager#getProfileOwner is called without a profile owner // THEN the method should return null assertThat(devicePolicyManager.getProfileOwner()).isNull(); }
@Test public void shouldWriteToExternalCacheDir() throws Exception { assertThat(context.getExternalCacheDir()).isNotNull(); File cacheTest = new File(context.getExternalCacheDir(), "__test__"); assertThat(cacheTest.getAbsolutePath()) .startsWith(System.getProperty("java.io.tmpdir")); assertThat(cacheTest.getAbsolutePath()) .endsWith(File.separator + "__test__"); try (FileOutputStream fos = new FileOutputStream(cacheTest)) { fos.write("test".getBytes(UTF_8)); } assertThat(cacheTest.exists()).isTrue(); }
@Test public void testSetDataSourceUri() throws IOException { Map<String, String> headers = new HashMap<>(); Uri uri = Uri.parse("file:/test"); DataSource ds = toDataSource(ApplicationProvider.getApplicationContext(), uri, headers); ShadowMediaPlayer.addMediaInfo(ds, info); mediaPlayer.setDataSource(ApplicationProvider.getApplicationContext(), uri, headers); assertThat(shadowMediaPlayer.getSourceUri()).named("sourceUri").isSameAs(uri); assertThat(shadowMediaPlayer.getDataSource()).named("dataSource").isEqualTo(ds); }
@Test public void testGetNotificationUri() { Uri uri = Uri.parse("content://foo.com"); ShadowAbstractCursor shadow = Shadows.shadowOf(cursor); assertThat(shadow.getNotificationUri_Compatibility()).isNull(); cursor.setNotificationUri( ApplicationProvider.getApplicationContext().getContentResolver(), uri); assertThat(shadow.getNotificationUri_Compatibility()).isEqualTo(uri); }
@Test public void getNextScheduledAlarm_shouldReturnRepeatingAlarms() { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); long now = new Date().getTime(); Intent intent = new Intent(activity, activity.getClass()); PendingIntent pendingIntent = PendingIntent.getActivity(activity, 0, intent, 0); alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, now, INTERVAL_HOUR, pendingIntent); ShadowAlarmManager.ScheduledAlarm scheduledAlarm = shadowAlarmManager.getNextScheduledAlarm(); assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); assertRepeatingScheduledAlarm(now, INTERVAL_HOUR, pendingIntent, scheduledAlarm); }
@Test public void shouldWriteToCacheDir() throws Exception { assertThat(context.getCacheDir()).isNotNull(); File cacheTest = new File(context.getCacheDir(), "__test__"); assertThat(cacheTest.getAbsolutePath()) .startsWith(System.getProperty("java.io.tmpdir")); assertThat(cacheTest.getAbsolutePath()) .endsWith(File.separator + "__test__"); try (FileOutputStream fos = new FileOutputStream(cacheTest)) { fos.write("test".getBytes(UTF_8)); } assertThat(cacheTest.exists()).isTrue(); }
@Test public void getMaxSupportedSdk() throws Exception { assertThat(sdkCollection.getMaxSupportedSdk()).isSameAs(fakeSdk1236); }
public void testToFile() throws Exception { assertThat(ClassPath.toFile(new URL("file:///c:/Documents%20and%20Settings/"))) .isEqualTo(new File("/c:/Documents and Settings/")); assertThat(ClassPath.toFile(new URL("file:///c:/Documents ~ Settings, or not/11-12 12:05"))) .isEqualTo(new File("/c:/Documents ~ Settings, or not/11-12 12:05")); }
@Test public void bindServiceShouldCallOnServiceConnectedWithDefaultValues() { TestService service = new TestService(); ComponentName expectedComponentName = new ComponentName("", ""); Binder expectedBinder = new Binder(); Shadows.shadowOf(context) .setComponentNameAndServiceForBindService(expectedComponentName, expectedBinder); context.bindService(new Intent(""), service, Context.BIND_AUTO_CREATE); assertThat(service.name).isEqualTo(expectedComponentName); assertThat(service.service).isEqualTo(expectedBinder); assertThat(service.nameUnbound).isNull(); context.unbindService(service); assertThat(service.nameUnbound).isEqualTo(expectedComponentName); }
@Test @Config(minSdk = KITKAT) public void setWindow_shouldRegisterAlarm_forApi19() { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); alarmManager.setWindow(AlarmManager.ELAPSED_REALTIME, 0, 1, PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0)); assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNotNull(); }
@Test public void shouldSupportGetNextScheduledAlarm() { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); long now = new Date().getTime(); Intent intent = new Intent(activity, activity.getClass()); PendingIntent pendingIntent = PendingIntent.getActivity(activity, 0, intent, 0); alarmManager.set(AlarmManager.ELAPSED_REALTIME, now, pendingIntent); ShadowAlarmManager.ScheduledAlarm scheduledAlarm = shadowAlarmManager.getNextScheduledAlarm(); assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); assertScheduledAlarm(now, pendingIntent, scheduledAlarm); }
@Test public void testDispatchChangeBooleanUri() { assertThat(observer.changed).isFalse(); assertThat(observer.selfChange).isFalse(); assertThat(observer.uri).isNull(); Uri uri = Uri.parse("http://www.somewhere.com"); observer.dispatchChange(true, uri); assertThat(observer.changed).isTrue(); assertThat(observer.selfChange).isTrue(); assertThat(observer.uri).isSameAs(uri); }
@Test public void testConfiguration() { Configuration configuration = resources.getConfiguration(); assertThat(configuration).isNotNull(); assertThat(configuration.locale).isNotNull(); }