1 19 package org.netbeans.api.sendopts; 20 21 import java.util.Collections ; 22 import java.util.Map ; 23 import java.util.Set ; 24 import junit.framework.TestCase; 25 import org.netbeans.junit.MockServices; 26 import org.netbeans.spi.sendopts.OptionGroups; 27 import org.netbeans.spi.sendopts.Env; 28 import org.netbeans.spi.sendopts.Option; 29 import org.netbeans.spi.sendopts.OptionProcessor; 30 31 35 public class MasterTest extends TestCase { 36 37 static final Option SHARED = Option.requiredArgument(Option.NO_SHORT_NAME, "shared"); 38 39 public MasterTest(String s) { 40 super(s); 41 } 42 43 protected void setUp() throws Exception { 44 MockServices.setServices(P1.class); 45 } 46 47 public void testSharedSelected() throws Exception { 48 try { 49 CommandLine.getDefault().process(new String [] { "--shared", "Ahoj" }); 50 fail("Should fail with CommandException"); 51 } catch (CommandException ex) { 52 if (ex.getExitCode() == 1) { 53 fail("Real working that p1 needs to be used shall be printed"); 54 } 55 } 56 } 57 public void testP1() throws Exception { 58 try { 59 CommandLine.getDefault().process(new String [] { "--p1" }); 60 fail("Should fail with CommandException thrown during processing of our OptionProcessor"); 61 } catch (CommandException ex) { 62 if (ex.getExitCode() != 1) { 63 throw ex; 64 } 65 } 66 } 67 public void testNothing() throws Exception { 68 CommandLine.getDefault().process(new String [] { }); 69 } 70 public void testAll() throws Exception { 71 try { 72 CommandLine.getDefault().process(new String [] { "--shared", "ble", "--p1" }); 73 fail("Should fail with CommandException thrown during processing of our OptionProcessor"); 74 } catch (CommandException ex) { 75 if (ex.getExitCode() != 1) { 76 throw ex; 77 } 78 } 79 } 80 81 public static final class P1 extends OptionProcessor { 82 private static final Option P1 = Option.withoutArgument(Option.NO_SHORT_NAME, "p1"); 83 84 protected Set <Option> getOptions() { 85 return Collections.singleton(OptionGroups.allOf(P1, OptionGroups.anyOf(SHARED))); 86 } 87 88 protected void process(Env env, Map <Option, String []> optionValues) throws CommandException { 89 throw new CommandException(1); 91 } 92 } 93 } 94 95 | Popular Tags |