KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > ristretto > message > FlagsTest


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Ristretto Mail API.
15  *
16  * The Initial Developers of the Original Code are
17  * Timo Stich and Frederik Dietz.
18  * Portions created by the Initial Developers are Copyright (C) 2004
19  * All Rights Reserved.
20  *
21  * Contributor(s):
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPL"), or
25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26  * in which case the provisions of the GPL or the LGPL are applicable instead
27  * of those above. If you wish to allow use of your version of this file only
28  * under the terms of either the GPL or the LGPL, and not to allow others to
29  * use your version of this file under the terms of the MPL, indicate your
30  * decision by deleting the provisions above and replace them with the notice
31  * and other provisions required by the GPL or the LGPL. If you do not delete
32  * the provisions above, a recipient may use your version of this file under
33  * the terms of any one of the MPL, the GPL or the LGPL.
34  *
35  * ***** END LICENSE BLOCK ***** */

36 package org.columba.ristretto.message;
37
38 import junit.framework.TestCase;
39
40 public class FlagsTest extends TestCase {
41
42     /**
43      * Constructor for FlagsTest.
44      *
45      * @param arg0 name of test.
46      */

47     public FlagsTest(String JavaDoc 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     /**
79      * Test the equals() method.
80      */

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 JavaDoc(4)));
102     }
103
104     /**
105      * Test the hashcode() method.
106      */

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     /**
127      * Test the clone() method.
128      *
129      */

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