KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > debug > DebugWatchDataTest


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2006 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 /*BEGIN_COPYRIGHT_BLOCK
35  *
36  * This file is a part of DrJava. Current versions of this project are available
37  * at http://sourceforge.net/projects/drjava
38  *
39  * Copyright (C) 2001-2002 JavaPLT group at Rice University (javaplt@rice.edu)
40  *
41  * DrJava is free software; you can redistribute it and/or modify
42  * it under the terms of the GNU General Public License as published by
43  * the Free Software Foundation; either version 2 of the License, or
44  * (at your option) any later version.
45  *
46  * DrJava is distributed in the hope that it will be useful,
47  * but WITHOUT ANY WARRANTY; without even the implied warranty of
48  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49  * GNU General Public License for more details.
50  *
51  * You should have received a copy of the GNU General Public License
52  * along with this program; if not, write to the Free Software
53  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
54  * or see http://www.gnu.org/licenses/gpl.html
55  *
56  * In addition, as a special exception, the JavaPLT group at Rice University
57  * (javaplt@rice.edu) gives permission to link the code of DrJava with
58  * the classes in the gj.util package, even if they are provided in binary-only
59  * form, and distribute linked combinations including the DrJava and the
60  * gj.util package. You must obey the GNU General Public License in all
61  * respects for all of the code used other than these classes in the gj.util
62  * package: Dictionary, HashtableEntry, ValueEnumerator, Enumeration,
63  * KeyEnumerator, Vector, Hashtable, Stack, VectorEnumerator.
64  *
65  * If you modify this file, you may extend this exception to your version of the
66  * file, but you are not obligated to do so. If you do not wish to
67  * do so, delete this exception statement from your version. (However, the
68  * present version of DrJava depends on these classes, so you'd want to
69  * remove the dependency first!)
70  *
71 END_COPYRIGHT_BLOCK*/

72
73 package edu.rice.cs.drjava.model.debug;
74
75 import edu.rice.cs.drjava.DrJavaTestCase;
76
77 /**
78  * Tests that the DebugWatchData class can display state correctly.
79  * @version $Id: DebugWatchDataTest.java 4031 2006-11-15 22:09:06Z rcartwright $
80  */

81 public final class DebugWatchDataTest extends DrJavaTestCase {
82  
83   /**
84    * Tests the state of a watch after its creation.
85    */

86   public void testFirstCreation() {
87     DebugWatchData data = new DebugWatchData("foo");
88     assertEquals("should have a name on startUp",
89                  "foo", data.getName());
90     assertEquals("should have no value on startUp",
91                  "", data.getValue());
92     assertEquals("should have no type on startUp",
93                  "", data.getType());
94     assertTrue("should not be changed on startUp", !data.isChanged());
95   }
96   
97   /**
98    * Tests that a watch displays its value and type correctly,
99    * then hides it when the thread resumes. Also tests that
100    * the changed flag works correctly.
101    */

102   public void testInScopeThenCleared() {
103     DebugWatchData data = new DebugWatchData("foo");
104
105     // Set value and type
106
data.setValue(new Integer JavaDoc(7));
107     data.setType("java.lang.Integer");
108     assertEquals("should have a value", "7", data.getValue());
109     assertEquals("should have a type", "java.lang.Integer", data.getType());
110     assertTrue("should be changed", data.isChanged());
111     
112     // Hide value and type
113
data.hideValueAndType();
114     assertEquals("should have no value after hide",
115                  "", data.getValue());
116     assertEquals("should have no type after hide",
117                  "", data.getType());
118     assertTrue("should not be changed after hide", !data.isChanged());
119     
120     // Make sure using same value doesn't indicate a change
121
data.setValue(new Integer JavaDoc(7));
122     assertTrue("should not be changed after setting same value",
123                !data.isChanged());
124     
125     // Make sure using a new value indicates a change
126
data.setValue(new Integer JavaDoc(8));
127     assertTrue("should be changed after setting different value",
128                data.isChanged());
129   }
130   
131   /**
132    * Tests that a watch displays correctly if it is not in scope.
133    */

134   public void testNotInScope() {
135     DebugWatchData data = new DebugWatchData("bar");
136     data.setNoValue();
137     data.setNoType();
138     
139     assertEquals("should not be in scope",
140                  DebugWatchData.NO_VALUE, data.getValue());
141     assertEquals("should not have a type",
142                  DebugWatchData.NO_TYPE, data.getType());
143     assertTrue("should not appear changed", !data.isChanged());
144   }
145   
146   
147 }
Popular Tags