Clean up MigrationTo60Test
This commit is contained in:
parent
af0c47c325
commit
78c7f01719
1 changed files with 145 additions and 150 deletions
|
@ -1,11 +1,7 @@
|
||||||
package com.fsck.k9.mailstore.migrations;
|
package com.fsck.k9.mailstore.migrations;
|
||||||
|
|
||||||
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -13,6 +9,9 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
import com.fsck.k9.controller.MessagingControllerCommands.PendingAppend;
|
import com.fsck.k9.controller.MessagingControllerCommands.PendingAppend;
|
||||||
import com.fsck.k9.controller.MessagingControllerCommands.PendingCommand;
|
import com.fsck.k9.controller.MessagingControllerCommands.PendingCommand;
|
||||||
import com.fsck.k9.controller.MessagingControllerCommands.PendingEmptyTrash;
|
import com.fsck.k9.controller.MessagingControllerCommands.PendingEmptyTrash;
|
||||||
|
@ -27,11 +26,12 @@ import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static java.util.Arrays.asList;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(manifest = Config.NONE)
|
@Config(manifest = Config.NONE)
|
||||||
public class MigrationTo60Test {
|
public class MigrationTo60Test {
|
||||||
|
@ -53,51 +53,33 @@ public class MigrationTo60Test {
|
||||||
private static final Flag FLAG = Flag.X_DESTROYED;
|
private static final Flag FLAG = Flag.X_DESTROYED;
|
||||||
private static final String UID = "uid";
|
private static final String UID = "uid";
|
||||||
private static final HashMap<String, String> UID_MAP = new HashMap<>();
|
private static final HashMap<String, String> UID_MAP = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
UID_MAP.put("uid_1", "uid_other_1");
|
UID_MAP.put("uid_1", "uid_other_1");
|
||||||
UID_MAP.put("uid_2", "uid_other_2");
|
UID_MAP.put("uid_2", "uid_other_2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void migratePendingCommands_changesTableStructure() {
|
public void migratePendingCommands_shouldChangeTableStructure() {
|
||||||
SQLiteDatabase database = SQLiteDatabase.create(null);
|
SQLiteDatabase database = createV59Table();
|
||||||
createV59Table(database);
|
|
||||||
MigrationTo60.migratePendingCommands(database);
|
MigrationTo60.migratePendingCommands(database);
|
||||||
|
|
||||||
List<String> columns = getColumnList(database, "pending_commands");
|
List<String> columns = getColumnList(database, "pending_commands");
|
||||||
|
assertEquals(asList("id", "command", "data"), columns);
|
||||||
assertArrayEquals(new String[]{"id", "command", "data"}, columns.toArray());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void migratePendingCommands_isMultiRunSafe() {
|
public void migratePendingCommands_withMultipleRuns_shouldNotThrow() {
|
||||||
SQLiteDatabase database = SQLiteDatabase.create(null);
|
SQLiteDatabase database = createV59Table();
|
||||||
createV59Table(database);
|
|
||||||
MigrationTo60.migratePendingCommands(database);
|
MigrationTo60.migratePendingCommands(database);
|
||||||
|
|
||||||
MigrationTo60.migratePendingCommands(database);
|
MigrationTo60.migratePendingCommands(database);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getColumnList(SQLiteDatabase db, String table) {
|
|
||||||
List<String> columns = new ArrayList<>();
|
|
||||||
Cursor columnCursor = db.rawQuery("PRAGMA table_info("+table+")", null);
|
|
||||||
while (columnCursor.moveToNext()) {
|
|
||||||
columns.add(columnCursor.getString(1));
|
|
||||||
}
|
|
||||||
return columns;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createV59Table(SQLiteDatabase db) {
|
|
||||||
db.execSQL("CREATE TABLE pending_commands (" +
|
|
||||||
"id INTEGER PRIMARY KEY, " +
|
|
||||||
"command TEXT, " +
|
|
||||||
"arguments TEXT" +
|
|
||||||
")");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMigrateMoveOrCopy__withUidArray() {
|
public void migrateMoveOrCopy_withUidArray() {
|
||||||
OldPendingCommand command = queueMoveOrCopy(SOURCE_FOLDER, DEST_FOLDER, IS_COPY, UID_ARRAY);
|
OldPendingCommand command = queueMoveOrCopy(SOURCE_FOLDER, DEST_FOLDER, IS_COPY, UID_ARRAY);
|
||||||
|
|
||||||
PendingMoveOrCopy pendingCommand = (PendingMoveOrCopy) MigrationTo60.migratePendingCommand(command);
|
PendingMoveOrCopy pendingCommand = (PendingMoveOrCopy) MigrationTo60.migratePendingCommand(command);
|
||||||
|
@ -105,10 +87,117 @@ public class MigrationTo60Test {
|
||||||
assertEquals(SOURCE_FOLDER, pendingCommand.srcFolder);
|
assertEquals(SOURCE_FOLDER, pendingCommand.srcFolder);
|
||||||
assertEquals(DEST_FOLDER, pendingCommand.destFolder);
|
assertEquals(DEST_FOLDER, pendingCommand.destFolder);
|
||||||
assertEquals(IS_COPY, pendingCommand.isCopy);
|
assertEquals(IS_COPY, pendingCommand.isCopy);
|
||||||
assertEquals(Arrays.asList(UID_ARRAY), pendingCommand.uids);
|
assertEquals(asList(UID_ARRAY), pendingCommand.uids);
|
||||||
assertNull(pendingCommand.newUidMap);
|
assertNull(pendingCommand.newUidMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void migrateMoveOrCopy_withUidMap() {
|
||||||
|
OldPendingCommand command = queueMoveOrCopy(SOURCE_FOLDER, DEST_FOLDER, IS_COPY, UID_MAP);
|
||||||
|
|
||||||
|
PendingMoveOrCopy pendingCommand = (PendingMoveOrCopy) MigrationTo60.migratePendingCommand(command);
|
||||||
|
|
||||||
|
assertEquals(SOURCE_FOLDER, pendingCommand.srcFolder);
|
||||||
|
assertEquals(DEST_FOLDER, pendingCommand.destFolder);
|
||||||
|
assertEquals(IS_COPY, pendingCommand.isCopy);
|
||||||
|
assertEquals(UID_MAP, pendingCommand.newUidMap);
|
||||||
|
assertNull(pendingCommand.uids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void migrateMoveOrCopy_withOldFormat() {
|
||||||
|
OldPendingCommand command = queueMoveOrCopyOld(SOURCE_FOLDER, DEST_FOLDER, IS_COPY, UID_ARRAY);
|
||||||
|
|
||||||
|
PendingMoveOrCopy pendingCommand = (PendingMoveOrCopy) MigrationTo60.migratePendingCommand(command);
|
||||||
|
|
||||||
|
assertEquals(SOURCE_FOLDER, pendingCommand.srcFolder);
|
||||||
|
assertEquals(DEST_FOLDER, pendingCommand.destFolder);
|
||||||
|
assertEquals(IS_COPY, pendingCommand.isCopy);
|
||||||
|
assertEquals(asList(UID_ARRAY), pendingCommand.uids);
|
||||||
|
assertNull(pendingCommand.newUidMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void migrateMoveOrCopy__withEvenOlderFormat() {
|
||||||
|
OldPendingCommand command = queueMoveOrCopyEvenOlder(SOURCE_FOLDER, DEST_FOLDER, UID, IS_COPY);
|
||||||
|
|
||||||
|
PendingMoveOrCopy pendingCommand = (PendingMoveOrCopy) MigrationTo60.migratePendingCommand(command);
|
||||||
|
|
||||||
|
assertEquals(SOURCE_FOLDER, pendingCommand.srcFolder);
|
||||||
|
assertEquals(DEST_FOLDER, pendingCommand.destFolder);
|
||||||
|
assertEquals(IS_COPY, pendingCommand.isCopy);
|
||||||
|
assertEquals(Collections.singletonList(UID), pendingCommand.uids);
|
||||||
|
assertNull(pendingCommand.newUidMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void migrateSetFlag() {
|
||||||
|
OldPendingCommand command = queueSetFlagBulk(SOURCE_FOLDER, FLAG_STATE, FLAG, UID_ARRAY);
|
||||||
|
|
||||||
|
PendingSetFlag pendingCommand = (PendingSetFlag) MigrationTo60.migratePendingCommand(command);
|
||||||
|
|
||||||
|
assertEquals(SOURCE_FOLDER, pendingCommand.folder);
|
||||||
|
assertEquals(FLAG_STATE, pendingCommand.newState);
|
||||||
|
assertEquals(FLAG, pendingCommand.flag);
|
||||||
|
assertEquals(asList(UID_ARRAY), pendingCommand.uids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void migrateSetFlag_oldFormat() {
|
||||||
|
OldPendingCommand command = queueSetFlagOld(SOURCE_FOLDER, FLAG_STATE, FLAG, UID);
|
||||||
|
|
||||||
|
PendingSetFlag pendingCommand = (PendingSetFlag) MigrationTo60.migratePendingCommand(command);
|
||||||
|
|
||||||
|
assertEquals(SOURCE_FOLDER, pendingCommand.folder);
|
||||||
|
assertEquals(FLAG_STATE, pendingCommand.newState);
|
||||||
|
assertEquals(FLAG, pendingCommand.flag);
|
||||||
|
assertEquals(Collections.singletonList(UID), pendingCommand.uids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void migrateExpunge() {
|
||||||
|
OldPendingCommand command = queueExpunge(SOURCE_FOLDER);
|
||||||
|
|
||||||
|
PendingExpunge pendingCommand = (PendingExpunge) MigrationTo60.migratePendingCommand(command);
|
||||||
|
|
||||||
|
assertEquals(SOURCE_FOLDER, pendingCommand.folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void migrateEmptyTrash() {
|
||||||
|
OldPendingCommand command = queueEmptyTrash();
|
||||||
|
|
||||||
|
PendingCommand pendingCommand = MigrationTo60.migratePendingCommand(command);
|
||||||
|
|
||||||
|
assertTrue(pendingCommand instanceof PendingEmptyTrash);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void migrateMarkAllMessagesRead() {
|
||||||
|
OldPendingCommand command = queueMarkAllMessagesRead(SOURCE_FOLDER);
|
||||||
|
|
||||||
|
PendingMarkAllAsRead pendingCommand = (PendingMarkAllAsRead) MigrationTo60.migratePendingCommand(command);
|
||||||
|
|
||||||
|
assertEquals(SOURCE_FOLDER, pendingCommand.folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void migrateAppend() {
|
||||||
|
OldPendingCommand command = queueAppend(SOURCE_FOLDER, UID);
|
||||||
|
|
||||||
|
PendingAppend pendingCommand = (PendingAppend) MigrationTo60.migratePendingCommand(command);
|
||||||
|
|
||||||
|
assertEquals(SOURCE_FOLDER, pendingCommand.folder);
|
||||||
|
assertEquals(UID, pendingCommand.uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
OldPendingCommand queueAppend(String srcFolder, String uid) {
|
||||||
|
OldPendingCommand command = new OldPendingCommand();
|
||||||
|
command.command = PENDING_COMMAND_APPEND;
|
||||||
|
command.arguments = new String[] { srcFolder, uid };
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
OldPendingCommand queueMoveOrCopy(String srcFolder, String destFolder, boolean isCopy, String uids[]) {
|
OldPendingCommand queueMoveOrCopy(String srcFolder, String destFolder, boolean isCopy, String uids[]) {
|
||||||
OldPendingCommand command = new OldPendingCommand();
|
OldPendingCommand command = new OldPendingCommand();
|
||||||
command.command = PENDING_COMMAND_MOVE_OR_COPY_BULK_NEW;
|
command.command = PENDING_COMMAND_MOVE_OR_COPY_BULK_NEW;
|
||||||
|
@ -123,22 +212,7 @@ public class MigrationTo60Test {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OldPendingCommand queueMoveOrCopy(String srcFolder, String destFolder, boolean isCopy, Map<String, String> uidMap) {
|
||||||
@Test
|
|
||||||
public void testMigrateMoveOrCopy__withUidMap() {
|
|
||||||
OldPendingCommand command = queueMoveOrCopy(SOURCE_FOLDER, DEST_FOLDER, IS_COPY, UID_MAP);
|
|
||||||
|
|
||||||
PendingMoveOrCopy pendingCommand = (PendingMoveOrCopy) MigrationTo60.migratePendingCommand(command);
|
|
||||||
|
|
||||||
assertEquals(SOURCE_FOLDER, pendingCommand.srcFolder);
|
|
||||||
assertEquals(DEST_FOLDER, pendingCommand.destFolder);
|
|
||||||
assertEquals(IS_COPY, pendingCommand.isCopy);
|
|
||||||
assertEquals(UID_MAP, pendingCommand.newUidMap);
|
|
||||||
assertNull(pendingCommand.uids);
|
|
||||||
}
|
|
||||||
|
|
||||||
OldPendingCommand queueMoveOrCopy(
|
|
||||||
String srcFolder, String destFolder, boolean isCopy, Map<String, String> uidMap) {
|
|
||||||
OldPendingCommand command = new OldPendingCommand();
|
OldPendingCommand command = new OldPendingCommand();
|
||||||
command.command = PENDING_COMMAND_MOVE_OR_COPY_BULK_NEW;
|
command.command = PENDING_COMMAND_MOVE_OR_COPY_BULK_NEW;
|
||||||
|
|
||||||
|
@ -151,24 +225,11 @@ public class MigrationTo60Test {
|
||||||
Set<String> strings = uidMap.keySet();
|
Set<String> strings = uidMap.keySet();
|
||||||
System.arraycopy(strings.toArray(new String[strings.size()]), 0, command.arguments, 4, uidMap.keySet().size());
|
System.arraycopy(strings.toArray(new String[strings.size()]), 0, command.arguments, 4, uidMap.keySet().size());
|
||||||
Collection<String> values = uidMap.values();
|
Collection<String> values = uidMap.values();
|
||||||
System.arraycopy(values.toArray(new String[values.size()]), 0, command.arguments, 4 + uidMap.keySet().size(), uidMap.values().size());
|
System.arraycopy(values.toArray(new String[values.size()]), 0, command.arguments, 4 + uidMap.keySet().size(),
|
||||||
|
uidMap.values().size());
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMigrateMoveOrCopy__withOldFormat() {
|
|
||||||
OldPendingCommand command = queueMoveOrCopyOld(SOURCE_FOLDER, DEST_FOLDER, IS_COPY, UID_ARRAY);
|
|
||||||
|
|
||||||
PendingMoveOrCopy pendingCommand = (PendingMoveOrCopy) MigrationTo60.migratePendingCommand(command);
|
|
||||||
|
|
||||||
assertEquals(SOURCE_FOLDER, pendingCommand.srcFolder);
|
|
||||||
assertEquals(DEST_FOLDER, pendingCommand.destFolder);
|
|
||||||
assertEquals(IS_COPY, pendingCommand.isCopy);
|
|
||||||
assertEquals(Arrays.asList(UID_ARRAY), pendingCommand.uids);
|
|
||||||
assertNull(pendingCommand.newUidMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
OldPendingCommand queueMoveOrCopyOld(String srcFolder, String destFolder, boolean isCopy, String uids[]) {
|
OldPendingCommand queueMoveOrCopyOld(String srcFolder, String destFolder, boolean isCopy, String uids[]) {
|
||||||
OldPendingCommand command = new OldPendingCommand();
|
OldPendingCommand command = new OldPendingCommand();
|
||||||
command.command = PENDING_COMMAND_MOVE_OR_COPY_BULK;
|
command.command = PENDING_COMMAND_MOVE_OR_COPY_BULK;
|
||||||
|
@ -182,20 +243,6 @@ public class MigrationTo60Test {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMigrateMoveOrCopy__withEvenOlderFormat() {
|
|
||||||
OldPendingCommand command = queueMoveOrCopyEvenOlder(SOURCE_FOLDER, DEST_FOLDER, UID, IS_COPY);
|
|
||||||
|
|
||||||
PendingMoveOrCopy pendingCommand = (PendingMoveOrCopy) MigrationTo60.migratePendingCommand(command);
|
|
||||||
|
|
||||||
assertEquals(SOURCE_FOLDER, pendingCommand.srcFolder);
|
|
||||||
assertEquals(DEST_FOLDER, pendingCommand.destFolder);
|
|
||||||
assertEquals(IS_COPY, pendingCommand.isCopy);
|
|
||||||
assertEquals(Collections.singletonList(UID), pendingCommand.uids);
|
|
||||||
assertNull(pendingCommand.newUidMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
OldPendingCommand queueMoveOrCopyEvenOlder(String srcFolder, String destFolder, String uid, boolean isCopy) {
|
OldPendingCommand queueMoveOrCopyEvenOlder(String srcFolder, String destFolder, String uid, boolean isCopy) {
|
||||||
OldPendingCommand command = new OldPendingCommand();
|
OldPendingCommand command = new OldPendingCommand();
|
||||||
command.command = PENDING_COMMAND_MOVE_OR_COPY;
|
command.command = PENDING_COMMAND_MOVE_OR_COPY;
|
||||||
|
@ -208,19 +255,6 @@ public class MigrationTo60Test {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMigrateSetFlag() {
|
|
||||||
OldPendingCommand command = queueSetFlagBulk(SOURCE_FOLDER, FLAG_STATE, FLAG, UID_ARRAY);
|
|
||||||
|
|
||||||
PendingSetFlag pendingCommand = (PendingSetFlag) MigrationTo60.migratePendingCommand(command);
|
|
||||||
|
|
||||||
assertEquals(SOURCE_FOLDER, pendingCommand.folder);
|
|
||||||
assertEquals(FLAG_STATE, pendingCommand.newState);
|
|
||||||
assertEquals(FLAG, pendingCommand.flag);
|
|
||||||
assertEquals(Arrays.asList(UID_ARRAY), pendingCommand.uids);
|
|
||||||
}
|
|
||||||
|
|
||||||
OldPendingCommand queueSetFlagBulk(String folderName, boolean newState, Flag flag, String[] uids) {
|
OldPendingCommand queueSetFlagBulk(String folderName, boolean newState, Flag flag, String[] uids) {
|
||||||
OldPendingCommand command = new OldPendingCommand();
|
OldPendingCommand command = new OldPendingCommand();
|
||||||
command.command = PENDING_COMMAND_SET_FLAG_BULK;
|
command.command = PENDING_COMMAND_SET_FLAG_BULK;
|
||||||
|
@ -233,19 +267,6 @@ public class MigrationTo60Test {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMigrateSetFlag__oldFormat() {
|
|
||||||
OldPendingCommand command = queueSetFlagOld(SOURCE_FOLDER, FLAG_STATE, FLAG, UID);
|
|
||||||
|
|
||||||
PendingSetFlag pendingCommand = (PendingSetFlag) MigrationTo60.migratePendingCommand(command);
|
|
||||||
|
|
||||||
assertEquals(SOURCE_FOLDER, pendingCommand.folder);
|
|
||||||
assertEquals(FLAG_STATE, pendingCommand.newState);
|
|
||||||
assertEquals(FLAG, pendingCommand.flag);
|
|
||||||
assertEquals(Collections.singletonList(UID), pendingCommand.uids);
|
|
||||||
}
|
|
||||||
|
|
||||||
OldPendingCommand queueSetFlagOld(String folderName, boolean newState, Flag flag, String uid) {
|
OldPendingCommand queueSetFlagOld(String folderName, boolean newState, Flag flag, String uid) {
|
||||||
OldPendingCommand command = new OldPendingCommand();
|
OldPendingCommand command = new OldPendingCommand();
|
||||||
command.command = PENDING_COMMAND_SET_FLAG;
|
command.command = PENDING_COMMAND_SET_FLAG;
|
||||||
|
@ -257,16 +278,6 @@ public class MigrationTo60Test {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMigrateExpunge() {
|
|
||||||
OldPendingCommand command = queueExpunge(SOURCE_FOLDER);
|
|
||||||
|
|
||||||
PendingExpunge pendingCommand = (PendingExpunge) MigrationTo60.migratePendingCommand(command);
|
|
||||||
|
|
||||||
assertEquals(SOURCE_FOLDER, pendingCommand.folder);
|
|
||||||
}
|
|
||||||
|
|
||||||
OldPendingCommand queueExpunge(String folderName) {
|
OldPendingCommand queueExpunge(String folderName) {
|
||||||
OldPendingCommand command = new OldPendingCommand();
|
OldPendingCommand command = new OldPendingCommand();
|
||||||
command.command = PENDING_COMMAND_EXPUNGE;
|
command.command = PENDING_COMMAND_EXPUNGE;
|
||||||
|
@ -275,16 +286,6 @@ public class MigrationTo60Test {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMigrateEmptyTrash() {
|
|
||||||
OldPendingCommand command = queueEmptyTrash();
|
|
||||||
|
|
||||||
PendingCommand pendingCommand = MigrationTo60.migratePendingCommand(command);
|
|
||||||
|
|
||||||
assertTrue(pendingCommand instanceof PendingEmptyTrash);
|
|
||||||
}
|
|
||||||
|
|
||||||
OldPendingCommand queueEmptyTrash() {
|
OldPendingCommand queueEmptyTrash() {
|
||||||
OldPendingCommand command = new OldPendingCommand();
|
OldPendingCommand command = new OldPendingCommand();
|
||||||
command.command = PENDING_COMMAND_EMPTY_TRASH;
|
command.command = PENDING_COMMAND_EMPTY_TRASH;
|
||||||
|
@ -292,16 +293,6 @@ public class MigrationTo60Test {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMigrateMarkAllMessagesRead() {
|
|
||||||
OldPendingCommand command = queueMarkAllMessagesRead(SOURCE_FOLDER);
|
|
||||||
|
|
||||||
PendingMarkAllAsRead pendingCommand = (PendingMarkAllAsRead) MigrationTo60.migratePendingCommand(command);
|
|
||||||
|
|
||||||
assertEquals(SOURCE_FOLDER, pendingCommand.folder);
|
|
||||||
}
|
|
||||||
|
|
||||||
OldPendingCommand queueMarkAllMessagesRead(final String folder) {
|
OldPendingCommand queueMarkAllMessagesRead(final String folder) {
|
||||||
OldPendingCommand command = new OldPendingCommand();
|
OldPendingCommand command = new OldPendingCommand();
|
||||||
command.command = PENDING_COMMAND_MARK_ALL_AS_READ;
|
command.command = PENDING_COMMAND_MARK_ALL_AS_READ;
|
||||||
|
@ -309,22 +300,26 @@ public class MigrationTo60Test {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> getColumnList(SQLiteDatabase db, String table) {
|
||||||
@Test
|
List<String> columns = new ArrayList<>();
|
||||||
public void testMigrateAppend() {
|
Cursor columnCursor = db.rawQuery("PRAGMA table_info(" + table + ")", null);
|
||||||
OldPendingCommand command = queueAppend(SOURCE_FOLDER, UID);
|
try {
|
||||||
|
while (columnCursor.moveToNext()) {
|
||||||
PendingAppend pendingCommand = (PendingAppend) MigrationTo60.migratePendingCommand(command);
|
columns.add(columnCursor.getString(1));
|
||||||
|
}
|
||||||
assertEquals(SOURCE_FOLDER, pendingCommand.folder);
|
} finally {
|
||||||
assertEquals(UID, pendingCommand.uid);
|
columnCursor.close();
|
||||||
|
}
|
||||||
|
return columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
OldPendingCommand queueAppend(String srcFolder, String uid) {
|
private SQLiteDatabase createV59Table() {
|
||||||
OldPendingCommand command = new OldPendingCommand();
|
SQLiteDatabase database = SQLiteDatabase.create(null);
|
||||||
command.command = PENDING_COMMAND_APPEND;
|
database.execSQL("CREATE TABLE pending_commands (" +
|
||||||
command.arguments = new String[] { srcFolder, uid };
|
"id INTEGER PRIMARY KEY, " +
|
||||||
return command;
|
"command TEXT, " +
|
||||||
|
"arguments TEXT" +
|
||||||
|
")");
|
||||||
|
return database;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue