TopLevelStoragePreferenceControllerTest converted to JUnit
Helper function composed to return thread future, to guarantee
concurrent function finishes before test condition is checked.
Additionally a @VisibleForTesting helper function is used rather than
robolectric reflection helpers to set a class variable.
Fixes: 187249674
Test: atest -c TopLevelStoragePreferenceControllerTest
Change-Id: Ia22ebac4baec60f72b8516e9e79998cd788266ab
Merged-In: Ia22ebac4baec60f72b8516e9e79998cd788266ab
(cherry picked from commit 899eb7282d)
This commit is contained in:
committed by
Yanting Yang
parent
80daf4fc49
commit
8e712c1501
@@ -21,6 +21,7 @@ import android.os.storage.StorageManager;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -31,6 +32,7 @@ import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class TopLevelStoragePreferenceController extends BasePreferenceController {
|
||||
|
||||
@@ -59,10 +61,15 @@ public class TopLevelStoragePreferenceController extends BasePreferenceControlle
|
||||
return;
|
||||
}
|
||||
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
refreshSummaryThread(preference);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected Future refreshSummaryThread(Preference preference) {
|
||||
return ThreadUtils.postOnBackgroundThread(() -> {
|
||||
final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
|
||||
final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
|
||||
mStorageManagerVolumeProvider);
|
||||
getStorageManagerVolumeProvider());
|
||||
final double privateUsedBytes = info.totalBytes - info.freeBytes;
|
||||
|
||||
ThreadUtils.postOnMainThread(() -> {
|
||||
@@ -72,4 +79,10 @@ public class TopLevelStoragePreferenceController extends BasePreferenceControlle
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@VisibleForTesting
|
||||
protected StorageManagerVolumeProvider getStorageManagerVolumeProvider() {
|
||||
return mStorageManagerVolumeProvider;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user