add unit tests for PendingCommand serialization
This commit is contained in:
parent
73c2b1e9ad
commit
d6c50b4db6
1 changed files with 80 additions and 0 deletions
|
@ -0,0 +1,80 @@
|
||||||
|
package com.fsck.k9.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import com.fsck.k9.controller.MessagingControllerCommands.PendingAppend;
|
||||||
|
import com.fsck.k9.controller.MessagingControllerCommands.PendingCommand;
|
||||||
|
import com.fsck.k9.controller.MessagingControllerCommands.PendingEmptyTrash;
|
||||||
|
import com.fsck.k9.controller.MessagingControllerCommands.PendingMoveOrCopy;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class PendingCommandSerializerTest {
|
||||||
|
static final int DATABASE_ID = 123;
|
||||||
|
static final String UID = "uid";
|
||||||
|
static final String SOURCE_FOLDER = "source_folder";
|
||||||
|
static final String DEST_FOLDER = "dest_folder";
|
||||||
|
static final HashMap<String, String> UID_MAP = new HashMap<>();
|
||||||
|
public static final boolean IS_COPY = true;
|
||||||
|
|
||||||
|
static {
|
||||||
|
UID_MAP.put("uid_1", "uid_other_1");
|
||||||
|
UID_MAP.put("uid_2", "uid_other_2");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PendingCommandSerializer pendingCommandSerializer = PendingCommandSerializer.getInstance();
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerializeDeserialize__withoutArguments() {
|
||||||
|
PendingCommand pendingCommand = MessagingControllerCommands.createEmptyTrash();
|
||||||
|
|
||||||
|
String serializedCommand = pendingCommandSerializer.serialize(pendingCommand);
|
||||||
|
PendingEmptyTrash unserializedCommand = (PendingEmptyTrash) pendingCommandSerializer.unserialize(
|
||||||
|
DATABASE_ID, pendingCommand.getCommandName(), serializedCommand);
|
||||||
|
|
||||||
|
assertEquals(DATABASE_ID, unserializedCommand.databaseId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerializeDeserialize__withArguments() {
|
||||||
|
PendingCommand pendingCommand = MessagingControllerCommands.createAppend(SOURCE_FOLDER, UID);
|
||||||
|
|
||||||
|
String serializedCommand = pendingCommandSerializer.serialize(pendingCommand);
|
||||||
|
PendingAppend unserializedCommand = (PendingAppend) pendingCommandSerializer.unserialize(
|
||||||
|
DATABASE_ID, pendingCommand.getCommandName(), serializedCommand);
|
||||||
|
|
||||||
|
assertEquals(DATABASE_ID, unserializedCommand.databaseId);
|
||||||
|
assertEquals(SOURCE_FOLDER, unserializedCommand.folder);
|
||||||
|
assertEquals(UID, unserializedCommand.uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerializeDeserialize__withComplexArguments() {
|
||||||
|
PendingCommand pendingCommand = MessagingControllerCommands.createMoveOrCopyBulk(
|
||||||
|
SOURCE_FOLDER, DEST_FOLDER, IS_COPY, UID_MAP);
|
||||||
|
|
||||||
|
String serializedCommand = pendingCommandSerializer.serialize(pendingCommand);
|
||||||
|
PendingMoveOrCopy unserializedCommand = (PendingMoveOrCopy) pendingCommandSerializer.unserialize(
|
||||||
|
DATABASE_ID, pendingCommand.getCommandName(), serializedCommand);
|
||||||
|
|
||||||
|
assertEquals(DATABASE_ID, unserializedCommand.databaseId);
|
||||||
|
assertEquals(SOURCE_FOLDER, unserializedCommand.srcFolder);
|
||||||
|
assertEquals(DEST_FOLDER, unserializedCommand.destFolder);
|
||||||
|
assertEquals(UID_MAP, unserializedCommand.newUidMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testDeserialize__withUnknownCommandName__shouldFail() {
|
||||||
|
PendingCommand pendingCommand = MessagingControllerCommands.createEmptyTrash();
|
||||||
|
|
||||||
|
String serializedCommand = pendingCommandSerializer.serialize(pendingCommand);
|
||||||
|
pendingCommandSerializer.unserialize(DATABASE_ID, "BAD_COMMAND_NAME", serializedCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue