KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > validation > util > DisplayTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * DisplayTest.java June 16, 2003, 3:26 PM
26  *
27  */

28
29 package com.sun.enterprise.tools.common.validation.util;
30
31 import junit.framework.*;
32 import com.sun.enterprise.tools.common.validation.constraints.ConstraintFailure;
33
34 import java.util.ArrayList JavaDoc;
35
36
37 /**
38  *
39  * @author Rajeshwar Patil
40  * @version %I%, %G%
41  */

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

85     public static Test suite(){
86         TestSuite suite = new TestSuite(DisplayTest.class);
87         return suite;
88     }
89
90
91     /**
92      * Initialize; allocate any resources needed to perform Tests.
93      */

94     protected void setUp() {
95     }
96
97
98     /**
99      * Free all the resources initilized/allocated to perform Tests.
100      */

101     protected void tearDown() {
102     }
103
104
105     private void nyi() {
106         fail("Not yet implemented"); //NOI18N
107
}
108     
109     class CustomDisplay extends Display
110     {
111         CustomDisplay(){
112             super();
113         }
114
115         protected void reportFailure(String JavaDoc message){
116             assertTrue((message.equals("failureMessage_abc")) //NOI18N
117
||(message.equals("failureMessage_xyz"))); //NOI18N
118
}
119
120         protected void reportError(Object JavaDoc object){
121             Class JavaDoc classObject = object.getClass();
122             String JavaDoc objectType = classObject.getName();
123             assertTrue((objectType.equals("java.lang.Integer")) //NOI18N
124
||(objectType.equals("java.lang.String"))); //NOI18N
125
}
126     }
127 }
128
Popular Tags