ModuleLicenseProviderTest converted to JUnit

The superclass ContentProvider's "getContext" method is final and
cannot be mocked, so a helper method visible for testing was added
to allow for context injection.

Bug: 175389659
Test: atest -c ModuleLicenseProviderTest
Change-Id: I9e20171340ae0a48d74fae44c7b356ea67dba43b
This commit is contained in:
Jeremy Goldman
2020-12-17 14:39:19 +08:00
parent 836df5eb3a
commit 471659f30d
2 changed files with 25 additions and 21 deletions

View File

@@ -62,7 +62,7 @@ public class ModuleLicenseProvider extends ContentProvider {
@Override
public String getType(Uri uri) {
checkUri(getContext(), uri);
checkUri(getModuleContext(), uri);
return LICENSE_FILE_MIME_TYPE;
}
@@ -83,7 +83,7 @@ public class ModuleLicenseProvider extends ContentProvider {
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) {
final Context context = getContext();
final Context context = getModuleContext();
checkUri(context, uri);
Preconditions.checkArgument("r".equals(mode), "Read is the only supported mode");
@@ -191,4 +191,10 @@ public class ModuleLicenseProvider extends ContentProvider {
private static SharedPreferences getPrefs(Context context) {
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
}
// Method to allow context injection for testing purposes.
@VisibleForTesting
protected Context getModuleContext() {
return getContext();
}
}