Skip to content

Instantly share code, notes, and snippets.

@xcesco
Created May 14, 2018 20:13
Show Gist options
  • Save xcesco/60d73015d99e53b9c18779cafd51612e to your computer and use it in GitHub Desktop.
Save xcesco/60d73015d99e53b9c18779cafd51612e to your computer and use it in GitHub Desktop.
@Test
public void testMigration() throws Exception {
// Context of the app under test.
Context testContext = InstrumentationRegistry.getContext();
Context context = InstrumentationRegistry.getTargetContext();
KriptonLibrary.init(context);
InputStream schema1 = testContext.getAssets().open("xeno_schema_1.sql");
InputStream schema2 = testContext.getAssets().open("xeno_schema_2.sql");
InputStream finalSchema1 = testContext.getAssets().open("xeno_schema_1.sql");
InputStream finalSchema2 = testContext.getAssets().open("xeno_schema_2.sql");
SQLiteTestDatabase.clearDatabase(context);
SQLiteTestDatabase database = SQLiteTestDatabase.builder(1, schema1)
.addPopulator(datasource -> XenoApplication.fillCountryCodes(context))
.addVersionUpdateTask(2, (datasource, previousVersion, currentVersion) -> XenoApplication.migrationVersion2(context, datasource))
.build();
database.updateAndVerify(1, finalSchema1);
database.updateAndVerify(2, finalSchema2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment