Skip to content

Commit

Permalink
Fixed "migrate12To14IndexSideEffects"
Browse files Browse the repository at this point in the history
This also makes the test method compatible with "MappingSupportSQLiteDatabase"
Also added "assertIsUUID"

*This commit is related to issue #529 [1]*

[1] #529
  • Loading branch information
JaniruTEC committed Apr 21, 2024
1 parent 6af9811 commit abf19e2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import com.google.android.gms.common.util.Strings;

import java.text.MessageFormat;
import java.util.regex.Pattern;

import static org.junit.Assert.fail;

public class CryptomatorAssert {

private final static Pattern UUID_PATTERN = Pattern.compile("^\\p{XDigit}{8}-\\p{XDigit}{4}-\\p{XDigit}{4}-\\p{XDigit}{4}-\\p{XDigit}{12}$");

private CryptomatorAssert() {
}

Expand Down Expand Up @@ -40,4 +43,18 @@ private static void failCursorNotEquals(String message, Cursor expected, Cursor
CryptomatorDatabaseKt.stringify(actual));
fail(failMessage);
}

public static void assertIsUUID(String actual) {
assertIsUUID(null, actual);
}

public static void assertIsUUID(String message, String actual) {
if (actual != null && UUID_PATTERN.matcher(actual).matches()) {
return;
}
String failMessage = MessageFormat.format("{0}: {1}", //
message != null && !Strings.isEmptyOrWhitespace(message) ? message : "String is not a valid UUID", //
actual != null ? '"' + actual + '"' : "<null>");
fail(failMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.test.filters.SmallTest
import androidx.test.platform.app.InstrumentationRegistry
import com.google.common.base.Optional
import org.cryptomator.data.db.CryptomatorAssert.assertCursorEquals
import org.cryptomator.data.db.CryptomatorAssert.assertIsUUID
import org.cryptomator.data.db.migrations.Sql
import org.cryptomator.data.db.migrations.legacy.Upgrade10To11
import org.cryptomator.data.db.migrations.legacy.Upgrade11To12
Expand Down Expand Up @@ -43,6 +44,8 @@ import org.junit.runner.RunWith
private const val TEST_DB = "migration-test"
private const val LATEST_LEGACY_MIGRATION = 12

private const val UUID_LENGTH = 36

@RunWith(AndroidJUnit4::class)
@SmallTest
class UpgradeDatabaseTest {
Expand Down Expand Up @@ -755,9 +758,10 @@ class UpgradeDatabaseTest {
Upgrade11To12(sharedPreferencesHandler).migrate(db)

val pre13Statement = indexStatement(db)
val pre13Expected = "CREATE UNIQUE INDEX \"IDX_VAULT_ENTITY_FOLDER_PATH_FOLDER_CLOUD_ID\" ON \"VAULT_ENTITY\" (\"FOLDER_PATH\" ASC,\"FOLDER_CLOUD_ID\" ASC)"
val pre13Expected = "CREATE UNIQUE INDEX \"IDX_VAULT_ENTITY_FOLDER_PATH_FOLDER_CLOUD_ID\" ON \"VAULT_ENTITY\" (\"FOLDER_PATH\" ASC,\"FOLDER_CLOUD_ID\" ASC) -- "
//This is a sanity check and may need to be updated if Sql.java is changed
assertEquals(pre13Expected, pre13Statement)
assertEquals(pre13Expected, pre13Statement.substring(0, pre13Statement.length - UUID_LENGTH))
assertIsUUID(pre13Statement.substring(pre13Statement.length - UUID_LENGTH))
db.close()

helper.runMigrationsAndValidate(TEST_DB, 13, true, Migration12To13()).also { migratedDb ->
Expand Down

0 comments on commit abf19e2

Please sign in to comment.