1 /*
2 * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/FieldTest.java,v 1.3 2004/02/21 17:10:30 rleland Exp $
3 * $Revision: 1.3 $
4 * $Date: 2004/02/21 17:10:30 $
5 *
6 * ====================================================================
7 * Copyright 2001-2004 The Apache Software Foundation
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22 package org.apache.commons.validator;
23
24 import junit.framework.TestCase;
25
26 /***
27 * Test <code>Field</code> objects.
28 */
29 public class FieldTest extends TestCase {
30
31 /***
32 * FieldTest constructor.
33 */
34 public FieldTest() {
35 super();
36 }
37
38 /***
39 * FieldTest constructor.
40 * @param name
41 */
42 public FieldTest(String name) {
43 super(name);
44 }
45
46 public void testGetArgs() {
47 // Arg with a validator name
48 Arg a = new Arg();
49 a.setKey("my.resource.key");
50 a.setName("required");
51
52 // Arg without name so it will be stored under default name
53 Arg a2 = new Arg();
54 a2.setKey("another.resource.key");
55 a2.setPosition(1);
56
57 Field f = new Field();
58 // test empty args first
59 Arg[] emptyArgs = f.getArgs("required");
60 assertEquals(0, emptyArgs.length);
61
62 // add args for other tests
63 f.addArg(a);
64 f.addArg(a2);
65
66 // test arg lookup for "required" validator
67 Arg[] args = f.getArgs("required");
68 assertEquals(2, args.length);
69 assertTrue(args[0] == a);
70
71 // test arg lookup for non-existent "required2" validator
72 // should find default arg for position 1
73 Arg[] args2 = f.getArgs("required2");
74 assertEquals(2, args2.length);
75 assertNull(args2[0]); // we didn't define a 0 position arg
76 assertTrue(args2[1] == a2);
77
78 }
79
80 }
This page was automatically generated by Maven