Java Code Examples for org.robolectric.Robolectric#shadowOf()

The following examples show how to use org.robolectric.Robolectric#shadowOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DirectoryChooserFragmentTest.java    From droid-stealth with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testCreateDirectoryDialog() {
	final String directoryName = "mydir";
	final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance(
			directoryName, null);

	startFragment(fragment, DirectoryChooserActivityMock.class);

	fragment.onOptionsItemSelected(new TestMenuItem() {
		@Override
		public int getItemId() {
			return R.id.new_folder_item;
		}
	});

	final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog();
	final ShadowAlertDialog shadowAlertDialog = Robolectric.shadowOf(dialog);
	assertEquals(shadowAlertDialog.getTitle(), "Create folder");
	assertEquals(shadowAlertDialog.getMessage(), "Create new folder with name \"mydir\"?");
}
 
Example 2
Source File: PictureResizeDialogTest.java    From Onosendai with Apache License 2.0 6 votes vote down vote up
@Test
public void itCanBeCancelled () throws Exception {
	this.alert.show();

	assertTrue(this.shadowAlert.isCancelable());
	assertFalse(this.shadowAlert.hasBeenDismissed());

	this.alert.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
	assertTrue(this.shadowAlert.hasBeenDismissed());

	assertEquals(0, this.okClick.get());
	assertEquals(1, this.cancelClick.get());

	final ShadowActivity shadowActivity = Robolectric.shadowOf(this.activity);
	assertNull(shadowActivity.getNextStartedActivity());
}
 
Example 3
Source File: SmsRadarServiceTest.java    From SmsRadar with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRestartServiceUsingAlarmManagerWhenTaskRemoved() {
	when(mockedTimeProvider.getDate()).thenReturn(new Date(ANY_TIME));

	startSmsInterceptorService();
	smsRadarService.onTaskRemoved(ANY_INTENT);

	ArgumentCaptor<PendingIntent> pendingIntentArgumentCaptor = ArgumentCaptor.forClass(PendingIntent.class);
	verify(mockedAlarmManager).set(eq(AlarmManager.RTC_WAKEUP), eq(ANY_TIME + ONE_SECOND),
			pendingIntentArgumentCaptor.capture());
	PendingIntent capturedPendingIntent = pendingIntentArgumentCaptor.getValue();
	ShadowPendingIntent pendingIntent = Robolectric.shadowOf(capturedPendingIntent);
	ShadowIntent intent = Robolectric.shadowOf(pendingIntent.getSavedIntent());
	assertEquals(SmsRadarService.class, intent.getIntentClass());
}
 
Example 4
Source File: ActivityUtilsTest.java    From android-utilset with Apache License 2.0 5 votes vote down vote up
private RunningTaskInfo createRunningTaskInfo() {
	ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
	ShadowActivityManager shadowAm = Robolectric.shadowOf(am);
	RunningTaskInfo info = new RunningTaskInfo();
	shadowAm.setTasks(Arrays.asList(info));
	return info;
}
 
Example 5
Source File: ActivityUtilsTest.java    From android-utilset with Apache License 2.0 5 votes vote down vote up
private void createRunningAppProcessInfo(int pid) {
	ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
	ShadowActivityManager shadowAm = Robolectric.shadowOf(am);
	
	RunningAppProcessInfo proc = new RunningAppProcessInfo();
	proc.importance = RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
	proc.pid = pid;
	shadowAm.setProcesses(Arrays.asList(proc));
}
 
Example 6
Source File: BaseActivityTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void onCreate_shouldSetDataUploadServiceAlarm() throws Exception {
    Token token = new Token("yo", "yo");
    activity.setAccessToken(token);
    activity = initBaseActivityWithMenu(menu);
    AlarmManager alarmManager =
            (AlarmManager) Robolectric.application.getSystemService(Context.ALARM_SERVICE);
    ShadowAlarmManager shadowAlarmManager = Robolectric.shadowOf(alarmManager);
    assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNotNull();
}
 
Example 7
Source File: MapzenNotificationCreatorTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldCreatePersistentNotification() throws Exception {
    mnc.createNewNotification("title", "content");
    NotificationManager notificationManager = (NotificationManager)
            ACTIVITY.getSystemService(Robolectric.application.NOTIFICATION_SERVICE);
    ShadowNotificationManager shadowManager = Robolectric.shadowOf(notificationManager);
    Notification notification = shadowManager.getAllNotifications().get(0);
    assertThat(Robolectric.shadowOf(notification).isOngoing()).isTrue();
}
 
Example 8
Source File: RobolectricSampleActivityTest.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
@Test
public void WebViewで読み込んだURLのテスト() {
    Activity activity = Robolectric
            .buildActivity(RobolectricSampleActivity.class).create().get();
    WebView webView = (WebView) activity.findViewById(R.id.webview);

    ShadowWebView shadowWebView = Robolectric.shadowOf((WebView) webView);

    assertThat("http://robolectric.org/index.html",
            is(shadowWebView.getLastLoadedUrl()));
}
 
Example 9
Source File: CachedImageFileProviderTest.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
@Test
public void itAddsExtension () throws Exception {
	final ShadowMimeTypeMap shadowMimeTypeMap = Robolectric.shadowOf(MimeTypeMap.getSingleton());
	shadowMimeTypeMap.addExtensionMimeTypMapping("png", "image/png");

	final File picFile = this.tmp.newFile();
	IoHelper.copy(new File("./res/drawable-hdpi/ic_hosaka_meji.png"), picFile); // Just something to test with.
	final List<File> actual = CachedImageFileProvider.addFileExtensions(Collections.singletonList(picFile));
	assertThat(actual, hasItem(new File(picFile.getAbsolutePath() + ".png")));
}
 
Example 10
Source File: ActivityUtilsTest.java    From android-utilset with Apache License 2.0 4 votes vote down vote up
private boolean getFlag(TestActivity activity, int flagToMatch) {
	ShadowWindow window = Robolectric.shadowOf(activity.getWindow());
	return window.getFlag(flagToMatch);
}