当前位置: 首页>>代码示例>>Java>>正文


Java Shadows类代码示例

本文整理汇总了Java中org.robolectric.Shadows的典型用法代码示例。如果您正苦于以下问题:Java Shadows类的具体用法?Java Shadows怎么用?Java Shadows使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Shadows类属于org.robolectric包,在下文中一共展示了Shadows类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDoesNotRecycleChildResourceSynchronously

import org.robolectric.Shadows; //导入依赖的package包/类
@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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ResourceRecyclerTest.java

示例2: testCumulativePoolAndMemoryCacheSizesAreSmallerOnLowMemoryDevices

import org.robolectric.Shadows; //导入依赖的package包/类
@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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:MemorySizeCalculatorTest.java

示例3: checkBroadcastResponse

import org.robolectric.Shadows; //导入依赖的package包/类
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);
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:22,代码来源:QueryResponseSenderTest.java

示例4: 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

示例5: 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,项目名称:droidconde-2016,代码行数:18,代码来源:IntentsTest.java

示例6: 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,项目名称:droidconde-2016,代码行数:18,代码来源:IntentsTest.java

示例7: service

import org.robolectric.Shadows; //导入依赖的package包/类
@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);
}
 
开发者ID:barracksiot,项目名称:android-client,代码行数:20,代码来源:UpdateCheckHelperTest.java

示例8: service

import org.robolectric.Shadows; //导入依赖的package包/类
@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);
}
 
开发者ID:barracksiot,项目名称:android-client,代码行数:17,代码来源:PackageDownloadHelperTest.java

示例9: 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

示例10: createsOperationInsertProject

import org.robolectric.Shadows; //导入依赖的package包/类
@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()));
}
 
开发者ID:scarrupt,项目名称:Capstone-Project,代码行数:24,代码来源:ProjectDataHandlerTest.java

示例11: createsOperationDeleteRemovedComment

import org.robolectric.Shadows; //导入依赖的package包/类
@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(CONTENT_URI));
    final ShadowContentProviderOperation shadowOperation = Shadows.shadowOf(operation);
    assertThat(shadowOperation.getType(), equalTo(TYPE_DELETE));
}
 
开发者ID:scarrupt,项目名称:Capstone-Project,代码行数:23,代码来源:CommentDataHandlerTest.java

示例12: createsOperationDeleteRemovedIssue

import org.robolectric.Shadows; //导入依赖的package包/类
@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));
}
 
开发者ID:scarrupt,项目名称:Capstone-Project,代码行数:23,代码来源:IssueDataHandlerTest.java

示例13: createsOperationDeleteRemoveUser

import org.robolectric.Shadows; //导入依赖的package包/类
@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));
}
 
开发者ID:scarrupt,项目名称:Capstone-Project,代码行数:24,代码来源:UserDataHandlerTest.java

示例14: 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

示例15: 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


注:本文中的org.robolectric.Shadows类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。