mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-13 04:55:04 -05:00
Merge pull request #559
This commit is contained in:
commit
4db7de4ed8
@ -1,5 +1,6 @@
|
||||
package com.fsck.k9.activity;
|
||||
|
||||
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.fsck.k9.mail.Flag;
|
||||
@ -8,84 +9,148 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class MessageReferenceTest
|
||||
{
|
||||
/**
|
||||
* Typically happens during forwards. (You have a reference, but no flag since we don't currently consider FORWARDED a flag.)
|
||||
*/
|
||||
public class MessageReferenceTest {
|
||||
|
||||
@Test
|
||||
public void testIdentityStringNoFlag()
|
||||
{
|
||||
MessageReference mr = new MessageReference();
|
||||
mr.accountUuid = "o hai!";
|
||||
mr.folderName = "folder";
|
||||
mr.uid = "10101010";
|
||||
public void checkIdentityStringFromMessageReferenceWithoutFlag() {
|
||||
MessageReference messageReference = createMessageReference("o hai!", "folder", "10101010");
|
||||
|
||||
assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=", mr.toIdentityString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Typically happens during replies.
|
||||
*/
|
||||
@Test
|
||||
public void testIdentityString()
|
||||
{
|
||||
MessageReference mr = new MessageReference();
|
||||
mr.accountUuid = "o hai!";
|
||||
mr.folderName = "folder";
|
||||
mr.uid = "10101010";
|
||||
mr.flag = Flag.ANSWERED;
|
||||
|
||||
assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED", mr.toIdentityString());
|
||||
assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=", messageReference.toIdentityString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseIdentityStringNoFlag() throws MessagingException
|
||||
{
|
||||
MessageReference mr = new MessageReference("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=");
|
||||
assertEquals("o hai!", mr.accountUuid);
|
||||
assertEquals("folder", mr.folderName);
|
||||
assertEquals("10101010", mr.uid);
|
||||
assertNull(mr.flag);
|
||||
public void checkIdentityStringFromMessageReferenceWithFlag() {
|
||||
MessageReference messageReference =
|
||||
createMessageReferenceWithFlag("o hai!", "folder", "10101010", Flag.ANSWERED);
|
||||
|
||||
assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED", messageReference.toIdentityString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseIdentityString() throws MessagingException
|
||||
{
|
||||
MessageReference mr = new MessageReference("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED");
|
||||
assertEquals("o hai!", mr.accountUuid);
|
||||
assertEquals("folder", mr.folderName);
|
||||
assertEquals("10101010", mr.uid);
|
||||
assertEquals(Flag.ANSWERED, mr.flag);
|
||||
public void parseIdentityStringWithoutFlag() throws MessagingException {
|
||||
MessageReference messageReference = new MessageReference("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=");
|
||||
|
||||
assertEquals("o hai!", messageReference.accountUuid);
|
||||
assertEquals("folder", messageReference.folderName);
|
||||
assertEquals("10101010", messageReference.uid);
|
||||
assertNull(messageReference.flag);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadVersion() throws MessagingException
|
||||
{
|
||||
MessageReference mr = new MessageReference("@:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED");
|
||||
assertNull(mr.accountUuid);
|
||||
public void parseIdentityStringWithFlag() throws MessagingException {
|
||||
MessageReference messageReference = new MessageReference("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED");
|
||||
|
||||
assertEquals("o hai!", messageReference.accountUuid);
|
||||
assertEquals("folder", messageReference.folderName);
|
||||
assertEquals("10101010", messageReference.uid);
|
||||
assertEquals(Flag.ANSWERED, messageReference.flag);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseIdentityStringContainingBadVersionNumber() throws MessagingException {
|
||||
MessageReference messageReference = new MessageReference("@:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED");
|
||||
|
||||
assertNull(messageReference.accountUuid);
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void testNull() throws MessagingException
|
||||
{
|
||||
public void parseNullIdentityString() throws MessagingException {
|
||||
new MessageReference(null);
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void testCorruption() throws MessagingException
|
||||
{
|
||||
MessageReference mr = new MessageReference("!:%^&%^*$&$by&(BYWkh:Zm9%^@sZGVy:MT-35#$AxMDEwMTA=:ANSWERED");
|
||||
// No idea what this is going to generate, but it should be non-null.
|
||||
assertNotNull(mr.accountUuid);
|
||||
assertNotNull(mr.folderName);
|
||||
assertNotNull(mr.uid);
|
||||
|
||||
// Corruption in the Flag should throw MessagingException.
|
||||
public void parseIdentityStringWithCorruptFlag() throws MessagingException {
|
||||
new MessageReference("!:%^&%^*$&$by&(BYWkh:Zm9%^@sZGVy:MT-35#$AxMDEwMTA=:ANSWE!RED");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWithAnObjectShouldReturnFalse() {
|
||||
MessageReference messageReference = new MessageReference();
|
||||
Object object = new Object();
|
||||
|
||||
assertFalse(messageReference.equals(object));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ObjectEqualsNull")
|
||||
@Test
|
||||
public void equalsWithNullShouldReturnFalse() {
|
||||
MessageReference messageReference = createMessageReference("account", "folder", "uid");
|
||||
|
||||
assertFalse(messageReference.equals(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWithSameMessageReferenceShouldReturnTrue() {
|
||||
MessageReference messageReference = createMessageReference("account", "folder", "uid");
|
||||
|
||||
assertTrue(messageReference.equals(messageReference));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWithMessageReferenceContainingSameDataShouldReturnTrue() {
|
||||
MessageReference messageReferenceOne = createMessageReference("account", "folder", "uid");
|
||||
MessageReference messageReferenceTwo = createMessageReference("account", "folder", "uid");
|
||||
|
||||
assertEqualsReturnsTrueSymmetrically(messageReferenceOne, messageReferenceTwo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWithMessageReferenceContainingDifferentAccountUuidShouldReturnFalse() {
|
||||
MessageReference messageReferenceOne = createMessageReference("account", "folder", "uid");
|
||||
MessageReference messageReferenceTwo = createMessageReference("-------", "folder", "uid");
|
||||
|
||||
assertEqualsReturnsFalseSymmetrically(messageReferenceOne, messageReferenceTwo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWithMessageReferenceContainingDifferentFolderNameShouldReturnFalse() {
|
||||
MessageReference messageReferenceOne = createMessageReference("account", "folder", "uid");
|
||||
MessageReference messageReferenceTwo = createMessageReference("account", "------", "uid");
|
||||
|
||||
assertEqualsReturnsFalseSymmetrically(messageReferenceOne, messageReferenceTwo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWithMessageReferenceContainingDifferentUidShouldReturnFalse() {
|
||||
MessageReference messageReferenceOne = createMessageReference("account", "folder", "uid");
|
||||
MessageReference messageReferenceTwo = createMessageReference("account", "folder", "---");
|
||||
|
||||
assertEqualsReturnsFalseSymmetrically(messageReferenceOne, messageReferenceTwo);
|
||||
}
|
||||
|
||||
private MessageReference createMessageReference(String accountUuid, String folderName, String uid) {
|
||||
MessageReference messageReference = new MessageReference();
|
||||
messageReference.accountUuid = accountUuid;
|
||||
messageReference.folderName = folderName;
|
||||
messageReference.uid = uid;
|
||||
|
||||
return messageReference;
|
||||
}
|
||||
|
||||
private MessageReference createMessageReferenceWithFlag(String accountUuid, String folderName, String uid,
|
||||
Flag flag) {
|
||||
MessageReference messageReference = new MessageReference();
|
||||
messageReference.accountUuid = accountUuid;
|
||||
messageReference.folderName = folderName;
|
||||
messageReference.uid = uid;
|
||||
messageReference.flag = flag;
|
||||
|
||||
return messageReference;
|
||||
}
|
||||
|
||||
private void assertEqualsReturnsTrueSymmetrically(MessageReference referenceOne, MessageReference referenceTwo) {
|
||||
assertTrue(referenceOne.equals(referenceTwo));
|
||||
assertTrue(referenceTwo.equals(referenceOne));
|
||||
}
|
||||
|
||||
private void assertEqualsReturnsFalseSymmetrically(MessageReference referenceOne, MessageReference referenceTwo) {
|
||||
assertFalse(referenceOne.equals(referenceTwo));
|
||||
assertFalse(referenceTwo.equals(referenceOne));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user