當前位置: 首頁>>代碼示例>>Java>>正文


Java Shadows.shadowOf方法代碼示例

本文整理匯總了Java中org.robolectric.Shadows.shadowOf方法的典型用法代碼示例。如果您正苦於以下問題:Java Shadows.shadowOf方法的具體用法?Java Shadows.shadowOf怎麽用?Java Shadows.shadowOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.robolectric.Shadows的用法示例。


在下文中一共展示了Shadows.shadowOf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: should_return_false_when_nothing_on_the_device_can_open_the_uri

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void should_return_false_when_nothing_on_the_device_can_open_the_uri() {
    // Given
    String url = "http://www.google.com";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), (ResolveInfo) null);

    // When
    boolean result = Intents.startUri(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(result).isFalse();
    assertThat(startedIntent).isNull();
}
 
開發者ID:Nilhcem,項目名稱:droidcongr-2016,代碼行數:18,代碼來源:IntentsTest.java

示例2: should_start_url_intent

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void should_start_url_intent() {
    // Given
    String url = "geo:22.5430883,114.1043205";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), ShadowResolveInfo.newResolveInfo("", "", ""));

    // When
    boolean result = Intents.startUri(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(result).isTrue();
    assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(startedIntent.getData().toString()).isEqualTo(url);
}
 
開發者ID:Nilhcem,項目名稱:droidconde-2016,代碼行數:19,代碼來源:IntentsTest.java

示例3: should_start_external_uri

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void should_start_external_uri() {
    // Given
    String url = "http://www.google.com";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), ShadowResolveInfo.newResolveInfo("", "", ""));

    // When
    Intents.startExternalUrl(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(startedIntent.getData().toString()).isEqualTo(url);
}
 
開發者ID:Nilhcem,項目名稱:devfestnantes-2016,代碼行數:18,代碼來源:IntentsTest.java

示例4: createsOperationDeleteRemovedProject

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void createsOperationDeleteRemovedProject() {
    final ProjectDataHandler projectDataHandler = new ProjectDataHandler(mContext) {
        @Override
        protected Cursor query() {
            final Cursor cursor = mock(Cursor.class);
            when(cursor.getCount()).thenReturn(1);
            when(cursor.moveToFirst()).thenReturn(true);
            when(cursor.getString(eq(COL_PROJECT_KEY))).thenReturn("removedId");
            return cursor;
        }
    };

    final ArrayList<ContentProviderOperation> operations = projectDataHandler.makeContentProviderOperations(new ArrayList<ProjectDto>());

    final ContentProviderOperation operation = operations.get(0);

    assertThat(operation.getUri(), equalTo(CONTENT_URI));
    final ShadowContentProviderOperation shadowOperation = Shadows.shadowOf(operation);
    assertThat(shadowOperation.getType(), equalTo(TYPE_DELETE));
}
 
開發者ID:scarrupt,項目名稱:Capstone-Project,代碼行數:22,代碼來源:ProjectDataHandlerTest.java

示例5: createsOperationInsertUser

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void createsOperationInsertUser() {
    final List<UserDto> users = new ArrayList<>();
    final UserDto userDto = new UserDto();
    userDto.setId(1L);
    userDto.setUserId("admin");
    userDto.setName("admin");
    users.add(userDto);

    final ArrayList<ContentProviderOperation> operations = new UserDataHandler(mContext)
            .makeContentProviderOperations(users);

    final ContentProviderOperation operation = operations.get(0);
    assertThat(operation.getUri(), equalTo(UserEntry.CONTENT_URI));

    final ShadowContentProviderOperation shadowOperation = Shadows.shadowOf(operation);
    assertThat(shadowOperation.getType(), equalTo(TYPE_INSERT));

    final ContentValues contentValues = shadowOperation.getContentValues();
    assertThat(contentValues.getAsLong(UserEntry._ID), equalTo(userDto.getId()));
    assertThat(contentValues.getAsString(UserEntry.USER_ID), equalTo(userDto.getUserId()));
    assertThat(contentValues.getAsString(UserEntry.NAME), equalTo(userDto.getName()));
}
 
開發者ID:scarrupt,項目名稱:Capstone-Project,代碼行數:24,代碼來源:UserDataHandlerTest.java

示例6: createsOperationInsertIssueType

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void createsOperationInsertIssueType() {
    final Set<IssueTypeDto> issueTypes = new HashSet<>();
    final IssueTypeDto issueTypeDto = new IssueTypeDto();
    issueTypeDto.setId(ISSUE_TYPE_ID);
    issueTypeDto.setProjectId(PROJECT_ID);
    issueTypeDto.setName("Bug");
    issueTypeDto.setColor("#990000");
    issueTypes.add(issueTypeDto);

    final ArrayList<ContentProviderOperation> operations = new IssueTypeDataHandler()
            .makeContentProviderOperations(issueTypes);

    final ContentProviderOperation operation = operations.get(INDEX_TYPE_INSERT);
    assertThat(operation.getUri(), equalTo(IssueTypeEntry.buildIssueTypeFromProjectIdUri(PROJECT_ID)));

    final ShadowContentProviderOperation shadowOperation = Shadows.shadowOf(operation);
    assertThat(shadowOperation.getType(), equalTo(TYPE_INSERT));

    final ContentValues contentValues = shadowOperation.getContentValues();
    assertThat(contentValues.getAsLong(IssueTypeEntry._ID), equalTo(issueTypeDto.getId()));
    assertThat(contentValues.getAsLong(IssueTypeEntry.PROJECT_ID), equalTo(issueTypeDto.getProjectId()));
    assertThat(contentValues.getAsString(IssueTypeEntry.NAME), equalTo(issueTypeDto.getName()));
    assertThat(contentValues.getAsString(IssueTypeEntry.COLOR), equalTo(issueTypeDto.getColor()));
}
 
開發者ID:scarrupt,項目名稱:Capstone-Project,代碼行數:26,代碼來源:IssueTypeDataHandlerTest.java

示例7: whenANotificationIsSentThenTheTheNotificationIncludesTheStoreName

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void whenANotificationIsSentThenTheTheNotificationIncludesTheStoreName() {
    ShadowApplication shadowApplication = (ShadowApplication) Shadows.shadowOf(RuntimeEnvironment.application);

    insertStoreLocation(shadowApplication);

    ShadowLocation.setDistanceBetween(new float[]{(float) GroceryReminderConstants.LOCATION_GEOFENCE_RADIUS_METERS});

    long currentTime = System.currentTimeMillis();
    groceryStoreNotificationManager.sendPotentialNotification(new Location(LocationManager.GPS_PROVIDER), currentTime);

    ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();
    Notification notification = shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT);
    ShadowNotification shadowNotification = (ShadowNotification)Shadows.shadowOf(notification);
    assertTrue(((String) shadowNotification.getContentTitle()).contains(ARBITRARY_STORE_NAME));
}
 
開發者ID:jameskbride,項目名稱:grocery-reminder,代碼行數:17,代碼來源:GroceryStoreNotificationManagerTest.java

示例8: should_start_email_intent

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void should_start_email_intent() {
    // Given
    String title = "Sending email...";
    String recipient = "[email protected]";
    String subject = "Hello!";

    // When
    IntentUtils.startEmailIntent(activity, title, recipient, subject);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent intent = shadowActivity.getNextStartedActivity();
    Intent mailExtra = intent.getParcelableExtra(Intent.EXTRA_INTENT);

    assertThat(intent.getStringExtra(Intent.EXTRA_TITLE)).isEqualTo(title);
    assertThat(mailExtra.getData().getScheme()).isEqualTo("mailto");
    assertThat(mailExtra.getStringExtra(Intent.EXTRA_SUBJECT)).isEqualTo(subject);
    assertThat(mailExtra.getData().getSchemeSpecificPart()).isEqualTo(recipient);
}
 
開發者ID:Nilhcem,項目名稱:bblfr-android,代碼行數:21,代碼來源:IntentUtilsTest.java

示例9: givenAStoreIsBoundWhenTheStoreViewHolderIsClickedThenTheMapApplicationIsLaunched

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void givenAStoreIsBoundWhenTheStoreViewHolderIsClickedThenTheMapApplicationIsLaunched() {
    RecyclerView recyclerView = getRecyclerView();
    Context context = recyclerView.getContext();
    View view = LayoutInflater.from(context).inflate(R.layout.store_viewholder, recyclerView, false);
    double latitude = 0.0;
    double longitude = 1.0;
    GroceryStore store = new GroceryStore(ARBITRARY_STORE_NAME, 2414.02, latitude, longitude);

    GroceryStoreListViewHolder viewHolder = new GroceryStoreListViewHolder(view);
    viewHolder.bind(store);

    viewHolder.onClick(view);

    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    ShadowIntent shadowIntent = Shadows.shadowOf(shadowActivity.peekNextStartedActivity());
    assertTrue(shadowIntent.getData().toString().contains("geo:" + latitude + "," + longitude));
}
 
開發者ID:jameskbride,項目名稱:grocery-reminder,代碼行數:19,代碼來源:GroceryStoreListViewHolderTest.java

示例10: testContextMenu1

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void testContextMenu1() {
    adapter.updateDataSet(contacts);
    RecyclerView.ViewHolder viewHolder = adapter.onCreateViewHolder(recyclerView, 0);
    adapter.onBindViewHolder(viewHolder, 0);
    try {
        viewHolder.itemView.performLongClick(); // Danke Robolectric. NullPointer weil irgendwas mit Menu buggy..
    } catch (NullPointerException e) {
        //Nichts tun.
    }

    RoboMenuItem item = new RoboMenuItem(R.id.context_tab_show_in_contacts);
    item.setGroupId(R.id.context_tab_contact_group);
    fragment.onContextItemSelected(item);
    ShadowActivity a = Shadows.shadowOf(activity);
    Intent i  = a.getNextStartedActivityForResult().intent;
    assertNotNull(i);

}
 
開發者ID:weichweich,項目名稱:AluShare,代碼行數:20,代碼來源:ContactTabFragmentTest.java

示例11: testsignUp

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public  void testsignUp(){
    activity.signUp(null);
    Intent startedIntent = Shadows.shadowOf(activity).getNextStartedActivity();
    ShadowIntent shadowIntent = Shadows.shadowOf(startedIntent);
    Assert.assertEquals("register user has not been launched",RegisterUser.class, shadowIntent.getIntentClass());
}
 
開發者ID:Welloculus,項目名稱:MobileAppForPatient,代碼行數:8,代碼來源:LoginActivityTest.java

示例12: setDisplayDimens

import org.robolectric.Shadows; //導入方法依賴的package包/類
private void setDisplayDimens(Integer width, Integer height) {
  WindowManager windowManager =
      (WindowManager) RuntimeEnvironment.application.getSystemService(Context.WINDOW_SERVICE);
  ShadowDisplay shadowDisplay =
      Shadows.shadowOf(Preconditions.checkNotNull(windowManager).getDefaultDisplay());
  if (width != null) {
    shadowDisplay.setWidth(width);
  }

  if (height != null) {
    shadowDisplay.setHeight(height);
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:ViewTargetTest.java

示例13: testReleasesResourceIfCancelledOnReady

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void testReleasesResourceIfCancelledOnReady() {
  ShadowLooper shadowLooper = Shadows.shadowOf(harness.mainHandler.getLooper());
  shadowLooper.pause();

  EngineJob<Object> job = harness.getJob();
  job.start(harness.decodeJob);
  job.onResourceReady(harness.resource, harness.dataSource);
  job.cancel();
  shadowLooper.runOneTask();

  verify(harness.resource).recycle();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:EngineJobTest.java

示例14: testExtractMimeNativelySupportedFileExtension

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void testExtractMimeNativelySupportedFileExtension() {
  ShadowMimeTypeMap mimeTypeMap = Shadows.shadowOf(MimeTypeMap.getSingleton());
  mimeTypeMap.addExtensionMimeTypMapping("jpg", "image/jpg");

  String path = "file/with/natively/supported/extension.jpg";
  assertThat(MediaUtils.extractMime(path)).isEqualTo("image/jpg");
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:MediaUtilsTest.java

示例15: onViewClickTest

import org.robolectric.Shadows; //導入方法依賴的package包/類
@Test
public void onViewClickTest() {
    onPostViewClickListener.onViewClick(viewMock, post);

    final ShadowActivity shadowActivity = Shadows.shadowOf(postsActivity);
    final Intent intent = shadowActivity.peekNextStartedActivityForResult().intent;
    assertThat(intent.getComponent()).isEqualTo(new ComponentName(postsActivity, PostActivity.class));
    assertThat(intent.getExtras().getInt(Post.USER_ID)).isEqualTo(getExtras(post).getInt(Post.USER_ID));
    assertThat(intent.getExtras().getInt(Post.ID)).isEqualTo(getExtras(post).getInt(Post.ID));
    assertThat(intent.getExtras().getInt(Post.TITLE)).isEqualTo(getExtras(post).getInt(Post.TITLE));
    assertThat(intent.getExtras().getInt(Post.BODY)).isEqualTo(getExtras(post).getInt(Post.BODY));
}
 
開發者ID:ParaskP7,項目名稱:sample-code-posts,代碼行數:13,代碼來源:OnPostViewClickListenerTest.java


注:本文中的org.robolectric.Shadows.shadowOf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。