1 19 package org.netbeans.api.sendopts; 20 21 import java.util.HashMap ; 22 import java.util.Map ; 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 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 s) { 40 super(s); 41 } 42 43 protected void tearDown() throws Exception { 44 super.tearDown(); 45 } 46 47 protected void setUp() throws Exception { 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 [] { "--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 [] { "--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 <Option, String []> clone; 80 81 public void process(Env env, Map <Option, String []> values) throws CommandException { 82 assertNull("No clone yet", clone); 83 clone = new HashMap <Option, String []>(values); 84 } 85 } 86 } 87 | Popular Tags |