@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 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 @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(); }
private void assertRepeatingScheduledAlarm(long now, long interval, PendingIntent pendingIntent, ShadowAlarmManager.ScheduledAlarm scheduledAlarm) { assertThat(scheduledAlarm).isNotNull(); assertThat(scheduledAlarm.operation).isNotNull(); assertThat(scheduledAlarm.operation).isSameAs(pendingIntent); assertThat(scheduledAlarm.type).isEqualTo(AlarmManager.ELAPSED_REALTIME); assertThat(scheduledAlarm.triggerAtTime).isEqualTo(now); assertThat(scheduledAlarm.interval).isEqualTo(interval); } }
@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 @Config(minSdk = M) public void setExactAndAllowWhileIdle_shouldRegisterAlarm() { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME, 0, PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0)); assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNotNull(); }
@Test @Config(minSdk = KITKAT) public void setExact_shouldRegisterAlarm_forApi19() { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, 0, PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0)); assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNotNull(); }
@Test public void setRepeating_shouldRegisterAlarm() { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, 0, INTERVAL_HOUR, PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0)); assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNotNull(); }
@Test public void set_shouldRegisterAlarm() { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); alarmManager.set(AlarmManager.ELAPSED_REALTIME, 0, PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0)); assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNotNull(); }
@Test public void peekNextScheduledAlarm_shouldReturnNextAlarm() { 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.peekNextScheduledAlarm(); assertThat(shadowAlarmManager.peekNextScheduledAlarm()).isNotNull(); assertScheduledAlarm(now, pendingIntent, scheduledAlarm); }
assertThat(file).isNotNull(); SecurityManager disallowFilesSecurityManager = new SecurityManager() {
@Test @Config(minSdk = N) public void set_shouldRegisterAlarm_forApi24() { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); OnAlarmListener listener = () -> {}; alarmManager.set(AlarmManager.ELAPSED_REALTIME, 0, "tag", listener, null); assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNotNull(); }
@Test @Config(minSdk = N) public void setExact_shouldRegisterAlarm_forApi124() { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); OnAlarmListener listener = () -> {}; alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, 0, "tag", listener, null); assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNotNull(); }
@Test @Config(minSdk = N) public void setWindow_shouldRegisterAlarm_forApi24() { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); OnAlarmListener listener = () -> {}; alarmManager.setWindow(AlarmManager.ELAPSED_REALTIME, 0, 1, "tag", listener, null); assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNotNull(); }
@Test public void testDateInterval_FormatDateRange() throws ParseException { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2013); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_MONTH, 20); long timeInMillis = calendar.getTimeInMillis(); String actual = DateIntervalFormat.formatDateRange(ULocale.getDefault(), TimeZone.getDefault(), timeInMillis, timeInMillis, DateUtils.FORMAT_NUMERIC_DATE); DateFormat format = new SimpleDateFormat("MM/dd/yyyy", ULocale.getDefault()); Date date = format.parse(actual); assertThat(date).isNotNull(); } }
@Test public void preferenceAddedWithCorrectDetails() { Preference preference = fragment.findPreference("edit_text"); assertThat(preference).isNotNull(); assertThat(preference.getTitle()).isEqualTo("EditText Test"); assertThat(preference.getSummary()).isEqualTo(""); }
@Test public void getSdk_shouldReturnNullObjectForUnknownSdks() throws Exception { assertThat(sdkCollection.getSdk(4321)).isNotNull(); assertThat(sdkCollection.getSdk(4321).isKnown()).isFalse(); }
@Test public void asFile_withUrl_succeeds() { File file = concurrency.get( GlideApp.with(context) .asFile() .load(URL) .submit()); assertThat(file).isNotNull(); }
@Test public void inflate_shouldBindPreferencesToPreferenceManager() throws Exception { final PreferenceScreen screen = inflatePreferenceActivity(); final Preference preference = screen.findPreference("preference"); assertThat(preference.getPreferenceManager().findPreference("preference")).isNotNull(); }
@Test public void asFile_withUrlAndDiskCacheStrategyData_succeeds() { File file = concurrency.get( GlideApp.with(context) .asFile() .diskCacheStrategy(DiskCacheStrategy.DATA) .load(URL) .submit()); assertThat(file).isNotNull(); }