KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > TestOptions


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16  
17 package org.apache.commons.betwixt;
18
19 import junit.framework.TestCase;
20
21 /**
22  * @author <a HREF='http://jakarta.apache.org/'>Jakarta Commons Team</a>
23  * @version $Revision: 1.1 $
24  */

25 public class TestOptions extends TestCase {
26     
27     private static final int A_SHIFT = 1 << 0;
28     private static final int B_SHIFT = 1 << 1;
29     private static final int C_SHIFT = 1 << 2;
30     
31     
32     public void testGetValue() {
33         Options options = new Options();
34         options.addOption("A", "Alpha");
35         options.addOption("B", "Beta");
36        
37         assertEquals("Get added value", "Alpha", options.getValue("A"));
38         assertNull("Value not added is null", options.getValue("C"));
39         
40         options.addOption("A", "New Value");
41         assertEquals("Lat value set wins", "New Value", options.getValue("A"));
42     }
43     
44     public void testGetNames() {
45         Options options = new Options();
46         options.addOption("A", "Alpha");
47         options.addOption("B", "Beta");
48         options.addOption("C", "Gamma");
49         
50         String JavaDoc[] names = options.getNames();
51         assertEquals("Expected three names", 3, names.length);
52         int flag = (A_SHIFT) + (B_SHIFT) + (C_SHIFT);
53         for ( int i = 0; i <3 ; i++ ) {
54             if (names[i].equals("A"))
55             {
56                 assertTrue("A named twice", (flag & (A_SHIFT))>0);
57                 flag -= (A_SHIFT);
58             }
59             else if (names[i].equals("B"))
60             {
61                 assertTrue("B named twice", (flag & (B_SHIFT))>0);
62                 flag -= (B_SHIFT);
63             }
64             else if (names[i].equals("C"))
65             {
66                 assertTrue("C named twice", (flag & (C_SHIFT))>0);
67                 flag -= (C_SHIFT);
68             }
69             else
70             {
71                 fail("Unexpected name: " + names[i]);
72             }
73         }
74     }
75     
76 }
77
Popular Tags