1 19 package org.netbeans.api.sendopts; 20 21 import java.io.PrintWriter ; 22 import java.io.StringWriter ; 23 import java.util.Map ; 24 import java.util.regex.Matcher ; 25 import java.util.regex.Pattern ; 26 import junit.framework.TestCase; 27 import org.netbeans.modules.sendopts.OptionImpl; 28 import org.netbeans.spi.sendopts.Env; 29 import org.netbeans.spi.sendopts.Option; 30 31 35 public class ShortDescriptionTest extends TestCase implements Processor { 36 private Option help; 37 private Option descr; 38 39 public ShortDescriptionTest(String s) { 40 super(s); 41 } 42 43 private void setUpHelp() throws Exception { 44 Provider.clearAll(); 45 help = Option.withoutArgument('h', "help"); 46 Provider.add(this, help); 47 } 48 49 private void setUpShort() { 50 Provider.clearAll(); 51 help = Option.withoutArgument('h', "help"); 52 descr = Option.shortDescription(help, "org.netbeans.api.sendopts.TestBundle", "HELP"); 53 assertEquals("Option with description is the same", help, descr); 54 assertEquals("Option with description has the same hashCode", help.hashCode(), descr.hashCode()); 55 Provider.add(this, descr); 56 } 57 58 public void testPrintedUsage() throws Exception { 59 setUpHelp(); 60 61 StringWriter w = new StringWriter (); 62 PrintWriter pw = new PrintWriter (w); 63 64 CommandLine.getDefault().usage(pw); 65 66 Matcher m = Pattern.compile("-h.*--help").matcher(w.toString()); 67 if (!m.find()) { 68 fail("-h, --help should be there:\n" + w.toString()); 69 } 70 71 assertEquals("No help associated", w.toString().indexOf("shorthelp"), -1); 72 } 73 public void testPrintedUsageEiyhFrdvtipyion() throws Exception { 74 setUpShort(); 75 76 StringWriter w = new StringWriter (); 77 PrintWriter pw = new PrintWriter (w); 78 79 CommandLine.getDefault().usage(pw); 80 81 Matcher m = Pattern.compile("-h.*--help").matcher(w.toString()); 82 if (!m.find()) { 83 fail("-h, --help should be there:\n" + w.toString()); 84 } 85 86 if (w.toString().indexOf("shorthelp") == -1) { 87 fail("shorthelp associated: " + w.toString()); 88 } 89 } 90 public void testProvidedOwnDisplayName() throws Exception { 91 Provider.clearAll(); 92 help = Option.withoutArgument('h', "help"); 93 Option shor = Option.shortDescription(help, "org.netbeans.api.sendopts.TestBundle", "HELP"); 94 assertEquals("Option with description is the same", help, shor); 95 assertEquals("Option with description has the same hashCode", help.hashCode(), shor.hashCode()); 96 descr = Option.displayName(shor, "org.netbeans.api.sendopts.TestBundle", "NAMEHELP"); 97 assertEquals("Option with description is the same", help, descr); 98 assertEquals("Option with description has the same hashCode", help.hashCode(), descr.hashCode()); 99 Provider.add(this, descr); 100 101 StringWriter w = new StringWriter (); 102 PrintWriter pw = new PrintWriter (w); 103 104 CommandLine.getDefault().usage(pw); 105 106 Matcher m = Pattern.compile("-p.*--pomoc").matcher(w.toString()); 107 if (!m.find()) { 108 fail("--pomoc should be there:\n" + w.toString()); 109 } 110 111 if (w.toString().indexOf("shorthelp") == -1) { 112 fail("shorthelp associated: " + w.toString()); 113 } 114 } 115 116 public void process(Env env, Map <Option, String []> values) throws CommandException { 117 } 118 119 } 120 121 | Popular Tags |