Exemplo n.º 1
0
  @Test
  public void addSubMenu() {
    TestMenu testMenu = new TestMenu(new MyActivity());
    testMenu.addSubMenu(9, 10, 0, org.robolectric.R.string.ok);

    TestMenuItem testMenuItem = (TestMenuItem) testMenu.findItem(10);

    assertThat(testMenuItem.getGroupId()).isEqualTo(9);
    assertThat(testMenuItem.getItemId()).isEqualTo(10);
  }
Exemplo n.º 2
0
  @Test
  public void addAndRemoveMenuItems() {
    TestMenu testMenu = new TestMenu(new MyActivity());
    testMenu.add(9, 10, 0, org.robolectric.R.string.ok);

    TestMenuItem testMenuItem = (TestMenuItem) testMenu.findItem(10);

    assertThat(testMenuItem.getGroupId()).isEqualTo(9);
    assertThat(testMenuItem.getItemId()).isEqualTo(10);

    testMenu.removeItem(10);

    testMenuItem = (TestMenuItem) testMenu.findItem(10);
    Assert.assertNull(testMenuItem);
  }
Exemplo n.º 3
0
  @Test
  public void clickWithIntent() {
    MyActivity activity = new MyActivity();

    TestMenu testMenu = new TestMenu(activity);
    testMenu.add(0, 10, 0, org.robolectric.R.string.ok);

    TestMenuItem testMenuItem = (TestMenuItem) testMenu.findItem(10);
    Assert.assertNull(testMenuItem.getIntent());

    Intent intent = new Intent(activity, MyActivity.class);
    testMenuItem.setIntent(intent);
    testMenuItem.click();

    Assert.assertNotNull(testMenuItem);

    ShadowActivity shadowActivity = Robolectric.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertNotNull(startedIntent);
  }
Exemplo n.º 4
0
  @Test
  public void add_AddsItemsInOrder() {
    MyActivity activity = new MyActivity();
    TestMenu testMenu = new TestMenu(activity);
    testMenu.add(0, 0, 1, "greeting");
    testMenu.add(0, 0, 0, "hell0");
    testMenu.add(0, 0, 0, "hello");

    MenuItem item = testMenu.getItem(0);
    assertEquals("hell0", item.getTitle());
    item = testMenu.getItem(1);
    assertEquals("hello", item.getTitle());
    item = testMenu.getItem(2);
    assertEquals("greeting", item.getTitle());
  }