FileDocCategorySizeDatePackage
TestBrowserControllerImplTest.javaAPI DocAndroid 1.5 API5250Wed May 06 22:42:02 BST 2009android.test

TestBrowserControllerImplTest

public class TestBrowserControllerImplTest extends TestCase

Fields Summary
private TestBrowserControllerImpl
mTestBrowserController
private TestBrowserViewStub
mTestBrowserView
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        mTestBrowserController = new TestBrowserControllerImpl();
        mTestBrowserView = new TestBrowserViewStub();
        mTestBrowserController.registerView(mTestBrowserView);
    
public voidtestGetIntentForRunAll()

        TestSuite testSuite = new DummyTestSuite();
        testSuite.addTestSuite(DummyTestCase.class);

        mTestBrowserController.setTestSuite(testSuite);
        Intent intent = mTestBrowserController.getIntentForTestAt(0);
        verifyIntent(intent, DummyTestSuite.class, "com.android.testharness");
    
public voidtestGetIntentForTestCase()

        TestSuite testSuite = new TestSuite();
        testSuite.addTest(new DummyTestCase());

        mTestBrowserController.setTestSuite(testSuite);
        Intent intent = mTestBrowserController.getIntentForTestAt(1);
        verifyIntent(intent, DummyTestCase.class, "com.android.testharness");
        assertEquals(TestBrowserControllerImpl.TEST_RUNNER_ACTIVITY_CLASS_NAME,
                intent.getComponent().getClassName());
        assertEquals("testDummyTest",
                intent.getStringExtra(TestBrowserController.BUNDLE_EXTRA_TEST_METHOD_NAME));
    
public voidtestGetIntentForTestSuite()

        TestSuite testSuite = new TestSuite();
        testSuite.addTestSuite(DummyTestCase.class);

        String targetBrowserActvityClassName = "com.android.bogus.DummyActivity";
        String expectedTargetPackageName = "com.android.bogus";
        mTestBrowserController.setTargetBrowserActivityClassName(targetBrowserActvityClassName);
        mTestBrowserController.setTestSuite(testSuite);
        mTestBrowserController.setTargetPackageName(expectedTargetPackageName);
        Intent intent = mTestBrowserController.getIntentForTestAt(1);
        verifyIntent(intent, DummyTestCase.class, expectedTargetPackageName);
        assertEquals(targetBrowserActvityClassName, intent.getComponent().getClassName());
    
public voidtestSetTestSuite()

        TestSuite testSuite = new TestSuite();
        testSuite.addTestSuite(DummyTestCase.class);

        mTestBrowserController.setTestSuite(testSuite);

        verifyTestNames(Arrays.asList("Run All", DummyTestCase.class.getSimpleName()),
                mTestBrowserView.getTestNames());
    
private static voidverifyIntent(android.content.Intent intent, java.lang.Class testClass, java.lang.String expectedPackageName)

        assertEquals(Intent.ACTION_RUN, intent.getAction());
        assertEquals(Intent.FLAG_ACTIVITY_NEW_TASK,
                intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK);
        assertEquals(Intent.FLAG_ACTIVITY_MULTIPLE_TASK,
                intent.getFlags() & Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        assertEquals(testClass.getName(), intent.getData().toString());
        assertEquals(expectedPackageName, intent.getComponent().getPackageName());
    
private static voidverifyTestNames(java.util.List expectedTestNames, java.util.List actualTestNames)

        assertEquals(expectedTestNames.size(), actualTestNames.size());

        // We use endsWith instead of equals because the return value of
        // class.getSimpleName(), when called on an inner class, varies
        // from one vm to another.
        // This allows the test to pass in multiple environments.
        for (int i = 0; i < expectedTestNames.size(); i++) {
            assertTrue(actualTestNames.get(i).endsWith(expectedTestNames.get(i)));
        }