simplify creation of Repo instances in tests

Creating a Repo instance first seems totally redundant and confusing.
This commit is contained in:
Hans-Christoph Steiner 2018-03-28 22:53:25 +02:00
parent 5e6ff06e0e
commit 34381f9cfb

View File

@ -158,22 +158,17 @@ public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
return createRepo(name, uri, context, PUB_KEY); return createRepo(name, uri, context, PUB_KEY);
} }
/**
* Creates a real instance of {@code Repo} by loading it from the database,
* that ensures it includes the primary key from the database.
*/
static Repo createRepo(String name, String uri, Context context, String signingCert) { static Repo createRepo(String name, String uri, Context context, String signingCert) {
Repo repo = new Repo();
repo.signingCertificate = signingCert;
repo.address = uri;
repo.name = name;
ContentValues values = new ContentValues(3); ContentValues values = new ContentValues(3);
values.put(Schema.RepoTable.Cols.SIGNING_CERT, repo.signingCertificate); values.put(Schema.RepoTable.Cols.SIGNING_CERT, signingCert);
values.put(Schema.RepoTable.Cols.ADDRESS, repo.address); values.put(Schema.RepoTable.Cols.ADDRESS, uri);
values.put(Schema.RepoTable.Cols.NAME, repo.name); values.put(Schema.RepoTable.Cols.NAME, name);
RepoProvider.Helper.insert(context, values); RepoProvider.Helper.insert(context, values);
return RepoProvider.Helper.findByAddress(context, uri);
// Need to reload the repo based on address so that it includes the primary key from
// the database.
return RepoProvider.Helper.findByAddress(context, repo.address);
} }
protected RepoUpdater createRepoUpdater(String name, String uri, Context context) { protected RepoUpdater createRepoUpdater(String name, String uri, Context context) {