KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > validation > util > DisplayTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.validation.util;
21
22 import junit.framework.*;
23 import org.netbeans.modules.j2ee.sun.validation.constraints.ConstraintFailure;
24
25 import java.util.ArrayList JavaDoc;
26
27
28 /**
29  *
30  * @author Rajeshwar Patil
31  * @version %I%, %G%
32  */

33
34 public class DisplayTest extends TestCase{
35     /* A class implementation comment can go here. */
36
37     public DisplayTest(String JavaDoc name){
38         super(name);
39     }
40
41
42     public static void main(String JavaDoc args[]){
43         junit.textui.TestRunner.run(suite());
44     }
45
46
47     public void testText() {
48         CustomDisplay display = new CustomDisplay();
49
50         
51         ArrayList JavaDoc failureMessages = new ArrayList JavaDoc();
52         ConstraintFailure failure_abc =
53             new ConstraintFailure("abc failed", "value_abc", //NOI18N
54
"name_abc", "failureMessage_abc", //NOI18N
55
"genericFailureMessage_abc"); //NOI18N
56
ConstraintFailure failure_xyz =
57             new ConstraintFailure("constraint_xyz", "value_xyz", //NOI18N
58
"name_xyz", "failureMessage_xyz", //NOI18N
59
"genericFailureMessage_xyz"); //NOI18N
60
failureMessages.add(failure_abc);
61         failureMessages.add(failure_xyz);
62         display.text(failureMessages);
63
64         //test to make sure text() reports error, if the Collection it is
65
//processing has objects that are not of type Failure.
66
ArrayList JavaDoc failures = new ArrayList JavaDoc();
67         failures.add(new Integer JavaDoc(5));
68         failures.add("failure_message"); //NOI18N
69
display.text(failures);
70     }
71
72
73     /**
74      * Define suite of all the Tests to run.
75      */

76     public static Test suite(){
77         TestSuite suite = new TestSuite(DisplayTest.class);
78         return suite;
79     }
80
81
82     /**
83      * Initialize; allocate any resources needed to perform Tests.
84      */

85     protected void setUp() {
86     }
87
88
89     /**
90      * Free all the resources initilized/allocated to perform Tests.
91      */

92     protected void tearDown() {
93     }
94
95
96     private void nyi() {
97         ///fail("Not yet implemented"); //NOI18N
98
}
99     
100     class CustomDisplay extends Display
101     {
102         CustomDisplay(){
103             super();
104         }
105
106         protected void reportFailure(String JavaDoc message){
107             assertTrue((message.equals("failureMessage_abc")) //NOI18N
108
||(message.equals("failureMessage_xyz"))); //NOI18N
109
}
110
111         protected void reportError(Object JavaDoc object){
112             Class JavaDoc classObject = object.getClass();
113             String JavaDoc objectType = classObject.getName();
114             assertTrue((objectType.equals("java.lang.Integer")) //NOI18N
115
||(objectType.equals("java.lang.String"))); //NOI18N
116
}
117     }
118 }
119
Popular Tags