當前位置: 首頁>>代碼示例>>Java>>正文


Java ShadowActivity類代碼示例

本文整理匯總了Java中org.robolectric.shadows.ShadowActivity的典型用法代碼示例。如果您正苦於以下問題:Java ShadowActivity類的具體用法?Java ShadowActivity怎麽用?Java ShadowActivity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ShadowActivity類屬於org.robolectric.shadows包,在下文中一共展示了ShadowActivity類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startActivity_withResult_finishesWithResult

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
@Test
public void startActivity_withResult_finishesWithResult() {
    int givenResultCode = 0x2c001;
    Intent givenIntent =
            new HintRetrieveResult.Builder(givenResultCode).build().toResultDataIntent();
    Intent intent = FinishWithResultActivity.createIntent(
            CONTEXT,
            ActivityResult.of(givenResultCode, givenIntent));

    ShadowActivity activity = startActivity(intent);

    assertThat(activity.isFinishing()).isTrue();
    HintRetrieveResult result =
            CredentialClient.getInstance(CONTEXT)
                    .getHintRetrieveResult(activity.getResultIntent());
    assertThat(result.getResultCode()).isEqualTo(givenResultCode);
    assertThat(activity.getResultCode()).isEqualTo(givenResultCode);
}
 
開發者ID:openid,項目名稱:OpenYOLO-Android,代碼行數:19,代碼來源:FinishWithResultActivityTest.java

示例2: clickBackFinishes

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
@Test
public void clickBackFinishes() throws IOException
{
    File file = new File(Environment.getExternalStorageDirectory(), "test.jpg");
    file.createNewFile();

    ActivityController controller = startWithFile(file);
    Activity activity = (Activity)controller.get();
    ShadowActivity shadowActivity = shadowOf(activity);

    assertTrue(shadowActivity.isFinishing() == false);
    shadowActivity.clickMenuItem(android.R.id.home);
    assertTrue(shadowActivity.isFinishing());

    // Check that can finish out the lifecycle
    controller.pause();
    controller.stop();
    controller.destroy();

    // The done menu item was not clicked, so the result should be that
    // the activity was canceled
    assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode());
    assertNull(shadowActivity.getResultIntent());
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:25,代碼來源:PictureViewActivityTest.java

示例3: clickDeleteFinishes

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
@Test
public void clickDeleteFinishes() throws IOException
{
    File file = new File(Environment.getExternalStorageDirectory(), "test.jpg");
    file.createNewFile();

    ActivityController controller = startWithFile(file);
    Activity activity = (Activity)controller.get();
    ShadowActivity shadowActivity = shadowOf(activity);

    assertTrue(shadowActivity.isFinishing() == false);
    boolean result = shadowActivity.clickMenuItem(R.id.action_delete);
    assertTrue(result);

    // Note, cannot finish the test because the v7 AlertDialog
    // currently does not have shadow support.
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:18,代碼來源:PictureViewActivityTest.java

示例4: checkOpenActivity

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
private void checkOpenActivity(ActivityController controller, int viewId, HashMap<String, Integer> items)
{
    Activity activity = (Activity)controller.get();
    activity.findViewById(viewId).performClick();

    assertTrue(activity.isFinishing() == false);

    ShadowActivity.IntentForResult next = shadowOf(activity).getNextStartedActivityForResult();

    ComponentName componentName = next.intent.getComponent();
    String name = componentName.flattenToShortString();
    assertEquals("protect.rentalcalc/.ItemizeActivity", name);

    Bundle extras = next.intent.getExtras();
    assertNotNull(extras);
    assertTrue(extras.containsKey("title"));
    assertTrue(extras.getInt("title") > 0);
    assertTrue(extras.containsKey("description"));
    assertTrue(extras.getInt("description") > 0);
    assertTrue(extras.containsKey("items"));
    assertEquals(items, extras.getSerializable("items"));

    // As the next activity is started, this activity is paused
    controller.pause();
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:26,代碼來源:PropertyWorksheetActivityTest.java

示例5: clickBackFinishes

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
@Test
public void clickBackFinishes()
{
    ActivityController controller = startWithMap(new HashMap<String, Integer>());
    Activity activity = (Activity)controller.get();
    ShadowActivity shadowActivity = shadowOf(activity);

    assertTrue(shadowActivity.isFinishing() == false);
    shadowActivity.clickMenuItem(android.R.id.home);
    assertTrue(shadowActivity.isFinishing());

    // Check that can finish out the lifecycle
    controller.pause();
    controller.stop();
    controller.destroy();

    // The done menu item was not clicked, so the result should be that
    // the activity was canceled
    assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode());
    assertNull(shadowActivity.getResultIntent());
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:22,代碼來源:ItemizationActivityTest.java

示例6: checkReturnedMap

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
private void checkReturnedMap(Activity activity, Map<String, Integer> expected)
{
    ShadowActivity shadowActivity = shadowOf(activity);

    assertEquals(Activity.RESULT_OK, shadowActivity.getResultCode());
    Intent intent = shadowActivity.getResultIntent();
    assertNotNull(intent);
    Bundle bundle = intent.getExtras();
    assertNotNull(bundle);
    assertTrue(bundle.containsKey("items"));
    HashMap<String, Integer> map = (HashMap<String, Integer>)bundle.getSerializable("items");
    assertNotNull(map);

    assertEquals(expected.size(), map.size());

    for(Map.Entry<String, Integer> item : expected.entrySet())
    {
        assertTrue("Did not contain: " + item.getKey(), map.containsKey(item.getKey()));
        assertEquals("Value did not match: " + item.getValue(), item.getValue(), map.get(item.getKey()));
    }
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:22,代碼來源:ItemizationActivityTest.java

示例7: doneNoItems

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
@Test
public void doneNoItems()
{
    HashMap<String, Integer> emptyMap = new HashMap<>();
    ActivityController controller = startWithMap(emptyMap);
    Activity activity = (Activity)controller.get();
    ShadowActivity shadowActivity = shadowOf(activity);

    assertTrue(shadowActivity.isFinishing() == false);
    shadowActivity.clickMenuItem(R.id.action_done);
    assertTrue(shadowActivity.isFinishing());

    // Check that can finish out the lifecycle
    controller.pause();
    controller.stop();
    controller.destroy();

    checkReturnedMap(activity, emptyMap);
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:20,代碼來源:ItemizationActivityTest.java

示例8: addItem

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
private void addItem(Activity activity, String name, Integer value)
{
    ShadowActivity shadowActivity = shadowOf(activity);
    ListView list = (ListView)activity.findViewById(R.id.list);
    assertNotNull(list);

    int initialCount = list.getCount();

    shadowActivity.clickMenuItem(R.id.action_add);
    ItemizationAdapter adapter = (ItemizationAdapter)list.getAdapter();
    Itemization listItem = adapter.getItem(initialCount);
    assertNotNull(listItem);
    listItem.name = name;
    listItem.value = value;

    assertEquals(initialCount+1, list.getCount());
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:18,代碼來源:ItemizationActivityTest.java

示例9: should_start_url_intent

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
@Test
public void should_start_url_intent() {
    // Given
    String url = "geo:22.5430883,114.1043205";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), ShadowResolveInfo.newResolveInfo("", "", ""));

    // When
    boolean result = Intents.startUri(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(result).isTrue();
    assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(startedIntent.getData().toString()).isEqualTo(url);
}
 
開發者ID:Nilhcem,項目名稱:droidconde-2016,代碼行數:19,代碼來源:IntentsTest.java

示例10: should_return_false_when_nothing_on_the_device_can_open_the_uri

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
@Test
public void should_return_false_when_nothing_on_the_device_can_open_the_uri() {
    // Given
    String url = "http://www.google.com";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), (ResolveInfo) null);

    // When
    boolean result = Intents.startUri(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(result).isFalse();
    assertThat(startedIntent).isNull();
}
 
開發者ID:Nilhcem,項目名稱:droidconde-2016,代碼行數:18,代碼來源:IntentsTest.java

示例11: should_start_external_uri

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
@Test
public void should_start_external_uri() {
    // Given
    String url = "http://www.google.com";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), ShadowResolveInfo.newResolveInfo("", "", ""));

    // When
    Intents.startExternalUrl(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(startedIntent.getData().toString()).isEqualTo(url);
}
 
開發者ID:Nilhcem,項目名稱:droidconde-2016,代碼行數:18,代碼來源:IntentsTest.java

示例12: finish_finishesWithPaymentMethodNonceAndDeviceDataInDropInResult

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
@Test
public void finish_finishesWithPaymentMethodNonceAndDeviceDataInDropInResult()
        throws JSONException {
    CardNonce cardNonce = CardNonce.fromJson(
            stringFromFixture("responses/visa_credit_card_response.json"));
    setup(new DropInRequest()
            .tokenizationKey(TOKENIZATION_KEY)
            .getIntent(RuntimeEnvironment.application));

    mActivity.finish(cardNonce, "device_data");

    ShadowActivity shadowActivity = shadowOf(mActivity);
    assertTrue(mActivity.isFinishing());
    assertEquals(Activity.RESULT_OK, shadowActivity.getResultCode());
    DropInResult result = shadowActivity.getResultIntent()
            .getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
    assertNotNull(result);
    assertEquals(cardNonce.getNonce(), result.getPaymentMethodNonce().getNonce());
    assertEquals("device_data", result.getDeviceData());
}
 
開發者ID:braintree,項目名稱:braintree-android-drop-in,代碼行數:21,代碼來源:BaseActivityUnitTest.java

示例13: finish_finishesWithException

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
@Test
public void finish_finishesWithException() {
    Exception exception = new Exception("Error message");
    setup(new DropInRequest()
            .tokenizationKey(TOKENIZATION_KEY)
            .getIntent(RuntimeEnvironment.application));

    mActivity.finish(exception);

    ShadowActivity shadowActivity = shadowOf(mActivity);
    assertTrue(mActivity.isFinishing());
    assertEquals(Activity.RESULT_FIRST_USER, shadowActivity.getResultCode());
    Exception error = (Exception) shadowActivity.getResultIntent()
            .getSerializableExtra(DropInActivity.EXTRA_ERROR);
    assertNotNull(error);
    assertEquals("Error message", error.getMessage());
}
 
開發者ID:braintree,項目名稱:braintree-android-drop-in,代碼行數:18,代碼來源:BaseActivityUnitTest.java

示例14: testClickAdd

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
@Test
public void testClickAdd()
{
    ActivityController activityController = Robolectric.buildActivity(BudgetActivity.class).create();
    Activity activity = (Activity)activityController.get();

    activityController.start();
    activityController.resume();
    activityController.visible();

    shadowOf(activity).clickMenuItem(R.id.action_add);

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    ComponentName name = startedIntent.getComponent();
    assertNotNull(name);
    assertEquals("protect.budgetwatch/.BudgetViewActivity", name.flattenToShortString());
    Bundle bundle = startedIntent.getExtras();
    assertNull(bundle);
}
 
開發者ID:brarcher,項目名稱:budget-watch,代碼行數:22,代碼來源:BudgetActivityTest.java

示例15: startAsViewClickEdit

import org.robolectric.shadows.ShadowActivity; //導入依賴的package包/類
@Test
public void startAsViewClickEdit() throws Exception
{
    ActivityController activityController = setupActivity("budget", "", true, false);
    Activity activity = (Activity)activityController.get();

    shadowOf(activity).clickMenuItem(R.id.action_edit);

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    ComponentName name = startedIntent.getComponent();
    assertNotNull(name);
    assertEquals("protect.budgetwatch/.TransactionViewActivity", name.flattenToShortString());
    Bundle bundle = startedIntent.getExtras();
    assertNotNull(bundle);

    assertEquals(DBHelper.TransactionDbIds.EXPENSE, bundle.getInt("type", -1));
    assertEquals(1, bundle.getInt("id", -1));
    assertEquals(true, bundle.getBoolean("update", false));
    assertEquals(false, bundle.getBoolean("view", false));
}
 
開發者ID:brarcher,項目名稱:budget-watch,代碼行數:23,代碼來源:TransactionViewActivityTest.java


注:本文中的org.robolectric.shadows.ShadowActivity類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。