1 36 package org.columba.ristretto.message; 37 38 import junit.framework.TestCase; 39 40 public class FlagsTest extends TestCase { 41 42 47 public FlagsTest(String arg0) { 48 super(arg0); 49 } 50 51 public void testGet() { 52 Flags testFlags = new Flags(); 53 assertFalse(testFlags.get(Flags.ANSWERED)); 54 assertFalse(testFlags.get(Flags.SEEN)); 55 assertFalse(testFlags.get(Flags.FLAGGED)); 56 } 57 58 public void testSet() { 59 Flags testFlags = new Flags(); 60 testFlags.set(Flags.ANSWERED); 61 assertTrue("The flag wasnt set correctly.", testFlags.get(Flags.ANSWERED)); 62 } 63 64 public void testClear() { 65 Flags testFlags = new Flags(); 66 testFlags.set(Flags.ANSWERED); 67 testFlags.clear(Flags.ANSWERED); 68 assertFalse(testFlags.get(Flags.ANSWERED)); 69 } 70 71 public void testToggle() { 72 Flags testFlags = new Flags(); 73 testFlags.set(Flags.ANSWERED); 74 testFlags.toggle(Flags.ANSWERED); 75 assertFalse(testFlags.get(Flags.ANSWERED)); 76 } 77 78 81 public void testEquals() { 82 Flags expected = new Flags(); 83 expected.setAnswered(true); 84 expected.setDraft(false); 85 expected.setFlagged(true); 86 87 Flags actual = new Flags(); 88 actual.setAnswered(true); 89 actual.setDraft(false); 90 actual.setFlagged(true); 91 assertTrue("The equals() method returned false, when the objects were equal", actual.equals(expected)); 92 assertTrue("The equals() method returned false, when the objects were equal", expected.equals(actual)); 93 assertFalse("The objects are equal though one is null", expected.equals(null)); 94 95 actual = new Flags(); 96 actual.setAnswered(true); 97 actual.setDraft(true); 98 actual.setFlagged(true); 99 assertFalse("The equals() method returned true, when the objects were unequal", actual.equals(expected)); 100 assertFalse("The equals() method returned true, when the objects were unequal", expected.equals(actual)); 101 assertFalse("The equals() method returned true, when the objects were of different types", expected.equals(new Integer (4))); 102 } 103 104 107 public void testHashCode() { 108 Flags expected = new Flags(); 109 expected.setAnswered(true); 110 expected.setDraft(false); 111 expected.setFlagged(true); 112 113 Flags actual = new Flags(); 114 actual.setAnswered(true); 115 actual.setDraft(false); 116 actual.setFlagged(true); 117 assertEquals("The hashCode() returned differnt value for equal objects.", expected.hashCode(), actual.hashCode()); 118 119 actual = new Flags(); 120 actual.setAnswered(true); 121 actual.setDraft(true); 122 actual.setFlagged(true); 123 assertTrue("The hashCode() returned same value for unequal objects", actual.hashCode() != expected.hashCode()); 124 } 125 126 130 public void testClone() { 131 132 Flags expected = new Flags(); 133 expected.setAnswered(true); 134 expected.setDraft(false); 135 expected.setFlagged(true); 136 137 Flags actual = (Flags) expected.clone(); 138 assertNotSame("The object is the same object after a clone", expected, actual); 139 assertEquals("The objects are not equal", expected, actual); 140 assertEquals("The object's flags are not equal", expected.getFlags(), actual.getFlags()); 141 } 142 } 143 | Popular Tags |