Clean up StoreSchemaDefinitionTest

This commit is contained in:
cketti 2017-02-12 12:26:18 +01:00
parent 83951c087e
commit ac6a1ea213

View file

@ -297,15 +297,13 @@ public class StoreSchemaDefinitionTest {
private List<String> objectsInDatabase(SQLiteDatabase db, String type) { private List<String> objectsInDatabase(SQLiteDatabase db, String type) {
List<String> databaseObjects = new ArrayList<>(); List<String> databaseObjects = new ArrayList<>();
Cursor cursor = db.rawQuery("SELECT sql FROM sqlite_master WHERE type = ? AND sql IS NOT NULL", new String[] { type }); Cursor cursor = db.rawQuery("SELECT sql FROM sqlite_master WHERE type = ? AND sql IS NOT NULL",
new String[] { type });
try { try {
if (cursor.moveToFirst()) { while (cursor.moveToNext()) {
while (!cursor.isAfterLast()) { String sql = cursor.getString(cursor.getColumnIndex("sql"));
String sql = cursor.getString(cursor.getColumnIndex("sql")); String resortedSql = "table".equals(type) ? sortTableColumns(sql) : sql;
String resortedSql = "table".equals(type) ? sortTableColumns(sql) : sql; databaseObjects.add(resortedSql);
databaseObjects.add(resortedSql);
cursor.moveToNext();
}
} }
} finally { } finally {
cursor.close(); cursor.close();
@ -316,10 +314,13 @@ public class StoreSchemaDefinitionTest {
private String sortTableColumns(String sql) { private String sortTableColumns(String sql) {
int positionOfColumnDefinitions = sql.indexOf('('); int positionOfColumnDefinitions = sql.indexOf('(');
String colsStr = sql.substring(positionOfColumnDefinitions+1, sql.length()-1); String columnDefinitionsSql = sql.substring(positionOfColumnDefinitions + 1, sql.length() - 1);
String[] cols = colsStr.split(" *, *(?![^\\(]*\\))"); String[] columnDefinitions = columnDefinitionsSql.split(" *, *(?![^(]*\\))");
Arrays.sort(cols); Arrays.sort(columnDefinitions);
return sql.substring(0, positionOfColumnDefinitions+1) + TextUtils.join(", ", cols) + ")";
String sqlPrefix = sql.substring(0, positionOfColumnDefinitions + 1);
String sortedColumnDefinitionsSql = TextUtils.join(", ", columnDefinitions);
return sqlPrefix + sortedColumnDefinitionsSql + ")";
} }
private void insertMessageWithSubject(SQLiteDatabase database, String subject) { private void insertMessageWithSubject(SQLiteDatabase database, String subject) {