Java Code Examples for org.robolectric.android.controller.ActivityController#visible()
The following examples show how to use
org.robolectric.android.controller.ActivityController#visible() .
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: CourseBaseActivityTest.java From edx-app-android with Apache License 2.0 | 6 votes |
/** * Testing process start and finish method functionality */ @Test public void processLifecycleTest() { // We need to retrieve the progressWheel view before calling visible(), since that // initializes fragment views as well, which might add other views with the same id ActivityController<? extends CourseBaseActivity> controller = Robolectric.buildActivity(getActivityClass(), getIntent()) .create().start().postCreate(null).resume(); CourseBaseActivity activity = controller.get(); ProgressBar progressWheel = (ProgressBar) activity.findViewById(R.id.loading_indicator); controller.visible(); if (progressWheel == null) { activity.startProcess(); activity.finishProcess(); } else { assertThat(progressWheel).isNotVisible(); activity.startProcess(); assertThat(progressWheel).isVisible(); activity.finishProcess(); assertThat(progressWheel).isNotVisible(); } }
Example 2
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 6 votes |
@Test public void startWithoutParametersCancel() { ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create(); activityController.start(); activityController.visible(); activityController.resume(); Activity activity = (Activity)activityController.get(); final Button cancelButton = (Button) activity.findViewById(R.id.cancelButton); assertEquals(false, activity.isFinishing()); cancelButton.performClick(); assertEquals(true, activity.isFinishing()); }
Example 3
Source File: BudgetActivityTest.java From budget-watch with GNU General Public License v3.0 | 6 votes |
@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); }
Example 4
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 5 votes |
@Test public void startWithGiftCardWithReceiptUpdateReceiptCancel() throws IOException { ActivityController activityController = createActivityWithGiftCard(); Activity activity = (Activity)activityController.get(); DBHelper db = new DBHelper(activity); db.insertGiftCard("store", "cardId", "value", "receipt"); activityController.start(); activityController.visible(); activityController.resume(); checkAllFields(activity, "store", "cardId", "value", "receipt", false); // Add something that will 'handle' the media capture intent registerMediaStoreIntentHandler(); // Complete image capture successfully Uri imageLocation = captureImageWithResult(activity, R.id.updateButton, true); checkAllFields(activity, "store", "cardId", "value", "receipt", true); // Cancel the gift card creation final Button cancelButton = (Button) activity.findViewById(R.id.cancelButton); assertEquals(false, activity.isFinishing()); cancelButton.performClick(); assertEquals(true, activity.isFinishing()); activityController.destroy(); // Ensure the image has been deleted File imageFile = new File(imageLocation.getPath()); assertEquals(false, imageFile.exists()); }
Example 5
Source File: SettingsActivityTest.java From budget-watch with GNU General Public License v3.0 | 5 votes |
@Test public void testAvailableSettings() { ActivityController activityController = Robolectric.buildActivity(SettingsActivity.class).create(); Activity activity = (Activity)activityController.get(); activityController.start(); activityController.resume(); activityController.visible(); ListView list = (ListView)activity.findViewById(android.R.id.list); shadowOf(list).populateItems(); List<String> settingTitles = new LinkedList<> (Arrays.asList( "Receipt Quality" )); assertEquals(settingTitles.size(), list.getCount()); for(int index = 0; index < list.getCount(); index++) { ListPreference preference = (ListPreference)list.getItemAtPosition(0); String title = preference.getTitle().toString(); assertTrue(settingTitles.remove(title)); } assertTrue(settingTitles.isEmpty()); }
Example 6
Source File: TransactionActivityTest.java From budget-watch with GNU General Public License v3.0 | 5 votes |
private void checkClickAddWhileOnTap(Integer tab, int expectedType) { ActivityController activityController = Robolectric.buildActivity(TransactionActivity.class).create(); Activity activity = (Activity)activityController.get(); activityController.start(); activityController.resume(); activityController.visible(); if(tab != null) { final ViewPager viewPager = (ViewPager) activity.findViewById(R.id.pager); viewPager.setCurrentItem(tab); } shadowOf(activity).clickMenuItem(R.id.action_add); 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); // Fields which should not be present assertEquals(-1, bundle.getInt("id", -1)); assertEquals(false, bundle.getBoolean("update", false)); assertEquals(false, bundle.getBoolean("view", false)); // Check the field which is expected assertEquals(expectedType, bundle.getInt("type", -1)); }
Example 7
Source File: MainActivityTest.java From budget-watch with GNU General Public License v3.0 | 5 votes |
@Test public void testClickImportExport() { ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create(); Activity activity = (Activity)activityController.get(); activityController.start(); activityController.resume(); activityController.visible(); shadowOf(activity).clickMenuItem(R.id.action_import_export); testNextStartedActivity(activity, "protect.budgetwatch/.ImportExportActivity"); }
Example 8
Source File: MainActivityTest.java From budget-watch with GNU General Public License v3.0 | 5 votes |
@Test public void testClickSettings() { ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create(); Activity activity = (Activity)activityController.get(); activityController.start(); activityController.resume(); activityController.visible(); shadowOf(activity).clickMenuItem(R.id.action_settings); testNextStartedActivity(activity, "protect.budgetwatch/.SettingsActivity"); }
Example 9
Source File: TransactionViewActivityTest.java From budget-watch with GNU General Public License v3.0 | 5 votes |
private ActivityController setupActivity(final int actionType, final String budget, final String receipt) { Intent intent = new Intent(); if(actionType == DBHelper.TransactionDbIds.EXPENSE) { intent.setAction(TransactionViewActivity.ACTION_NEW_EXPENSE); } else { intent.setAction(TransactionViewActivity.ACTION_NEW_REVENUE); } ActivityController activityController = Robolectric.buildActivity(TransactionViewActivity.class, intent).create(); Activity activity = (Activity)activityController.get(); if(budget != null) { addBudget(activity, budget); if (receipt != null) { addTransactionForBudget(activity, budget, receipt); } } activityController.start(); activityController.visible(); activityController.resume(); return activityController; }
Example 10
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 5 votes |
@Test public void startWithoutParametersCheckFieldsAvailable() { ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create(); activityController.start(); activityController.visible(); activityController.resume(); Activity activity = (Activity)activityController.get(); checkAllFields(activity, "", "", "", "", false); }
Example 11
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 5 votes |
@Test public void startWithGiftCardWithReceiptUpdateReceipt() throws IOException { ActivityController activityController = createActivityWithGiftCard(); Activity activity = (Activity)activityController.get(); DBHelper db = new DBHelper(activity); db.insertGiftCard("store", "cardId", "value", "receipt"); activityController.start(); activityController.visible(); activityController.resume(); checkAllFields(activity, "store", "cardId", "value", "receipt", false); // Add something that will 'handle' the media capture intent registerMediaStoreIntentHandler(); // Complete image capture successfully Uri imageLocation = captureImageWithResult(activity, R.id.updateButton, true); checkAllFields(activity, "store", "cardId", "value", "receipt", true); // Save and check the gift card saveGiftCardWithArguments(activity, "store", "cardId", "value", imageLocation.getPath(), false); // Ensure that the file still exists File imageFile = new File(imageLocation.getPath()); assertTrue(imageFile.isFile()); // Delete the file to cleanup boolean result = imageFile.delete(); assertTrue(result); }
Example 12
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 5 votes |
@Test public void startWithGiftCardWithReceiptCheckDisplay() throws IOException { ActivityController activityController = createActivityWithGiftCard(); Activity activity = (Activity)activityController.get(); DBHelper db = new DBHelper(activity); db.insertGiftCard("store", "cardId", "value", "receipt"); activityController.start(); activityController.visible(); activityController.resume(); checkAllFields(activity, "store", "cardId", "value", "receipt", false); }
Example 13
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 5 votes |
@Test public void startWithGiftCardNoReceiptCheckDisplay() throws IOException { ActivityController activityController = createActivityWithGiftCard(); Activity activity = (Activity)activityController.get(); DBHelper db = new DBHelper(activity); db.insertGiftCard("store", "cardId", "value", ""); activityController.start(); activityController.visible(); activityController.resume(); checkAllFields(activity, "store", "cardId", "value", "", false); }
Example 14
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 5 votes |
@Test public void startWithoutParametersCaptureReceiptCancel() throws IOException { ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create(); activityController.start(); activityController.visible(); activityController.resume(); // Add something that will 'handle' the media capture intent registerMediaStoreIntentHandler(); Activity activity = (Activity)activityController.get(); checkAllFields(activity, "", "", "", "", false); // Complete image capture successfully Uri imageLocation = captureImageWithResult(activity, R.id.captureButton, true); checkAllFields(activity, "", "", "", "", true); // Cancel the gift card creation final Button cancelButton = (Button) activity.findViewById(R.id.cancelButton); assertEquals(false, activity.isFinishing()); cancelButton.performClick(); assertEquals(true, activity.isFinishing()); activityController.destroy(); // Ensure the image has been deleted File imageFile = new File(imageLocation.getPath()); assertEquals(false, imageFile.exists()); }
Example 15
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 5 votes |
@Test public void startWithoutParametersCaptureReceiptFailureCreateGiftCard() throws IOException { ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create(); activityController.start(); activityController.visible(); activityController.resume(); // Add something that will 'handle' the media capture intent registerMediaStoreIntentHandler(); Activity activity = (Activity)activityController.get(); checkAllFields(activity, "", "", "", "", false); // Complete image capture in failure Uri imageLocation = captureImageWithResult(activity, R.id.captureButton, false); checkAllFields(activity, "", "", "", "", false); // Save and check the gift card saveGiftCardWithArguments(activity, "store", "cardId", "value", "", true); // Check that no file was created File imageFile = new File(imageLocation.getPath()); assertEquals(false, imageFile.exists()); }
Example 16
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 5 votes |
@Test public void startWithoutParametersCaptureReceiptCreateGiftCard() throws IOException { ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create(); activityController.start(); activityController.visible(); activityController.resume(); // Add something that will 'handle' the media capture intent registerMediaStoreIntentHandler(); Activity activity = (Activity)activityController.get(); checkAllFields(activity, "", "", "", "", false); // Complete image capture successfully Uri imageLocation = captureImageWithResult(activity, R.id.captureButton, true); checkAllFields(activity, "", "", "", "", true); // Save and check the gift card saveGiftCardWithArguments(activity, "store", "cardId", "value", imageLocation.getPath(), true); // Ensure that the file still exists File imageFile = new File(imageLocation.getPath()); assertTrue(imageFile.isFile()); // Delete the file to cleanup boolean result = imageFile.delete(); assertTrue(result); }
Example 17
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 5 votes |
@Test public void startWithoutParametersCreateGiftCardNoReceipt() { ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create(); activityController.start(); activityController.visible(); activityController.resume(); Activity activity = (Activity)activityController.get(); saveGiftCardWithArguments(activity, "store", "cardId", "value", "", true); }
Example 18
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 5 votes |
@Test public void startWithoutParametersCannotCreateGiftCard() { ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create(); activityController.start(); activityController.visible(); activityController.resume(); Activity activity = (Activity)activityController.get(); DBHelper db = new DBHelper(activity); assertEquals(0, db.getGiftCardCount()); final EditText storeField = (EditText) activity.findViewById(R.id.storeName); final EditText cardIdField = (EditText) activity.findViewById(R.id.cardId); final TextView receiptField = (TextView) activity.findViewById(R.id.receiptLocation); final Button saveButton = (Button) activity.findViewById(R.id.saveButton); saveButton.performClick(); assertEquals(0, db.getGiftCardCount()); storeField.setText("store"); saveButton.performClick(); assertEquals(0, db.getGiftCardCount()); cardIdField.setText("cardId"); saveButton.performClick(); assertEquals(0, db.getGiftCardCount()); receiptField.setText("receipt"); saveButton.performClick(); assertEquals(0, db.getGiftCardCount()); }
Example 19
Source File: TransactionViewActivityTest.java From budget-watch with GNU General Public License v3.0 | 4 votes |
private ActivityController setupActivity(final String budget, final String receipt, boolean launchAsView, boolean launchAsUpdate) { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putInt("type", DBHelper.TransactionDbIds.EXPENSE); if(receipt != null) { // Put the ID of the first transaction, which will be added shortly bundle.putInt("id", 1); } if(launchAsView) { bundle.putBoolean("view", true); } if(launchAsUpdate) { bundle.putBoolean("update", true); } intent.putExtras(bundle); ActivityController activityController = Robolectric.buildActivity(TransactionViewActivity.class, intent).create(); Activity activity = (Activity)activityController.get(); if(budget != null) { addBudget(activity, budget); if (receipt != null) { addTransactionForBudget(activity, budget, receipt); } } activityController.start(); activityController.visible(); activityController.resume(); return activityController; }
Example 20
Source File: BudgetViewActivityTest.java From budget-watch with GNU General Public License v3.0 | 4 votes |
private ActivityController setupActivity(final String budget, int value, boolean launchAsView, boolean launchAsUpdate) { Intent intent = new Intent(); final Bundle bundle = new Bundle(); if(budget != null) { bundle.putString("id", budget); } if(launchAsView) { bundle.putBoolean("view", true); } if(launchAsUpdate) { bundle.putBoolean("update", true); } intent.putExtras(bundle); ActivityController activityController = Robolectric.buildActivity(BudgetViewActivity.class, intent).create(); Activity activity = (Activity)activityController.get(); DBHelper db = new DBHelper(activity); if(budget != null) { boolean result = db.insertBudget(budget, value); assertTrue(result); } db.close(); activityController.start(); activityController.visible(); activityController.resume(); return activityController; }