KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > sendopts > DefineRefineIgnoreTest


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 package org.netbeans.api.sendopts;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23 import junit.framework.TestCase;
24 import org.netbeans.spi.sendopts.OptionGroups;
25 import org.netbeans.spi.sendopts.Env;
26 import org.netbeans.spi.sendopts.Option;
27
28 /** Various types of processor and option closures tested.
29  *
30  * @author Jaroslav Tulach
31  */

32 public class DefineRefineIgnoreTest extends TestCase {
33     private OneArgProc proc = new OneArgProc();
34     private Option define;
35     private Option refine;
36     private Option ignore;
37     private Option files;
38     
39     public DefineRefineIgnoreTest(String JavaDoc s) {
40         super(s);
41     }
42
43     protected void tearDown() throws Exception JavaDoc {
44         super.tearDown();
45     }
46
47     protected void setUp() throws Exception JavaDoc {
48         Provider.clearAll();
49         
50         define = Option.optionalArgument('D', "define");
51         refine = Option.requiredArgument('R', "refine");
52         ignore = Option.withoutArgument('I', "ignore");
53         files = Option.additionalArguments('F', "files");
54     }
55     
56     public void testDefineRefinePair() throws CommandException {
57         Option pair = OptionGroups.allOf(define, refine);
58         Provider.add(proc, pair);
59             
60         CommandLine l = CommandLine.getDefault();
61         l.process(new String JavaDoc[] { "--define=1", "--refine", "2" });
62         
63         assertEquals("V1", "1", proc.clone.get(define)[0]);
64         assertEquals("V2", "2", proc.clone.get(refine)[0]);
65     }
66     
67     public void testWithoutAdditonal() throws CommandException {
68         Option pair = OptionGroups.allOf(ignore, files);
69         Provider.add(proc, pair);
70             
71         CommandLine l = CommandLine.getDefault();
72         l.process(new String JavaDoc[] { "--ignore", "--files", "30" });
73         
74         assertTrue("V1", proc.clone.containsKey(ignore));
75         assertEquals("V2", "30", proc.clone.get(files)[0]);
76     }
77     
78     static final class OneArgProc implements Processor {
79         Map JavaDoc<Option, String JavaDoc[]> clone;
80         
81         public void process(Env env, Map JavaDoc<Option, String JavaDoc[]> values) throws CommandException {
82             assertNull("No clone yet", clone);
83             clone = new HashMap JavaDoc<Option, String JavaDoc[]>(values);
84         }
85     }
86 }
87
Popular Tags