Java Code Examples for org.robolectric.util.ActivityController#start()

The following examples show how to use org.robolectric.util.ActivityController#start() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReceiptViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void LoadReceipt()
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putString("receipt", "receipt");
    intent.putExtras(bundle);

    ActivityController activityController =  Robolectric.buildActivity(
        ReceiptViewActivity.class).withIntent(intent).create();
    activityController.start();
    activityController.resume();

    Activity activity = (Activity)activityController.get();
    WebView receiptView = (WebView)activity.findViewById(R.id.imageView);

    ShadowWebView.LoadDataWithBaseURL loadedData = shadowOf(receiptView).getLastLoadDataWithBaseURL();
    assertEquals("", loadedData.baseUrl);
    assertEquals("text/html", loadedData.mimeType);
    assertEquals("utf-8", loadedData.encoding);
    assertNull(loadedData.historyUrl);
    assertTrue(loadedData.data.contains("src=\"file://receipt\""));
}
 
Example 2
Source File: ControllerActivity.java    From AndroidUnitTest with Apache License 2.0 6 votes vote down vote up
private void applyState(ActivityState state,
                        ActivityController controller) {
    switch (state) {
        case STARTED:
            controller.start();
            break;
        case RESUMED:
            controller.resume();
            break;
        case PAUSED:
            controller.pause();
            break;
        case STOPPED:
            controller.stop();
            break;
        case DESTROYED:
            controller.destroy();
            break;
        case CREATED:
        default:
            controller.create();
            break;
    }
}
 
Example 3
Source File: MainActivityTest.java    From gift-card-guard with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void addOneGiftCard()
{
    ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create();

    Activity mainActivity = (Activity)activityController.get();
    activityController.start();
    activityController.resume();

    TextView helpText = (TextView)mainActivity.findViewById(R.id.helpText);
    ListView list = (ListView)mainActivity.findViewById(R.id.list);

    assertEquals(0, list.getCount());

    DBHelper db = new DBHelper(mainActivity);
    db.insertGiftCard("store", "cardId", "value", "receipt");

    assertEquals(View.VISIBLE, helpText.getVisibility());
    assertEquals(View.GONE, list.getVisibility());

    activityController.pause();
    activityController.resume();

    assertEquals(View.GONE, helpText.getVisibility());
    assertEquals(View.VISIBLE, list.getVisibility());

    assertEquals(1, list.getAdapter().getCount());
    Cursor cursor = (Cursor)list.getAdapter().getItem(0);
    assertNotNull(cursor);
}