コード例 #1
0
  @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();
    }
  }
コード例 #2
0
  // private ListView _lvMasterList;
  //	private EditText _etSearch;
  //	private ImageButton _btnSearch;
  @Before
  public void setup() {
    RoboGuice.setBaseApplicationInjector(
        Robolectric.application,
        RoboGuice.DEFAULT_STAGE,
        Modules.override(RoboGuice.newDefaultRoboModule(Robolectric.application))
            .with(new EmptyGroceryFilesModule()));

    super.setup();
    // Override the default RoboGuice module

    try {
      _activity =
          (EditMasterListActivity) shadowOf(super.editMasterList()).getIntentClass().newInstance();
      _activity.onCreate(null);
    } catch (Exception e) {
      fail(e.getMessage());
    }
    // _lvMasterList = (ListView) _activity.findViewById(R.id.masterlist);

    _btnAdd = (ImageButton) this._activity.findViewById(R.id.add_button);

    //	_etSearch = (EditText) this._activity.findViewById(R.id.search_text);

    //	_btnSearch = (Button) _currentListActivity.findViewById(R.id.search_button);

  }
コード例 #3
0
  @After
  public void teardown() {
    // Don't forget to tear down our custom injector to avoid polluting other test classes

    _activity.finish();
    super.teardown();
    // super.getMainActivity().finish();
  }
コード例 #4
0
  @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();
    }
  }