1 //----------------------------------------------------------------------
2 //
3 // PerfectJPattern: "Design patterns are good but components are better!"
4 // TestProgressData.java Copyright (c) 2009 Giovanni Azua Garcia
5 // bravegag@hotmail.com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 3
10 // of the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, see <http://www.gnu.org/licenses/>.
19 //
20 //----------------------------------------------------------------------
21 package org.perfectjpattern.core.behavioral.observer.data;
22
23 import junit.framework.*;
24
25 /**
26 * Test Suite for <code>ProgressData</code> implementation.
27 *
28 * @see ProgressData
29 *
30 * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
31 * @version $Revision: 1.0 $ $Date: Jun 23, 2007 1:23:01 AM $
32 */
33 public final
34 class TestProgressData
35 extends TestCase
36 {
37 //------------------------------------------------------------------------
38 // public
39 //------------------------------------------------------------------------
40 public void
41 testValueOf()
42 {
43 ProgressData myInstanceOne = new ProgressData(Status.STARTED,
44 "There was a time", 0);
45 ProgressData myInstanceTwo = new ProgressData(myInstanceOne);
46
47 assertEquals("valueOf implemented incorrectly", myInstanceOne,
48 myInstanceTwo);
49 }
50
51 //------------------------------------------------------------------------
52 public void
53 testEquals()
54 {
55 assertEquals("Equals implemented incorrectly", ProgressData.STARTED,
56 new ProgressData(Status.STARTED, "Task has started.", 0));
57
58 assertTrue("Equals implemented incorrectly",
59 !ProgressData.STARTED.equals(ProgressData.COMPLETED));
60
61 assertTrue("equals() implemented incorrectly",
62 !ProgressData.STARTED.equals(StatusData.STARTED));
63 }
64
65 //------------------------------------------------------------------------
66 public void
67 testHashcode()
68 {
69 // same hash code => equals true
70 assertTrue("hashCode() implemented incorrectly",
71 ProgressData.STARTED.hashCode() ==
72 ProgressData.STARTED.hashCode() &&
73 ProgressData.STARTED.equals(ProgressData.STARTED));
74
75 ProgressData myData =
76 new ProgressData(Status.STARTED, "Task has started.", 0);
77
78 // different hash code may still hold equals true
79 assertTrue("hashCode() implemented incorrectly",
80 ProgressData.STARTED.hashCode() == myData.hashCode() &&
81 ProgressData.STARTED.equals(myData));
82
83 // equals false => different hash code
84 assertTrue("hashCode() implemented incorrectly",
85 !ProgressData.COMPLETED.equals(myData) &&
86 ProgressData.COMPLETED.hashCode() != myData.hashCode());
87 }
88
89 //------------------------------------------------------------------------
90 public void
91 testToString()
92 {
93 assertEquals("toString() implemented incorrectly",
94 ProgressData.STARTED.toString(),
95 "ProgressData(StatusData(Status='Started', " +
96 "Message='Task has started.'), Progress='0%')");
97 }
98 }