### Question:
FileProvider extends ContentProvider { @Override public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) { final File file = mStrategy.getFileForUri(uri); if (projection == null) { projection = COLUMNS; } String[] cols = new String[projection.length]; Object[] values = new Object[projection.length]; int i = 0; for (String col : projection) { if (OpenableColumns.DISPLAY_NAME.equals(col)) { cols[i] = OpenableColumns.DISPLAY_NAME; values[i++] = file.getName(); } else if (OpenableColumns.SIZE.equals(col)) { cols[i] = OpenableColumns.SIZE; values[i++] = file.length(); } } cols = copyOf(cols, i); values = copyOf(values, i); final MatrixCursor cursor = new MatrixCursor(cols, 1); cursor.addRow(values); return cursor; }  @Override boolean onCreate(); @Override void attachInfo(@NonNull Context context, @NonNull ProviderInfo info); static Uri getUriForFile(@NonNull Context context, @NonNull String authority,
            @NonNull File file); @Override Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection,
            @Nullable String[] selectionArgs,
            @Nullable String sortOrder); @Override String getType(@NonNull Uri uri); @Override Uri insert(@NonNull Uri uri, ContentValues values); @Override int update(@NonNull Uri uri, ContentValues values, @Nullable String selection,
            @Nullable String[] selectionArgs); @Override int delete(@NonNull Uri uri, @Nullable String selection,
            @Nullable String[] selectionArgs); @Override ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode);  }### Answer:
@Test public void testQueryProjectionNull() throws Exception { final File file = new File(mContext.getFilesDir(), TEST_FILE); final Uri uri = stageFileAndGetUri(file, TEST_DATA); Cursor cursor = mResolver.query(uri, null, null, null, null); try { assertEquals(1, cursor.getCount()); cursor.moveToFirst(); assertEquals(TEST_FILE, cursor.getString(cursor.getColumnIndex(DISPLAY_NAME))); assertEquals(TEST_DATA.length, cursor.getLong(cursor.getColumnIndex(SIZE))); } finally { cursor.close(); } }
@Test public void testQueryProjectionOrder() throws Exception { final File file = new File(mContext.getFilesDir(), TEST_FILE); final Uri uri = stageFileAndGetUri(file, TEST_DATA); Cursor cursor = mResolver.query(uri, new String[] { SIZE, DISPLAY_NAME }, null, null, null); try { assertEquals(1, cursor.getCount()); cursor.moveToFirst(); assertEquals(TEST_DATA.length, cursor.getLong(0)); assertEquals(TEST_FILE, cursor.getString(1)); } finally { cursor.close(); } cursor = mResolver.query(uri, new String[] { DISPLAY_NAME, SIZE }, null, null, null); try { assertEquals(1, cursor.getCount()); cursor.moveToFirst(); assertEquals(TEST_FILE, cursor.getString(0)); assertEquals(TEST_DATA.length, cursor.getLong(1)); } finally { cursor.close(); } }
@Test public void testQueryExtraColumn() throws Exception { final File file = new File(mContext.getFilesDir(), TEST_FILE); final Uri uri = stageFileAndGetUri(file, TEST_DATA); Cursor cursor = mResolver.query(uri, new String[] { SIZE, "foobar", DISPLAY_NAME }, null, null, null); try { assertEquals(1, cursor.getCount()); cursor.moveToFirst(); assertEquals(TEST_DATA.length, cursor.getLong(0)); assertEquals(TEST_FILE, cursor.getString(1)); } finally { cursor.close(); } }