@Test public void testAddItem() { ArrayList<GroceryItem> items = _activity.getItemsDisplayed(); int count = items.size(); _btnAdd.performClick(); try { _btnAdd.performClick(); Intent data = super.targetActivityIsStarted( shadowOf(this._activity), EditMasterItemActivity.class.getName()); assert (data != null); GroceryItem item = saveGroceryItemValues(data); _activity.processActivityResult(BaseListActivity.ACTIVITY_ADD, Activity.RESULT_OK, data); ArrayList<GroceryItem> itemsDisplayed = _activity.getItemsDisplayed(); assertTrue(itemsDisplayed.contains(item)); _activity.saveList(); items = _activity.loadGroceryItems(FileNameConstants.MasterFileName); assertEquals(count + 1, items.size()); } catch (Exception e) { fail("Exception testing adding of an empty category"); // TODO Auto-generated catch block // e.printStackTrace(); } }
@Test public void testCannotSaveMasterItemWithoutAName() { ArrayList<GroceryItem> items = _activity.getItemsDisplayed(); int count = items.size(); try { this._btnAdd.performClick(); _activity.saveList(); items = _activity.loadGroceryItems(FileNameConstants.MasterFileName); assertEquals(count, items.size()); } catch (Exception e) { fail("Exception testing adding of an empty category"); // TODO Auto-generated catch block // e.printStackTrace(); } }