本文整理汇总了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();
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例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()));
}
示例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));
}
示例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));
}
示例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));
}
示例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()));
}
示例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()));
}