Skip to content

Commit

Permalink
Add test for Repository#onUpgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ekigamba committed Feb 3, 2021
1 parent 3107c81 commit e20a180
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion opensrp-app/src/test/assets/config/migrations/1.up.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CREATE IF NOT EXISTS TABLE key_value(key VARCHAR, val VARCHAR);
CREATE IF NOT EXISTS TABLE key_value(key VARCHAR, val VARCHAR);
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ public String getOauthClientSecret() {
public Class<? extends BaseLoginActivity> getAuthenticationActivity() {
return BaseLoginActivity.class;
}

@Override
public boolean isMigrationsConfigurationEnabled() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,19 @@ public void canUseThisPasswordShouldCallIsDatabaseWritableAndReturnTrue() {
Mockito.doReturn(true).when(repository).isDatabaseWritable(password);
Assert.assertTrue(repository.canUseThisPassword(password));
}

@Test
public void onUpgradeShouldApplyMigrationsFromAssetsFolder() {
Repository repository = Mockito.mock(Repository.class, Mockito.CALLS_REAL_METHODS);
ReflectionHelpers.setField(repository, "context", RuntimeEnvironment.application);
SQLiteDatabase database = Mockito.mock(SQLiteDatabase.class);

// call the method under test
repository.onUpgrade(database, 0, 3);

// Verify the migration calls
Mockito.verify(database).execSQL(Mockito.eq("CREATE IF NOT EXISTS TABLE key_value(key VARCHAR, val VARCHAR);"));
Mockito.verify(database).execSQL(Mockito.eq("CREATE IF NOT EXISTS TABLE clients(id INTEGER, full_name VARCHAR, age INTEGER, dob INTEGER);"));
Mockito.verify(database).execSQL(Mockito.eq("CREATE IF NOT EXISTS TABLE events(event_id INTEGER, json VARCHAR, server_version INTEGER);"));
}
}

0 comments on commit e20a180

Please sign in to comment.