1 37 package net.sourceforge.cruisecontrol.util; 38 39 import junit.framework.TestCase; 40 41 public class MainArgsTest extends TestCase { 42 public void testParseArgs() throws Exception { 43 final String argName = "port"; 44 final String defaultIfNoParam = "8080"; 45 final String defaultIfNoValue = "8000"; 46 47 String [] args = { 49 }; 50 String foundValue = MainArgs.parseArgument(args, argName, defaultIfNoParam, defaultIfNoValue); 51 assertEquals(defaultIfNoParam, foundValue); 52 53 String setValue = "100"; 55 args = new String [] {"-port", setValue}; 56 foundValue = MainArgs.parseArgument(args, argName, defaultIfNoParam, defaultIfNoValue); 57 assertEquals(setValue, foundValue); 58 59 args = new String [] {"-port", setValue, "-throwAway", "value"}; 61 foundValue = MainArgs.parseArgument(args, argName, defaultIfNoParam, defaultIfNoValue); 62 assertEquals(setValue, foundValue); 63 64 args = new String [] {"-throwAway", "value", "-port", setValue}; 66 foundValue = MainArgs.parseArgument(args, argName, defaultIfNoParam, defaultIfNoValue); 67 assertEquals(setValue, foundValue); 68 69 args = new String [] {"-port"}; 71 foundValue = MainArgs.parseArgument(args, argName, defaultIfNoParam, defaultIfNoValue); 72 assertEquals(defaultIfNoValue, foundValue); 73 } 74 75 public void testArgumentPresent() { 76 String [] args = {"-port", "8000"}; 77 assertTrue(MainArgs.argumentPresent(args, "port")); 78 assertFalse(MainArgs.argumentPresent(args, "foo")); 79 80 assertFalse(MainArgs.argumentPresent(new String [0], "foo")); 81 82 } 83 } 84 | Popular Tags |