### Question:
AppMetadataBackupWriter { public void backupObb(@UserIdInt int userId, PackageInfo packageInfo) { Environment.UserEnvironment userEnv = new Environment.UserEnvironment(userId); File obbDir = userEnv.buildExternalStorageAppObbDirs(packageInfo.packageName)[0]; if (obbDir != null) { if (MORE_DEBUG) { Log.i(TAG, "obb dir: " + obbDir.getAbsolutePath()); } File[] obbFiles = obbDir.listFiles(); if (obbFiles != null) { String obbDirName = obbDir.getAbsolutePath(); for (File obb : obbFiles) { FullBackup.backupToTar( packageInfo.packageName, FullBackup.OBB_TREE_TOKEN, null, obbDirName, obb.getAbsolutePath(), mOutput); } } } } AppMetadataBackupWriter(FullBackupDataOutput output, PackageManager packageManager); void backupManifest(
            PackageInfo packageInfo, File manifestFile, File filesDir, boolean withApk); void backupManifest(
            PackageInfo packageInfo,
            File manifestFile,
            File filesDir,
            @Nullable String domain,
            @Nullable String linkDomain,
            boolean withApk); void backupWidget(
            PackageInfo packageInfo, File metadataFile, File filesDir, byte[] widgetData); void backupApk(PackageInfo packageInfo); void backupObb(@UserIdInt int userId, PackageInfo packageInfo);  }### Answer:
@Test public void testBackupObb_withObbData_writesCorrectBytesToOutput() throws Exception { PackageInfo packageInfo = createPackageInfo(TEST_PACKAGE, TEST_PACKAGE_INSTALLER, TEST_PACKAGE_VERSION_CODE); File obbDir = createObbDirForPackage(packageInfo.packageName); byte[] obbBytes = "obb".getBytes(); File obbFile = createObbFileAndWrite(obbDir, obbBytes); mBackupWriter.backupObb(mUserId, packageInfo); byte[] writtenBytes = getWrittenBytes(mBackupDataOutputFile, false); assertThat(writtenBytes).isEqualTo(obbBytes); obbFile.delete(); }
@Test public void testBackupObb_withNoObbData_doesNotWriteBytesToOutput() { PackageInfo packageInfo = createPackageInfo(TEST_PACKAGE, TEST_PACKAGE_INSTALLER, TEST_PACKAGE_VERSION_CODE); File obbDir = createObbDirForPackage(packageInfo.packageName); mBackupWriter.backupObb(mUserId, packageInfo); assertThat(mBackupDataOutputFile.length()).isEqualTo(0); }