FileDocCategorySizeDatePackage
CommandLineProcessorTest.javaAPI DocAndroid 1.5 API6699Wed May 06 22:41:10 BST 2009com.android.sdkmanager

CommandLineProcessorTest

public class CommandLineProcessorTest extends TestCase

Fields Summary
private MockStdLogger
mLog
Constructors Summary
Methods Summary
protected voidsetUp()

        mLog = new MockStdLogger();
        super.setUp();
    
protected voidtearDown()

        super.tearDown();
    
public final voidtestHelp()

        MockCommandLineProcessor c = new MockCommandLineProcessor(mLog);        

        c.parseArgs(new String[] { "-h" });
        assertTrue(c.wasExitCalled());
        assertTrue(c.wasHelpCalled());
        assertTrue(c.getStdErr().indexOf("Missing verb name.") == -1);

        c = new MockCommandLineProcessor(mLog);        
        c.parseArgs(new String[] { "--help" });
        assertTrue(c.wasExitCalled());
        assertTrue(c.wasHelpCalled());
        assertTrue(c.getStdErr().indexOf("Missing verb name.") == -1);
    
public final voidtestMandatory()

        MockCommandLineProcessor c = new MockCommandLineProcessor(mLog);        

        c.parseArgs(new String[] { "verb1", "action1", "-1", "value1", "-2", "value2" });
        assertFalse(c.wasExitCalled());
        assertFalse(c.wasHelpCalled());
        assertEquals("", c.getStdErr());
        assertEquals("value1", c.getValue("verb1", "action1", "first"));
        assertEquals("value2", c.getValue("verb1", "action1", "second"));

        c = new MockCommandLineProcessor(mLog);        
        c.parseArgs(new String[] { "verb1", "action1", "-2", "value2" });
        assertFalse(c.wasExitCalled());
        assertFalse(c.wasHelpCalled());
        assertEquals("", c.getStdErr());
        assertEquals(null, c.getValue("verb1", "action1", "first"));
        assertEquals("value2", c.getValue("verb1", "action1", "second"));

        c = new MockCommandLineProcessor(mLog);        
        c.parseArgs(new String[] { "verb1", "action1" });
        assertTrue(c.wasExitCalled());
        assertTrue(c.wasHelpCalled());
        assertTrue(c.getStdErr().indexOf("must be defined") != -1);
        assertEquals(null, c.getValue("verb1", "action1", "first"));
        assertEquals(null, c.getValue("verb1", "action1", "second"));
    
public final voidtestPrintHelpAndExit()

        MockCommandLineProcessor c = new MockCommandLineProcessor(mLog);        
        assertFalse(c.wasExitCalled());
        assertFalse(c.wasHelpCalled());
        assertTrue(c.getStdOut().equals(""));
        assertTrue(c.getStdErr().equals(""));
        c.printHelpAndExit(null);
        assertTrue(c.getStdOut().indexOf("-v") != -1);
        assertTrue(c.getStdOut().indexOf("--verbose") != -1);
        assertTrue(c.getStdErr().equals(""));
        assertTrue(c.wasExitCalled());

        c = new MockCommandLineProcessor(mLog);        
        assertFalse(c.wasExitCalled());
        assertTrue(c.getStdOut().equals(""));
        assertTrue(c.getStdErr().indexOf("Missing parameter") == -1);

        c.printHelpAndExit("Missing %s", "parameter");
        assertTrue(c.wasExitCalled());
        assertFalse(c.getStdOut().equals(""));
        assertTrue(c.getStdErr().indexOf("Missing parameter") != -1);
    
public final voidtestVerbose()

        MockCommandLineProcessor c = new MockCommandLineProcessor(mLog);        

        assertFalse(c.isVerbose());
        c.parseArgs(new String[] { "-v" });
        assertTrue(c.isVerbose());
        assertTrue(c.wasExitCalled());
        assertTrue(c.wasHelpCalled());
        assertTrue(c.getStdErr().indexOf("Missing verb name.") != -1);

        c = new MockCommandLineProcessor(mLog);        
        c.parseArgs(new String[] { "--verbose" });
        assertTrue(c.isVerbose());
        assertTrue(c.wasExitCalled());
        assertTrue(c.wasHelpCalled());
        assertTrue(c.getStdErr().indexOf("Missing verb name.") != -1);