Java 类org.robolectric.shadows.ShadowContentProviderOperation 实例源码

项目: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(CONTENT_URI));
    final ShadowContentProviderOperation shadowOperation = Shadows.shadowOf(operation);
    assertThat(shadowOperation.getType(), 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()));
}
项目:android-db-commons    文件:BatcherTest.java   
@Test
public void shouldWorkFineWithValueBackReferences() throws Exception {
  final Insert firstInsert = ProviderAction.insert(Uri.EMPTY);
  final Insert secondInsert = ProviderAction.insert(Uri.EMPTY);
  final ArrayList<ContentProviderOperation> operations = Batcher.begin()
      .append(firstInsert)
      .append(secondInsert)
      .append(ProviderAction.insert(Uri.EMPTY))
      .withValueBackReference(firstInsert, BaseColumns._ID)
      .withValueBackReference(secondInsert, "contact_id")
      .operations();

  assertThat(operations).hasSize(3);

  final ContentProviderOperation lastOperation = operations.get(2);
  ShadowContentProviderOperation shadowOperation = Robolectric.shadowOf(lastOperation);
  final ContentValues backRefs = shadowOperation.getValuesBackReferences();
  assertThat(backRefs.get("_id")).isEqualTo(0);
  assertThat(backRefs.get("contact_id")).isEqualTo(1);
}
项目:android-db-commons    文件:BatcherTest.java   
@Test
public void shouldResolveSelectionBackReferences() throws Exception {
  final Insert firstInsert = ProviderAction.insert(Uri.EMPTY);
  final Insert secondInsert = ProviderAction.insert(Uri.EMPTY);
  final ArrayList<ContentProviderOperation> operations = Batcher.begin()
      .append(firstInsert)
      .append(secondInsert)
      .append(ProviderAction.update(Uri.EMPTY).value("test", 1L).where(BaseColumns._ID + "=? AND contact_id=?"))
      .withSelectionBackReference(firstInsert, 0)
      .withSelectionBackReference(secondInsert, 1)
      .operations();

  assertThat(operations).hasSize(3);

  final ContentProviderOperation lastOperation = operations.get(2);
  ShadowContentProviderOperation shadowOperation = Robolectric.shadowOf(lastOperation);
  final Map<Integer, Integer> backRefs = shadowOperation.getSelectionArgsBackReferences();
  assertThat(backRefs).containsEntry(0, 0);
  assertThat(backRefs).containsEntry(1, 1);
}
项目:android-db-commons    文件:BatcherTest.java   
@Test
public void shouldMapToProperInsertEvenIfTheyHaveIdenticalState() throws Exception {
  final Insert first = ProviderAction.insert(createFakeUri("only"));
  final Insert second = ProviderAction.insert(createFakeUri("only"));

  final ArrayList<ContentProviderOperation> operations = Batcher.begin()
      .append(first)
      .append(second)
      .append(ProviderAction.insert(createFakeUri("only"))).withValueBackReference(first, "column")
      .operations();

  assertThat(operations).hasSize(3);
  final ShadowContentProviderOperation shadowOperation = Robolectric.shadowOf(Iterables.getLast(operations));
  final ContentValues backRefs = shadowOperation.getValuesBackReferences();
  assertThat(backRefs.get("column")).isEqualTo(0);
}
项目:android-db-commons    文件:BatcherTest.java   
@Test
public void shouldDecorateOperationsUrisIfSpecified() throws Exception {
  final ArrayList<ContentProviderOperation> operations = Batcher.begin()
      .append(ProviderAction.insert(createFakeUri("first")))
      .append(ProviderAction.update(createFakeUri("second")).value("test", 1L))
      .append(ProviderAction.delete(createFakeUri("third")))
      .decorateUrisWith(new UriDecorator() {
        @Override
        public Uri decorate(Uri uri) {
          return Uri.withAppendedPath(uri, "boom");
        }
      })
      .operations();

  assertThat(operations).hasSize(3);

  operationAssert(operations.get(0), createFakeUri("first", "boom"), ShadowContentProviderOperation.TYPE_INSERT);
  operationAssert(operations.get(1), createFakeUri("second", "boom"), ShadowContentProviderOperation.TYPE_UPDATE);
  operationAssert(operations.get(2), createFakeUri("third", "boom"), ShadowContentProviderOperation.TYPE_DELETE);
}
项目:Capstone-Project    文件:ProjectDataHandlerTest.java   
@Test
public void createsOperationUpdateProject(){

    final String existingKey = "existingKey";

    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(existingKey);
            return cursor;
        }
    };

    final ProjectDto projectDto = new ProjectDto();
    projectDto.setProjectKey(existingKey);
    projectDto.setName("updatedName");

    final ArrayList<ContentProviderOperation> operations = projectDataHandler
            .makeContentProviderOperations(Lists.newArrayList(projectDto));

    final ContentProviderOperation operation = operations.get(0);

    assertThat(operation.getUri(), equalTo(ProjectEntry.CONTENT_URI));
    final ShadowContentProviderOperation shadowOperation = Shadows.shadowOf(operation);
    assertThat(shadowOperation.getType(), equalTo(TYPE_UPDATE));
}
项目:Capstone-Project    文件:CommentDataHandlerTest.java   
@Test
public void createsOperationUpdateComment(){

    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(COMMENT_ID);
            return cursor;
        }
    };

    final CommentDto commentDto = new CommentDto();
    commentDto.setId(COMMENT_ID);
    commentDto.setCreatedUserId(USER_ID);
    commentDto.setIssueId(ISSUE_ID);
    commentDto.setContent("test");
    commentDto.setCreated("2013-08-05T06:15:06Z");
    commentDto.setUpdated("2013-08-05T06:15:06Z");

    final ArrayList<ContentProviderOperation> operations = commentDataHandler
            .makeContentProviderOperations(Lists.newArrayList(commentDto));

    final ContentProviderOperation operation = operations.get(0);

    assertThat(operation.getUri(), equalTo(BacklogContract.CommentEntry.CONTENT_URI));
    final ShadowContentProviderOperation shadowOperation = Shadows.shadowOf(operation);
    assertThat(shadowOperation.getType(), equalTo(TYPE_UPDATE));
}
项目:Capstone-Project    文件:CommentDataHandlerTest.java   
@Test
public void createsOperationInsertCommentType() {
    final List<CommentDto> comments = new ArrayList<>();
    final CommentDto commentDto = new CommentDto();
    commentDto.setId(COMMENT_ID);
    commentDto.setCreatedUserId(USER_ID);
    commentDto.setIssueId(ISSUE_ID);
    commentDto.setContent("test");
    commentDto.setCreated("2013-08-05T06:15:06Z");
    commentDto.setUpdated("2013-08-05T06:15:06Z");
    comments.add(commentDto);

    final ArrayList<ContentProviderOperation> operations = new CommentDataHandler(mContext)
            .makeContentProviderOperations(comments);

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

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

    final ContentValues contentValues = shadowOperation.getContentValues();
    assertThat(contentValues.getAsLong(BacklogContract.CommentEntry._ID), equalTo(commentDto.getId()));
    assertThat(contentValues.getAsLong(BacklogContract.CommentEntry.ISSUE_ID), equalTo(commentDto.getIssueId()));
    assertThat(contentValues.getAsLong(BacklogContract.CommentEntry.CREATED_USER_ID), equalTo(commentDto.getCreatedUserId()));
    assertThat(contentValues.getAsString(BacklogContract.CommentEntry.CONTENT), equalTo(commentDto.getContent()));
    assertThat(contentValues.getAsString(BacklogContract.CommentEntry.CREATED), equalTo(commentDto.getCreated()));
    assertThat(contentValues.getAsString(BacklogContract.CommentEntry.UPDATED), equalTo(commentDto.getUpdated()));
}
项目:Capstone-Project    文件:IssueDataHandlerTest.java   
@Test
public void createsOperationUpdateIssue(){

    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(ISSUE_ID);
            return cursor;
        }
    };

    final IssueDto issueDto = new IssueDto();
    issueDto.setId(ISSUE_ID);
    issueDto.setProjectId(1L);
    final IssueTypeDto issueTypeDto = new IssueTypeDto();
    issueTypeDto.setId(1L);
    issueDto.setIssueType(issueTypeDto);
    issueDto.setSummary("first issue");
    issueDto.setDescription("");
    issueDto.setPriority("Normal");
    issueDto.setStatus("Open");
    issueDto.setMilestones("wait for release");
    issueDto.setAssigneeId(1L);
    issueDto.setCreatedUserId(1L);
    issueDto.setCreatedDate("2012-07-23T06:10:15Z");
    issueDto.setUpdatedUserId(1L);
    issueDto.setUpdatedDate("2013-02-07T08:09:49Z");

    final ArrayList<ContentProviderOperation> operations = issueDataHandler
            .makeContentProviderOperations(Lists.newArrayList(issueDto));

    final ContentProviderOperation operation = operations.get(0);

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

    final String existingUserId = "existingUserId";

    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(existingUserId);
            return cursor;
        }
    };

    final UserDto userDto = new UserDto();
    userDto.setUserId(existingUserId);
    userDto.setName("updatedName");

    final ArrayList<ContentProviderOperation> operations = userDataHandler
            .makeContentProviderOperations(Lists.newArrayList(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_UPDATE));
}
项目:Capstone-Project    文件:IssueTypeDataHandlerTest.java   
@Test
public void createsOperationDeleteAllIssueTypesAtFirst() {
    final ArrayList<ContentProviderOperation> operations = new IssueTypeDataHandler()
            .makeContentProviderOperations(new HashSet<IssueTypeDto>());

    final ContentProviderOperation operation = operations.get(INDEX_TYPE_DELETE);

    assertThat(operation.getUri(), equalTo(IssueTypeEntry.CONTENT_URI));
    final ShadowContentProviderOperation shadowOperation = Shadows.shadowOf(operation);
    assertThat(shadowOperation.getType(), equalTo(TYPE_DELETE));
}
项目:android-db-commons    文件:BatcherTest.java   
@Test
public void shouldGenerateProperListOfContentProviderOperations() throws Exception {
  final ArrayList<ContentProviderOperation> operations = Batcher.begin()
      .append(ProviderAction.insert(createFakeUri("first")))
      .append(ProviderAction.insert(createFakeUri("second")))
      .append(ProviderAction.update(createFakeUri("third")).value("test", 1L))
      .operations();
  assertThat(operations).hasSize(3);

  operationAssert(operations.get(0), createFakeUri("first"), ShadowContentProviderOperation.TYPE_INSERT);
  operationAssert(operations.get(1), createFakeUri("second"), ShadowContentProviderOperation.TYPE_INSERT);
  operationAssert(operations.get(2), createFakeUri("third"), ShadowContentProviderOperation.TYPE_UPDATE);
}
项目:android-db-commons    文件:BatcherTest.java   
@Test
public void shouldTakeCareAboutContentValuesInBatch() throws Exception {
  ContentValues values = new ContentValues();
  values.put("test1", 1L);
  values.put("test2", "blah");

  final ArrayList<ContentProviderOperation> operations = Batcher.begin()
      .append(ProviderAction.insert(createFakeUri("first")).values(values))
      .operations();

  final ShadowContentProviderOperation contentProviderOperation = Robolectric.shadowOf(operations.get(0));
  assertThat(contentProviderOperation.getContentValues()).isEqualTo(values);
}
项目:android-db-commons    文件:ConvertToContentProviderOperationTest.java   
@Test
public void shouldConstructInsertOperation() throws Exception {
  ContentValues values = new ContentValues();
  values.put("key", "value");
  values.put("second", 2L);

  final ContentProviderOperation operation = ProviderAction.insert(createFakeUri("endpoint"))
      .values(values)
      .toContentProviderOperation(Utils.DUMMY_URI_DECORATOR);

  final ShadowContentProviderOperation shadowOperation = Robolectric.shadowOf(operation);
  assertThat(operation.getUri()).isEqualTo(createFakeUri("endpoint"));
  assertThat(shadowOperation.getType()).isEqualTo(ShadowContentProviderOperation.TYPE_INSERT);
  assertThat(shadowOperation.getContentValues()).isEqualTo(values);
}
项目:android-db-commons    文件:ConvertToContentProviderOperationTest.java   
@Test
public void shouldConstructUpdateOperation() throws Exception {
  final ContentProviderOperation operation = ProviderAction.update(createFakeUri("endpoint"))
      .value("key", "value")
      .where("key=?", "hello")
      .toContentProviderOperation(Utils.DUMMY_URI_DECORATOR);

  final ShadowContentProviderOperation shadowOperation = Robolectric.shadowOf(operation);
  assertThat(operation.getUri()).isEqualTo(createFakeUri("endpoint"));
  assertThat(shadowOperation.getType()).isEqualTo(ShadowContentProviderOperation.TYPE_UPDATE);
  assertThat(shadowOperation.getSelection()).isEqualTo("(key=?)");
  assertThat(shadowOperation.getSelectionArgs()).isEqualTo(new String[] { "hello" });
}
项目:android-db-commons    文件:ConvertToContentProviderOperationTest.java   
@Test
public void shouldConstructDeleteOperation() throws Exception {
  final ContentProviderOperation operation = ProviderAction.delete(createFakeUri("endpoint"))
      .where("key=?", "hello")
      .toContentProviderOperation(Utils.DUMMY_URI_DECORATOR);

  final ShadowContentProviderOperation shadowOperation = Robolectric.shadowOf(operation);
  assertThat(operation.getUri()).isEqualTo(createFakeUri("endpoint"));
  assertThat(shadowOperation.getType()).isEqualTo(ShadowContentProviderOperation.TYPE_DELETE);
  assertThat(shadowOperation.getSelection()).isEqualTo("(key=?)");
  assertThat(shadowOperation.getSelectionArgs()).isEqualTo(new String[] { "hello" });
}
项目:Capstone-Project    文件:IssueDataHandlerTest.java   
@Test
public void createsOperationInsertIssue() {
    final List<IssueDto> issues = new ArrayList<>();
    final IssueDto issueDto = new IssueDto();
    issueDto.setId(ISSUE_ID);
    issueDto.setProjectId(1L);
    final IssueTypeDto issueTypeDto = new IssueTypeDto();
    issueTypeDto.setId(1L);
    issueDto.setIssueType(issueTypeDto);
    issueDto.setSummary("first issue");
    issueDto.setDescription("");
    issueDto.setPriority("Normal");
    issueDto.setStatus("Open");
    issueDto.setMilestones("wait for release");
    issueDto.setAssigneeId(1L);
    issueDto.setCreatedUserId(1L);
    issueDto.setCreatedDate("2012-07-23T06:10:15Z");
    issueDto.setUpdatedUserId(1L);
    issueDto.setUpdatedDate("2013-02-07T08:09:49Z");
    issues.add(issueDto);

    final ArrayList<ContentProviderOperation> operations = new IssueDataHandler(mContext)
            .makeContentProviderOperations(issues);

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

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

    final ContentValues contentValues = shadowOperation.getContentValues();
    assertThat(contentValues.getAsLong(IssueEntry._ID), equalTo(issueDto.getId()));
    assertThat(contentValues.getAsLong(IssueEntry.PROJECT_ID), equalTo(issueDto.getProjectId()));
    assertThat(contentValues.getAsLong(IssueEntry.TYPE_ID), equalTo(issueDto.getIssueType().getId()));
    assertThat(contentValues.getAsString(IssueEntry.SUMMARY), equalTo(issueDto.getSummary()));
    assertThat(contentValues.getAsString(IssueEntry.DESCRIPTION), equalTo(issueDto.getDescription()));
    assertThat(contentValues.getAsString(IssueEntry.PRIORITY), equalTo(issueDto.getPriority()));
    assertThat(contentValues.getAsString(IssueEntry.STATUS), equalTo(issueDto.getStatus()));
    assertThat(contentValues.getAsString(IssueEntry.MILESTONES), equalTo(issueDto.getMilestones()));
    assertThat(contentValues.getAsLong(IssueEntry.ASSIGNEE_ID), equalTo(issueDto.getAssigneeId()));
    assertThat(contentValues.getAsLong(IssueEntry.CREATED_USER_ID), equalTo(issueDto.getCreatedUserId()));
    assertThat(contentValues.getAsString(IssueEntry.CREATED_DATE), equalTo(issueDto.getCreatedDate()));
    assertThat(contentValues.getAsLong(IssueEntry.UPDATED_USER_ID), equalTo(issueDto.getUpdatedUserId()));
    assertThat(contentValues.getAsString(IssueEntry.UPDATED_DATE), equalTo(issueDto.getUpdatedDate()));
}
项目:FullRobolectricTestSample    文件:Robolectric.java   
public static ShadowContentProviderOperation shadowOf(ContentProviderOperation instance) {
  return (ShadowContentProviderOperation) shadowOf_(instance);
}
项目:android-db-commons    文件:BatcherTest.java   
private static void operationAssert(ContentProviderOperation operation, Uri uri, int type) {
  final ShadowContentProviderOperation shadowOperation = Robolectric.shadowOf(operation);
  assertThat(operation.getUri()).isEqualTo(uri);
  assertThat(shadowOperation.getType()).isEqualTo(type);
}
项目:HoebApp    文件:SoapLibraryServiceTest.java   
@Test
public void shouldRefreshMediaListWithTwoAccounts() throws Exception {
    // given
    TestUtils.setUserdata(context, new Account("username1", "password1"),
            new Account("user2name", "password2"));

    // when
    libraryService.refreshMediaList(context);

    // then
    @SuppressWarnings("unchecked")
    final ArgumentCaptor<ArrayList<ContentProviderOperation>> capturer = (ArgumentCaptor<ArrayList<ContentProviderOperation>>) (Object) ArgumentCaptor
            .forClass(ArrayList.class);
    verify(contentResolver).applyBatch(eq(MediaContentProvider.AUTHORITY),
            capturer.capture());
    final ArrayList<ContentProviderOperation> operations = capturer
            .getValue();

    assertThat("1 delete, 11 inserts (account1), 19 inserts (account2)",
            operations.size(), is(31));
    ContentProviderOperation operation = operations.get(0);
    final ShadowContentProviderOperation deleteOperation = Robolectric
            .shadowOf(operation);
    assertThat("delete old", deleteOperation.getType() == TYPE_DELETE, is(true));
    assertThat("delete old", operation.getUri(),
            is(equalTo(MediaContentProvider.CONTENT_URI)));

    for (int i = 1; i < 12; i++) {
        ContentProviderOperation operationI = operations.get(i);
        final ShadowContentProviderOperation insertOperation = Robolectric
                .shadowOf(operationI);
        assertThat("insert " + i, insertOperation.getType() == TYPE_INSERT, is(true));
        assertThat("insert " + i, operationI.getUri(),
                is(equalTo(MediaContentProvider.CONTENT_URI)));
        assertThat(
                "insert " + i,
                (String) insertOperation.getContentValues().get(
                        MediaDbHelper.COLUMN_ACCOUNT),
                is(equalTo("username1"))
        );
    }
}