auto import from //branches/cupcake/...@126645

This commit is contained in:
The Android Open Source Project
2009-01-15 16:12:07 -08:00
parent 95cf464c5a
commit b8d704a517
62 changed files with 1680 additions and 668 deletions

View File

@@ -16,11 +16,15 @@
package com.android.sdkmanager;
import com.android.sdklib.ISdkLog;
import junit.framework.TestCase;
public class CommandLineProcessorTest extends TestCase {
private MockStdLogger mLog;
/**
* A mock version of the {@link CommandLineProcessor} class that does not
* exits and captures its stdout/stderr output.
@@ -31,8 +35,9 @@ public class CommandLineProcessorTest extends TestCase {
private String mStdOut = "";
private String mStdErr = "";
public MockCommandLineProcessor() {
super(new String[][] {
public MockCommandLineProcessor(ISdkLog logger) {
super(logger,
new String[][] {
{ "action1", "Some action" },
{ "action2", "Another action" },
});
@@ -84,9 +89,10 @@ public class CommandLineProcessorTest extends TestCase {
return mStdErr;
}
}
@Override
protected void setUp() throws Exception {
mLog = new MockStdLogger();
super.setUp();
}
@@ -96,7 +102,7 @@ public class CommandLineProcessorTest extends TestCase {
}
public final void testPrintHelpAndExit() {
MockCommandLineProcessor c = new MockCommandLineProcessor();
MockCommandLineProcessor c = new MockCommandLineProcessor(mLog);
assertFalse(c.wasExitCalled());
assertFalse(c.wasHelpCalled());
assertTrue(c.getStdOut().equals(""));
@@ -107,7 +113,7 @@ public class CommandLineProcessorTest extends TestCase {
assertTrue(c.getStdErr().equals(""));
assertTrue(c.wasExitCalled());
c = new MockCommandLineProcessor();
c = new MockCommandLineProcessor(mLog);
assertFalse(c.wasExitCalled());
assertTrue(c.getStdOut().equals(""));
assertTrue(c.getStdErr().indexOf("Missing parameter") == -1);
@@ -119,7 +125,7 @@ public class CommandLineProcessorTest extends TestCase {
}
public final void testVerbose() {
MockCommandLineProcessor c = new MockCommandLineProcessor();
MockCommandLineProcessor c = new MockCommandLineProcessor(mLog);
assertFalse(c.isVerbose());
c.parseArgs(new String[] { "-v" });
@@ -128,7 +134,7 @@ public class CommandLineProcessorTest extends TestCase {
assertTrue(c.wasHelpCalled());
assertTrue(c.getStdErr().indexOf("Missing action name.") != -1);
c = new MockCommandLineProcessor();
c = new MockCommandLineProcessor(mLog);
c.parseArgs(new String[] { "--verbose" });
assertTrue(c.isVerbose());
assertTrue(c.wasExitCalled());
@@ -137,14 +143,14 @@ public class CommandLineProcessorTest extends TestCase {
}
public final void testHelp() {
MockCommandLineProcessor c = new MockCommandLineProcessor();
MockCommandLineProcessor c = new MockCommandLineProcessor(mLog);
c.parseArgs(new String[] { "-h" });
assertTrue(c.wasExitCalled());
assertTrue(c.wasHelpCalled());
assertTrue(c.getStdErr().indexOf("Missing action name.") == -1);
c = new MockCommandLineProcessor();
c = new MockCommandLineProcessor(mLog);
c.parseArgs(new String[] { "--help" });
assertTrue(c.wasExitCalled());
assertTrue(c.wasHelpCalled());
@@ -152,7 +158,7 @@ public class CommandLineProcessorTest extends TestCase {
}
public final void testMandatory() {
MockCommandLineProcessor c = new MockCommandLineProcessor();
MockCommandLineProcessor c = new MockCommandLineProcessor(mLog);
c.parseArgs(new String[] { "action1", "-1", "value1", "-2", "value2" });
assertFalse(c.wasExitCalled());
@@ -161,7 +167,7 @@ public class CommandLineProcessorTest extends TestCase {
assertEquals("value1", c.getValue("action1", "first"));
assertEquals("value2", c.getValue("action1", "second"));
c = new MockCommandLineProcessor();
c = new MockCommandLineProcessor(mLog);
c.parseArgs(new String[] { "action1", "-2", "value2" });
assertFalse(c.wasExitCalled());
assertFalse(c.wasHelpCalled());
@@ -169,7 +175,7 @@ public class CommandLineProcessorTest extends TestCase {
assertEquals(null, c.getValue("action1", "first"));
assertEquals("value2", c.getValue("action1", "second"));
c = new MockCommandLineProcessor();
c = new MockCommandLineProcessor(mLog);
c.parseArgs(new String[] { "action1" });
assertTrue(c.wasExitCalled());
assertTrue(c.wasHelpCalled());

View File

@@ -16,10 +16,14 @@
package com.android.sdkmanager;
import com.android.sdklib.ISdkLog;
import junit.framework.TestCase;
public class SdkCommandLineTest extends TestCase {
private MockStdLogger mLog;
/**
* A mock version of the {@link SdkCommandLine} class that does not
* exits and discards its stdout/stderr output.
@@ -28,7 +32,8 @@ public class SdkCommandLineTest extends TestCase {
private boolean mExitCalled;
private boolean mHelpCalled;
public MockSdkCommandLine() {
public MockSdkCommandLine(ISdkLog logger) {
super(logger);
}
@Override
@@ -64,6 +69,7 @@ public class SdkCommandLineTest extends TestCase {
@Override
protected void setUp() throws Exception {
mLog = new MockStdLogger();
super.setUp();
}
@@ -74,7 +80,7 @@ public class SdkCommandLineTest extends TestCase {
/** Test list with long name and verbose */
public final void testList_Long_Verbose() {
MockSdkCommandLine c = new MockSdkCommandLine();
MockSdkCommandLine c = new MockSdkCommandLine(mLog);
assertEquals("all", c.getListFilter());
c.parseArgs(new String[] { "-v", "list", "--filter", "vm" });
assertFalse(c.wasHelpCalled());
@@ -85,7 +91,7 @@ public class SdkCommandLineTest extends TestCase {
/** Test list with short name and no verbose */
public final void testList_Short() {
MockSdkCommandLine c = new MockSdkCommandLine();
MockSdkCommandLine c = new MockSdkCommandLine(mLog);
assertEquals("all", c.getListFilter());
c.parseArgs(new String[] { "list", "-f", "vm" });
assertFalse(c.wasHelpCalled());
@@ -95,7 +101,7 @@ public class SdkCommandLineTest extends TestCase {
/** Test list with long name and missing parameter */
public final void testList_Long_MissingParam() {
MockSdkCommandLine c = new MockSdkCommandLine();
MockSdkCommandLine c = new MockSdkCommandLine(mLog);
assertEquals("all", c.getListFilter());
c.parseArgs(new String[] { "list", "--filter" });
assertTrue(c.wasHelpCalled());