package com.fsck.k9.activity;


import android.support.test.runner.AndroidJUnit4;

import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.MessagingException;
import org.junit.Test;
import org.junit.runner.RunWith;

import static junit.framework.Assert.assertEquals;
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.)
     */
    @Test
    public void checkIdentityStringFromMessageReferenceWithoutFlag() {
        MessageReference mr = new MessageReference();
        mr.accountUuid = "o hai!";
        mr.folderName = "folder";
        mr.uid = "10101010";

        assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=", mr.toIdentityString());
    }

    /**
     * Typically happens during replies.
     */
    @Test
    public void checkIdentityStringFromMessageReferenceWithFlag() {
        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());
    }

    @Test
    public void parseIdentityStringWithoutFlag() 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);
    }

    @Test
    public void parseIdentityStringWithFlag() 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);
    }

    @Test
    public void parseIdentityStringContainingBadVersionNumber() throws MessagingException {
        MessageReference mr = new MessageReference("@:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED");
        assertNull(mr.accountUuid);
    }

    @Test(expected = MessagingException.class)
    public void parseNullIdentityString() throws MessagingException {
        new MessageReference(null);
    }

    @Test(expected = MessagingException.class)
    public void parseIdentityStringWithCorruptFlag() throws MessagingException {
        // Corruption in the Flag should throw MessagingException.
        new MessageReference("!:%^&%^*$&$by&(BYWkh:Zm9%^@sZGVy:MT-35#$AxMDEwMTA=:ANSWE!RED");
    }

    @Test
    public void equalsWithAnObjectShouldReturnFalse() {
        // A MessageReference :
        MessageReference m = new MessageReference();
        // And another Object :
        Object o = new Object();
        // Asserting it is not equals, as not an instance of MessageReference:
        assertFalse(m.equals(o));
    }

    @Test
    public void equalsWithMessageReferenceContainingSameDataShouldReturnTrue() {
        // First MessageReference :
        MessageReference m1 = new MessageReference();
        m1.accountUuid = "acc1";
        m1.folderName = "folder1";
        m1.uid = "uid1";
        // Same MessageReference than m1 :
        MessageReference m2 = new MessageReference();
        m2.accountUuid = "acc1";
        m2.folderName = "folder1";
        m2.uid = "uid1";

        assertTrue(m1.equals(m2));
        assertTrue(m2.equals(m1));
    }

    @Test
    public void equalsWithMessageReferenceContainingDifferentAccountUuidShouldReturnFalse() {
        // First MessageReference :
        MessageReference m1 = new MessageReference();
        m1.accountUuid = "acc1";
        // A MessageReference with another accountUuid :
        MessageReference m2 = new MessageReference();
        m2.accountUuid = "acc2";

        assertFalse(m1.equals(m2));
        assertFalse(m2.equals(m1));
    }

    @Test
    public void equalsWithMessageReferenceContainingDifferentFolderNameShouldReturnFalse() {
        // First MessageReference :
        MessageReference m1 = new MessageReference();
        m1.folderName = "folder1";
        // A MessageReference with another folderName :
        MessageReference m2 = new MessageReference();
        m2.folderName = "folder2";

        assertFalse(m1.equals(m2));
        assertFalse(m2.equals(m1));
    }

    @Test
    public void equalsWithMessageReferenceContainingDifferentUidShouldReturnFalse() {
        // First MessageReference :
        MessageReference m1 = new MessageReference();
        m1.uid = "uid1";
        // A MessageReference with another uid :
        MessageReference m2 = new MessageReference();
        m2.uid = "uid2";

        assertFalse(m1.equals(m2));
        assertFalse(m2.equals(m1));
    }
}

@@ -478,162 +478,9 @@
 t %7B%0A
-    /**%0A     * Typically happens during forwards.  (You have a reference, but no flag since we don't currently consider%0A     * FORWARDED a flag.)%0A     */
 %0A
+
     
@@ -801,65 +801,8 @@
  %7D%0A%0A
-    /**%0A     * Typically happens during replies.%0A     */%0A
     
@@ -2411,75 +2411,8 @@
 n %7B%0A
-        // Corruption in the Flag should throw MessagingException.%0A
     
@@ -2578,40 +2578,8 @@
 ) %7B%0A
-        // A MessageReference :%0A
     
@@ -2631,40 +2631,8 @@
 ();%0A
-        // And another Object :%0A
     
@@ -2664,87 +2664,8 @@
 ();%0A
-        // Asserting it is not equals, as not an instance of MessageReference:%0A
     
@@ -2796,44 +2796,8 @@
 ) %7B%0A
-        // First MessageReference :%0A
     
@@ -2943,51 +2943,9 @@
 1%22;%0A
-        // Same MessageReference than m1 :
 %0A
+
     
@@ -3273,44 +3273,8 @@
 ) %7B%0A
-        // First MessageReference :%0A
     
@@ -3360,65 +3360,9 @@
 1%22;%0A
-        // A MessageReference with another accountUuid :
 %0A
+
     
@@ -3631,44 +3631,8 @@
 ) %7B%0A
-        // First MessageReference :%0A
     
@@ -3720,64 +3720,9 @@
 1%22;%0A
-        // A MessageReference with another folderName :
 %0A
+
     
@@ -3986,44 +3986,8 @@
 ) %7B%0A
-        // First MessageReference :%0A
     
@@ -4065,56 +4065,8 @@
 1%22;%0A
-        // A MessageReference with another uid :
 %0A   

Remove comments