1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Add helper methods to get more readable tests

This commit is contained in:
cketti 2015-02-23 02:41:57 +01:00
parent af491fdb41
commit a979accb54

View File

@ -19,47 +19,44 @@ public class MessageReferenceTest {
@Test @Test
public void checkIdentityStringFromMessageReferenceWithoutFlag() { public void checkIdentityStringFromMessageReferenceWithoutFlag() {
MessageReference mr = new MessageReference(); MessageReference messageReference = createMessageReference("o hai!", "folder", "10101010");
mr.accountUuid = "o hai!";
mr.folderName = "folder";
mr.uid = "10101010";
assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=", mr.toIdentityString()); assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=", messageReference.toIdentityString());
} }
@Test @Test
public void checkIdentityStringFromMessageReferenceWithFlag() { public void checkIdentityStringFromMessageReferenceWithFlag() {
MessageReference mr = new MessageReference(); MessageReference messageReference =
mr.accountUuid = "o hai!"; createMessageReferenceWithFlag("o hai!", "folder", "10101010", Flag.ANSWERED);
mr.folderName = "folder";
mr.uid = "10101010";
mr.flag = Flag.ANSWERED;
assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED", mr.toIdentityString()); assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED", messageReference.toIdentityString());
} }
@Test @Test
public void parseIdentityStringWithoutFlag() throws MessagingException { public void parseIdentityStringWithoutFlag() throws MessagingException {
MessageReference mr = new MessageReference("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA="); MessageReference messageReference = new MessageReference("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=");
assertEquals("o hai!", mr.accountUuid);
assertEquals("folder", mr.folderName); assertEquals("o hai!", messageReference.accountUuid);
assertEquals("10101010", mr.uid); assertEquals("folder", messageReference.folderName);
assertNull(mr.flag); assertEquals("10101010", messageReference.uid);
assertNull(messageReference.flag);
} }
@Test @Test
public void parseIdentityStringWithFlag() throws MessagingException { public void parseIdentityStringWithFlag() throws MessagingException {
MessageReference mr = new MessageReference("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED"); MessageReference messageReference = new MessageReference("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED");
assertEquals("o hai!", mr.accountUuid);
assertEquals("folder", mr.folderName); assertEquals("o hai!", messageReference.accountUuid);
assertEquals("10101010", mr.uid); assertEquals("folder", messageReference.folderName);
assertEquals(Flag.ANSWERED, mr.flag); assertEquals("10101010", messageReference.uid);
assertEquals(Flag.ANSWERED, messageReference.flag);
} }
@Test @Test
public void parseIdentityStringContainingBadVersionNumber() throws MessagingException { public void parseIdentityStringContainingBadVersionNumber() throws MessagingException {
MessageReference mr = new MessageReference("@:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED"); MessageReference messageReference = new MessageReference("@:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED");
assertNull(mr.accountUuid);
assertNull(messageReference.accountUuid);
} }
@Test(expected = MessagingException.class) @Test(expected = MessagingException.class)
@ -74,60 +71,71 @@ public class MessageReferenceTest {
@Test @Test
public void equalsWithAnObjectShouldReturnFalse() { public void equalsWithAnObjectShouldReturnFalse() {
MessageReference m = new MessageReference(); MessageReference messageReference = new MessageReference();
Object o = new Object(); Object object = new Object();
assertFalse(m.equals(o));
assertFalse(messageReference.equals(object));
} }
@Test @Test
public void equalsWithMessageReferenceContainingSameDataShouldReturnTrue() { public void equalsWithMessageReferenceContainingSameDataShouldReturnTrue() {
MessageReference m1 = new MessageReference(); MessageReference messageReferenceOne = createMessageReference("account", "folder", "uid");
m1.accountUuid = "acc1"; MessageReference messageReferenceTwo = createMessageReference("account", "folder", "uid");
m1.folderName = "folder1";
m1.uid = "uid1";
MessageReference m2 = new MessageReference(); assertEqualsReturnsTrueSymmetrically(messageReferenceOne, messageReferenceTwo);
m2.accountUuid = "acc1";
m2.folderName = "folder1";
m2.uid = "uid1";
assertTrue(m1.equals(m2));
assertTrue(m2.equals(m1));
} }
@Test @Test
public void equalsWithMessageReferenceContainingDifferentAccountUuidShouldReturnFalse() { public void equalsWithMessageReferenceContainingDifferentAccountUuidShouldReturnFalse() {
MessageReference m1 = new MessageReference(); MessageReference messageReferenceOne = createMessageReference("account", "folder", "uid");
m1.accountUuid = "acc1"; MessageReference messageReferenceTwo = createMessageReference("-------", "folder", "uid");
MessageReference m2 = new MessageReference(); assertEqualsReturnsFalseSymmetrically(messageReferenceOne, messageReferenceTwo);
m2.accountUuid = "acc2";
assertFalse(m1.equals(m2));
assertFalse(m2.equals(m1));
} }
@Test @Test
public void equalsWithMessageReferenceContainingDifferentFolderNameShouldReturnFalse() { public void equalsWithMessageReferenceContainingDifferentFolderNameShouldReturnFalse() {
MessageReference m1 = new MessageReference(); MessageReference messageReferenceOne = createMessageReference("account", "folder", "uid");
m1.folderName = "folder1"; MessageReference messageReferenceTwo = createMessageReference("account", "------", "uid");
MessageReference m2 = new MessageReference(); assertEqualsReturnsFalseSymmetrically(messageReferenceOne, messageReferenceTwo);
m2.folderName = "folder2";
assertFalse(m1.equals(m2));
assertFalse(m2.equals(m1));
} }
@Test @Test
public void equalsWithMessageReferenceContainingDifferentUidShouldReturnFalse() { public void equalsWithMessageReferenceContainingDifferentUidShouldReturnFalse() {
MessageReference m1 = new MessageReference(); MessageReference messageReferenceOne = createMessageReference("account", "folder", "uid");
m1.uid = "uid1"; MessageReference messageReferenceTwo = createMessageReference("account", "folder", "---");
MessageReference m2 = new MessageReference(); assertEqualsReturnsFalseSymmetrically(messageReferenceOne, messageReferenceTwo);
m2.uid = "uid2"; }
assertFalse(m1.equals(m2)); private MessageReference createMessageReference(String accountUuid, String folderName, String uid) {
assertFalse(m2.equals(m1)); 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));
} }
} }