mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-06-18 20:59:48 -04:00
Refactored the recent MR for dynamicly adding default repos.
The idea was good: reduce the amount of copied/pasted code where ContentValues were initialized, populated, then inserted. I've kept the idea, by putting it in its own method which is called twice. But the resources are not loaded dynamically any more. This is so that the compiler will be able to pick up if we reference a missing resource. Also, I took the opportunity to replace the field name string literals with references to RepoProvider.DataColumns.* constants. Finally, changed the tests around because now we need to have the "getInteger()" call mocked in resources correctly (for priority/inUse).
This commit is contained in:
36
test/src/mock/MockFDroidResources.java
Normal file
36
test/src/mock/MockFDroidResources.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package mock;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.test.mock.*;
|
||||
import org.fdroid.fdroid.*;
|
||||
|
||||
public class MockFDroidResources extends MockResources {
|
||||
|
||||
private Context getStringDelegatingContext;
|
||||
|
||||
public MockFDroidResources(Context getStringDelegatingContext) {
|
||||
this.getStringDelegatingContext = getStringDelegatingContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(int id) {
|
||||
return getStringDelegatingContext.getString(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInteger(int id) {
|
||||
if (id == R.integer.default_repo_inuse1) {
|
||||
return 1;
|
||||
} else if (id == R.integer.default_repo_inuse2) {
|
||||
return 0;
|
||||
} else if (id == R.integer.default_repo_priority1) {
|
||||
return 10;
|
||||
} else if (id == R.integer.default_repo_priority2) {
|
||||
return 20;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user