1 19 package org.netbeans.api.sendopts; 20 21 import java.io.ByteArrayInputStream ; 22 import java.io.ByteArrayOutputStream ; 23 import java.io.File ; 24 import java.io.InputStream ; 25 import java.io.OutputStream ; 26 import java.io.PrintStream ; 27 import java.util.HashMap ; 28 import java.util.Map ; 29 import junit.framework.TestCase; 30 import org.netbeans.modules.sendopts.OptionImpl; 31 import org.netbeans.spi.sendopts.Env; 32 import org.netbeans.spi.sendopts.Option; 33 34 38 public class EnvTest extends TestCase { 39 private CommandLine l; 40 private OneArgProc proc = new OneArgProc(); 41 private Option define; 42 private Option refine; 43 private Option ignore; 44 private Option files; 45 46 public EnvTest(String s) { 47 super(s); 48 } 49 50 protected void tearDown() throws Exception { 51 52 super.tearDown(); 53 } 54 55 protected void setUp() throws Exception { 56 Provider.clearAll(); 57 58 define = Option.optionalArgument('D', "define"); 59 refine = Option.requiredArgument('R', "refine"); 60 ignore = Option.withoutArgument('I', "ignore"); 61 files = Option.additionalArguments('F', "files"); 62 63 Provider.add(proc, define, refine, ignore, files); 64 65 l = CommandLine.getDefault(); 66 } 67 68 public void testDefaultEnv() throws Exception { 69 proc.expIs = System.in; 70 proc.expOs = System.out; 71 proc.expErr = System.err; 72 proc.expDir = new File (System.getProperty("user.dir")); 73 74 l.process(new String [] { "-Dx", "-Ry", "-I", "-F", "somefile" }); 75 assertEquals("one checks", 1, proc.cnt); 76 assertEquals("but on four options", 4, proc.values.size()); 77 } 78 79 public void testOwnEnv() throws Exception { 80 proc.expIs = new ByteArrayInputStream (new byte[0]); 81 proc.expOs = new PrintStream (new ByteArrayOutputStream ()); 82 proc.expErr = new PrintStream (new ByteArrayOutputStream ()); 83 proc.expDir = new File ("c:/"); 84 85 l.process(new String [] { "-Dx", "-Ry", "-I", "-F", "somefile" }, proc.expIs, proc.expOs, proc.expErr, proc.expDir); 86 87 assertEquals("one check", 1, proc.cnt); 88 assertEquals("but on four options", 4, proc.values.size()); 89 } 90 91 static final class OneArgProc implements Processor { 92 InputStream expIs; 93 OutputStream expOs; 94 OutputStream expErr; 95 File expDir; 96 int cnt; 97 Map <Option,String []> values; 98 99 private void assertEnv(Env env) { 100 assertEquals(expIs, env.getInputStream()); 101 assertEquals(expOs, env.getOutputStream()); 102 assertEquals(expErr, env.getErrorStream()); 103 assertEquals(expDir, env.getCurrentDirectory()); 104 cnt++; 105 } 106 107 public void process(Env env, Map <Option, String []> values) throws CommandException { 108 assertEnv(env); 109 this.values = new HashMap <Option,String []>(values); 110 } 111 } 112 } 113 | Popular Tags |