
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).
37 lines
936 B
Java
37 lines
936 B
Java
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;
|
|
}
|
|
}
|
|
|
|
}
|