微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.robolectric.Shadows的实例源码

项目:GitHub    文件ResourceRecyclerTest.java   
@Test
public void testDoesNotRecycleChildResourceSynchronously() {
  Resource<?> parent = mockResource();
  final Resource<?> child = mockResource();
  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      recycler.recycle(child);
      return null;
    }
  }).when(parent).recycle();

  Shadows.shadowOf(Looper.getMainLooper()).pause();

  recycler.recycle(parent);

  verify(parent).recycle();
  verify(child,never()).recycle();

  Shadows.shadowOf(Looper.getMainLooper()).runOneTask();

  verify(child).recycle();
}
项目:GitHub    文件MemorySizeCalculatorTest.java   
@Test
public void testCumulativePoolAndMemoryCacheSizesAreSmallerOnLowMemoryDevices() {
  Shadows.shadowOf(harness.activityManager).setMemoryClass(getLargeEnoughMemoryClass() / 2);
  final int normalMemoryCacheSize = harness.getCalculator().getMemoryCacheSize();
  final int normalBitmapPoolSize = harness.getCalculator().getBitmapPoolSize();

  Util.setSdkVersionInt(10);

  // Keep the bitmap pool size constant,even though normally it would change.
  harness.bytearraypoolsizeBytes *= 2;
  final int smallMemoryCacheSize = harness.getCalculator().getMemoryCacheSize();
  final int smallBitmapPoolSize = harness.getCalculator().getBitmapPoolSize();

  assertthat(smallMemoryCacheSize).isLessthan(normalMemoryCacheSize);
  assertthat(smallBitmapPoolSize).isLessthan(normalBitmapPoolSize);
}
项目:OpenYOLO-Android    文件QueryResponseSenderTest.java   
private void checkbroadcastResponse(ByteString expectedResponseBytes)
        throws InvalidProtocolBufferException {
    List<Intent> broadcasts =
            Shadows.shadowOf(RuntimeEnvironment.application).getbroadcastIntents();

    assertthat(broadcasts.size()).isEqualTo(1);
    Intent broadcastIntent = broadcasts.get(0);

    assertthat(broadcastIntent.getAction())
            .isEqualTo("example:0000000000000080");
    assertthat(broadcastIntent.getCategories()).containsExactly(QueryUtil.BBQ_CATEGORY);
    assertthat(broadcastIntent.getPackage()).isEqualTo(mQuery.getRequestingApp());
    assertthat(broadcastIntent.getByteArrayExtra(QueryUtil.EXTRA_RESPONSE_MESSAGE)).isNotNull();

    byte[] responseBytes = broadcastIntent.getByteArrayExtra(QueryUtil.EXTRA_RESPONSE_MESSAGE);
    broadcastQueryResponse response = broadcastQueryResponse.parseFrom(responseBytes);

    assertthat(response.getRequestId()).isEqualTo(mQuery.getRequestId());
    assertthat(response.getResponseId()).isEqualTo(mQuery.getResponseId());
    assertthat(response.getResponseMessage()).isEqualTo(expectedResponseBytes);
}
项目:droidconde-2016    文件IntentsTest.java   
@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);
}
项目:droidconde-2016    文件IntentsTest.java   
@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,(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();
}
项目:droidconde-2016    文件IntentsTest.java   
@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,""));

    // 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);
}
项目:devfestnantes-2016    文件IntentsTest.java   
@Test
public void should_start_url_intent() {
    // Given
    String url = "geo:22.5430883,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);
}
项目:devfestnantes-2016    文件IntentsTest.java   
@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,url);

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

    assertthat(result).isFalse();
    assertthat(startedIntent).isNull();
}
项目:devfestnantes-2016    文件IntentsTest.java   
@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,url);

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

    assertthat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertthat(startedIntent.getData().toString()).isEqualTo(url);
}
项目:mobilization-2016    文件IntentsTest.java   
@Test
public void should_start_url_intent() {
    // Given
    String url = "geo:22.5430883,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);
}
项目:mobilization-2016    文件IntentsTest.java   
@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,url);

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

    assertthat(result).isFalse();
    assertthat(startedIntent).isNull();
}
项目:mobilization-2016    文件IntentsTest.java   
@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,url);

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

    assertthat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertthat(startedIntent.getData().toString()).isEqualTo(url);
}
项目:droidconat-2016    文件IntentsTest.java   
@Test
public void should_start_url_intent() {
    // Given
    String url = "geo:22.5430883,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);
}
项目:droidconat-2016    文件IntentsTest.java   
@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,url);

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

    assertthat(result).isFalse();
    assertthat(startedIntent).isNull();
}
项目:droidconat-2016    文件IntentsTest.java   
@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,url);

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

    assertthat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertthat(startedIntent.getData().toString()).isEqualTo(url);
}
项目:android-client    文件UpdateCheckHelperTest.java   
@Test
public void service() {
    UpdateDetailsRequest request = new UpdateDetailsRequest.Builder()
            .unitId("HAL")
            .versionId("42")
            .build();
    TestCallback callback = new TestCallback();
    UpdateCheckHelper helper = new UpdateCheckHelper("deadbeef");
    helper.bind(RuntimeEnvironment.application,callback);
    helper.requestUpdate(request);
    Intent intent = Shadows.shadowOf(RuntimeEnvironment.application).getNextStartedService();
    Assert.assertNotNull(intent);
    Assert.assertEquals(intent.getComponent().getClassName(),UpdateCheckService.class.getName());
    Assert.assertEquals(intent.getAction(),UpdateCheckService.ACTION_CHECK);
    Assert.assertEquals(callback.hashCode(),intent.getIntExtra(UpdateCheckService.EXTRA_CALLBACK,0));
    UpdateDetailsRequest request2 = intent.getParcelableExtra(UpdateCheckService.EXTRA_REQUEST);
    Assert.assertNotNull(request2);
    helper.unbind(RuntimeEnvironment.application);
}
项目:android-client    文件PackageDownloadHelperTest.java   
@Test
public void service() throws FileNotFoundException {
    UpdateDetails response = Utils.getUpdateDetailsFromFile("download_success.json");
    TestCallback callback = new TestCallback();
    PackageDownloadHelper helper = new PackageDownloadHelper("deadbeef");
    helper.bind(RuntimeEnvironment.application,callback);
    helper.requestDownload(response);
    Intent intent = Shadows.shadowOf(RuntimeEnvironment.application).getNextStartedService();
    Assert.assertNotNull(intent);
    Assert.assertEquals(intent.getComponent().getClassName(),PackageDownloadService.class.getName());
    Assert.assertEquals(intent.getAction(),PackageDownloadService.ACTION_DOWNLOAD_PACKAGE);
    Assert.assertEquals(callback.hashCode(),intent.getIntExtra(PackageDownloadService.EXTRA_CALLBACK,0));
    UpdateDetails response2 = intent.getParcelableExtra(PackageDownloadService.EXTRA_UPDATE_DETAILS);
    Assert.assertNotNull(response2);
    helper.unbind(RuntimeEnvironment.application);
}
项目:Capstone-Project    文件ProjectDataHandlerTest.java   
@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));
}
项目:Capstone-Project    文件ProjectDataHandlerTest.java   
@Test
public void createsOperationInsertProject() {
    final List<ProjectDto> projects = new ArrayList<>();
    final ProjectDto projectDto = new ProjectDto();
    projectDto.setId(1L);
    projectDto.setProjectKey("TEST");
    projectDto.setName("Test project");
    projects.add(projectDto);

    final ArrayList<ContentProviderOperation> operations = new ProjectDataHandler(mContext)
            .makeContentProviderOperations(projects);

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

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

    final ContentValues contentValues = shadowOperation.getContentValues();
    assertthat(contentValues.getAsLong(ProjectEntry._ID),equalTo(projectDto.getId()));
    assertthat(contentValues.getAsstring(ProjectEntry.PROJECT_KEY),equalTo(projectDto.getProjectKey()));
    assertthat(contentValues.getAsstring(ProjectEntry.NAME),equalTo(projectDto.getName()));
}
项目:Capstone-Project    文件CommentDataHandlerTest.java   
@Test
public void createsOperationDeleteRemovedComment() {
    final CommentDataHandler commentDataHandler = new CommentDataHandler(mContext) {
        @Override
        protected Cursor query() {
            final Cursor cursor = mock(Cursor.class);
            when(cursor.getCount()).thenReturn(1);
            when(cursor.movetoFirst()).thenReturn(true);
            when(cursor.getLong(eq(COL_ID))).thenReturn(1L);
            return cursor;
        }
    };

    final ArrayList<ContentProviderOperation> operations = commentDataHandler
            .makeContentProviderOperations(new ArrayList<CommentDto>());

    final ContentProviderOperation operation = operations.get(0);

    assertthat(operation.getUri(),equalTo(TYPE_DELETE));
}
项目:Capstone-Project    文件IssueDataHandlerTest.java   
@Test
public void createsOperationDeleteRemovedissue() {
    final IssueDataHandler issueDataHandler = new IssueDataHandler(mContext) {
        @Override
        protected Cursor query() {
            final Cursor cursor = mock(Cursor.class);
            when(cursor.getCount()).thenReturn(1);
            when(cursor.movetoFirst()).thenReturn(true);
            when(cursor.getLong(eq(COL_ID))).thenReturn(1L);
            return cursor;
        }
    };

    final ArrayList<ContentProviderOperation> operations = issueDataHandler
            .makeContentProviderOperations(new ArrayList<IssueDto>());

    final ContentProviderOperation operation = operations.get(0);

    assertthat(operation.getUri(),equalTo(IssueEntry.CONTENT_URI));
    final ShadowContentProviderOperation shadowOperation = Shadows.shadowOf(operation);
    assertthat(shadowOperation.getType(),equalTo(TYPE_DELETE));
}
项目:Capstone-Project    文件UserDataHandlerTest.java   
@Test
public void createsOperationDeleteRemoveUser(){

    final UserDataHandler userDataHandler = new UserDataHandler(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_USER_ID))).thenReturn("removedUserId");
            return cursor;
        }
    };

    final ArrayList<ContentProviderOperation> operations = userDataHandler
            .makeContentProviderOperations(new ArrayList<UserDto>());

    final ContentProviderOperation operation = operations.get(0);

    assertthat(operation.getUri(),equalTo(UserEntry.CONTENT_URI));
    final ShadowContentProviderOperation shadowOperation = Shadows.shadowOf(operation);
    assertthat(shadowOperation.getType(),equalTo(TYPE_DELETE));
}
项目:Capstone-Project    文件UserDataHandlerTest.java   
@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()));
}
项目:Capstone-Project    文件IssueTypeDataHandlerTest.java   
@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()));
}
项目:devoxxfr-2016    文件IntentsTest.java   
@Test
public void should_start_url_intent() {
    // Given
    String url = "geo:22.5430883,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);
}
项目:devoxxfr-2016    文件IntentsTest.java   
@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,url);

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

    assertthat(result).isFalse();
    assertthat(startedIntent).isNull();
}
项目:devoxxfr-2016    文件IntentsTest.java   
@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,url);

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

    assertthat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertthat(startedIntent.getData().toString()).isEqualTo(url);
}
项目:droidcongr-2016    文件IntentsTest.java   
@Test
public void should_start_url_intent() {
    // Given
    String url = "geo:22.5430883,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);
}
项目:droidcongr-2016    文件IntentsTest.java   
@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,url);

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

    assertthat(result).isFalse();
    assertthat(startedIntent).isNull();
}
项目:droidcongr-2016    文件IntentsTest.java   
@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,url);

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

    assertthat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertthat(startedIntent.getData().toString()).isEqualTo(url);
}
项目:BaseUtil    文件TestClient.java   
@Test
public void testActivity() {
    //加载Activity
    MainActivity activity = Robolectric.setupActivity(MainActivity.class);
    //加载控件
    TextView tv = (TextView) activity.findViewById(R.id.tv);
    Button bt = (Button) activity.findViewById(R.id.bt);
    //执行点击
    bt.performClick();
    //判断TextView是否改变
    String text = tv.getText().toString();
    LogUtil.print("tv.text=" + text);
    assertthat(text).isEqualTo("我要变");
    //判断Activity是否跳转
    Intent actualIntent = Shadows.shadowOf(activity).getNextStartedActivity();
    Intent expectedIntent = new Intent();
    expectedIntent.setAction(IntentAction.ACTIVITY_SECOND);
    LogUtil.print("actualIntent.action=" + actualIntent.getAction());
    assertthat(expectedIntent.getAction()).isEqualTo(actualIntent.getAction());
}
项目:droidcontn-2016    文件IntentsTest.java   
@Test
public void should_start_url_intent() {
    // Given
    String url = "geo:22.5430883,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);
}
项目:droidcontn-2016    文件IntentsTest.java   
@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,url);

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

    assertthat(result).isFalse();
    assertthat(startedIntent).isNull();
}
项目:droidcontn-2016    文件IntentsTest.java   
@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,url);

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

    assertthat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertthat(startedIntent.getData().toString()).isEqualTo(url);
}
项目:stack-overflow-android    文件SimpleTest.java   
@Test
public void shouldStartNextActivity() {
    // given
    List<Questionlistadapter.QuestionAdapterData> questions =
            Lists.newArrayList(
                    new Questionlistadapter.QuestionAdapterData().setTitle("Topic 1").setLink("http://top1"),new Questionlistadapter.QuestionAdapterData().setTitle("Topic 2").setLink("http://top2")
            );

    list.setAdapter(new Questionlistadapter(activity,questions));

    // when
    int index = 1;
    Shadows.shadowOf(list).performItemClick(index);

    // then
    Intent expectedIntent = new Intent(activity,DetailsActivity.class);
    expectedIntent.putExtra(DetailsActivity.EXTRA_URL,questions.get(index).getLink());
    assertthat(Shadows.shadowOf(activity).getNextStartedActivity()).isEqualTo(expectedIntent);
}
项目:goro    文件BaseBindingGoroTest.java   
@Before
public void init() {
  context = Robolectric.setupActivity(Activity.class);
  shadowContext = Shadows.shadowOf(context);

  testingQueues = new TestingQueues();
  serviceInstance = spy(new Goro.GoroImpl(testingQueues));

  serviceCompName = new ComponentName(context,GoroService.class);
  GoroService service = new GoroService();
  binder = new GoroService.GoroBinderImpl(serviceInstance,service.new GoroTasksListener());
  ShadowApplication.getInstance()
      .setComponentNameAndServiceForBindService(
          serviceCompName,binder
      );
  reset(serviceInstance);
}
项目:bblfr-android    文件CitiesFallbackActivityTest.java   
@Test
public void should_start_baggers_list_activity_when_city_is_selected() {
    // Given
    City city = new City();
    city.name = "Paris";
    city.lat = 42d;
    city.lng = 1d;

    // When
    activity.onCitySelected(city);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent intent = shadowActivity.getNextStartedActivity();
    assertthat(intent.getComponent().getClassName()).isEqualTo(BaggersListActivity.class.getName());
    assertthat(((City) intent.getParcelableExtra("mCity")).name).isEqualTo("Paris");
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。