Java 类org.robolectric.tester.android.view.TestMenu 实例源码

项目:open    文件:AutoCompleteAdapterTest.java   
@Before
public void setUp() throws Exception {
    ((MapzenApplication) application).inject(this);
    MockitoAnnotations.initMocks(this);
    savedSearch.clear();
    menu = new TestMenu();
    baseActivity = TestHelper.initBaseActivityWithMenu(menu);
    fragmentManager = baseActivity.getSupportFragmentManager();
    adapter = new AutoCompleteAdapter(baseActivity.getSupportActionBar().getThemedContext(),
            baseActivity, ((MapzenApplication) application).getColumns(), fragmentManager);
    adapter.setSearchView(baseActivity.getSearchView());
    adapter.setMapFragment(initMapFragment(baseActivity));
    view = (TextView) adapter.newView(baseActivity,
            new TestCursor(), new FrameLayout(baseActivity));
    simpleFeature = getTestSimpleFeature();
    view.setTag(simpleFeature);
}
项目:FullRobolectricTestSample    文件:MenuInflaterTest.java   
@Test
public void shouldParseSubItemCorrectly() throws Exception {
  TestMenu testMenu = new TestMenu();
  new MenuInflater(context).inflate(R.menu.test_withchilds, testMenu);
  MenuItem mi = testMenu.findItem(R.id.test_submenu_1);
  assertTrue(mi.hasSubMenu());
  assertThat(mi.getSubMenu().size()).isEqualTo(2);
  assertThat(mi.getSubMenu().getItem(1).getTitle() + "").isEqualTo("Test menu item 3");
}
项目:FullRobolectricTestSample    文件:MenuInflaterTest.java   
@Test
public void shouldCreateActionViews() throws Exception {
  TestMenu testMenu = new TestMenu();
  new MenuInflater(context).inflate(R.menu.action_menu, testMenu);

  MenuItem item = testMenu.getItem(0);
  assertEquals(item.getActionView().getClass(), SearchView.class);
}
项目:robolectric-ant-sample    文件:RecentActivityActivityTest.java   
@Test
public void shouldSignOutWhenTheSignOutButtonIsClicked() throws Exception {
    TestMenu menu = new TestMenu();
    menu.add("garbage that should be cleared upon onPrepareOptionsMenu");

    activity.onPrepareOptionsMenu(menu);

    TestMenuItem signOutMenuItem = (TestMenuItem) menu.getItem(0);
    assertThat(signOutMenuItem.isEnabled(), equalTo(true));
    assertThat(signOutMenuItem.getTitle().toString(), equalTo("Sign Out"));

    signOutMenuItem.click();
    assertThat(authenticationGateway.isAuthenticated(), equalTo(false));
    assertThat(shadowOf(activity).isFinishing(), equalTo(true));
}
项目:robolectric-ant-sample    文件:RecentActivityActivityTest.java   
@Test
public void signOutButtonShouldBeDisabledWhenNotSignedIn() throws Exception {
    authenticationGateway.signOut();
    TestMenu menu = new TestMenu();

    activity.onPrepareOptionsMenu(menu);

    TestMenuItem signOutMenuItem = (TestMenuItem) menu.getItem(0);
    assertThat(signOutMenuItem.isEnabled(), equalTo(false));
    assertThat(signOutMenuItem.getTitle().toString(), equalTo("Sign Out"));
}
项目:open    文件:PagerResultsFragmentTest.java   
@Before
public void setUp() throws Exception {
    app = (MapzenApplication) application;
    app.inject(this);
    MockitoAnnotations.initMocks(this);
    menu = new TestMenu();
    act = initBaseActivityWithMenu(menu);
    initMapFragment(act);
    fragment = PagerResultsFragment.newInstance(act);
    TestHelper.startFragment(fragment, act);
}
项目:open    文件:TestHelper.java   
public static TestBaseActivity initBaseActivityWithMenu(TestMenu menu) {
    TestHelper.initLastKnownLocation();
    TestBaseActivity activity = buildActivity(TestBaseActivity.class)
            .create()
            .start()
            .resume()
            .visible()
            .get();

    activity.onCreateOptionsMenu(menu);
    return activity;
}
项目:open    文件:BaseActivityTest.java   
@Before
public void setUp() throws Exception {
    ((TestMapzenApplication) Robolectric.application).inject(this);
    menu = new TestMenu();
    activity = initBaseActivityWithMenu(menu);
    savedSearch.clear();
}
项目:open    文件:BaseActivityTest.java   
@Test
public void geoIntent_shouldSetQuery() throws Exception {
    Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("geo:0,0?q=Empire State Building"));
    Menu menu = new TestMenu();
    activity.setIntent(intent);
    activity.onCreateOptionsMenu(menu);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    assertThat(searchView.getQuery().toString()).isEqualTo("Empire State Building");
}
项目:open    文件:BaseActivityTest.java   
@Test
public void shouldHaveOSMLogoutOption() throws Exception {
    Token token = new Token("stuff", "fun");
    Menu menu = new TestMenu();
    activity.onCreateOptionsMenu(menu);
    activity.setAccessToken(token);
    MenuItem menuItem = menu.findItem(R.id.logout);
    assertThat(menuItem).isVisible();
}
项目:open    文件:BaseActivityTest.java   
@Test
public void onOptionsItemSelected_shouldLogout() throws Exception {
    Token token = new Token("stuff", "fun");
    Menu menu = new TestMenu();
    activity.onCreateOptionsMenu(menu);
    activity.setAccessToken(token);
    MenuItem menuItem = menu.findItem(R.id.logout);
    assertThat(app.getAccessToken()).isNotNull();
    activity.onOptionsItemSelected(menuItem);
    assertThat(app.getAccessToken()).isNull();
}
项目:Inside_Android_Testing    文件:RecentActivityActivityTest.java   
@Test
public void shouldSignOutWhenTheSignOutButtonIsClicked() throws Exception {
    TestMenu menu = new TestMenu();
    menu.add("garbage that should be cleared upon onPrepareOptionsMenu");

    activity.onPrepareOptionsMenu(menu);

    TestMenuItem signOutMenuItem = (TestMenuItem) menu.getItem(0);
    assertThat(signOutMenuItem.isEnabled(), equalTo(true));
    assertThat(signOutMenuItem.getTitle().toString(), equalTo("Sign Out"));

    signOutMenuItem.click();
    assertThat(authenticationGateway.isAuthenticated(), equalTo(false));
    assertThat(shadowOf(activity).isFinishing(), equalTo(true));
}
项目:Inside_Android_Testing    文件:RecentActivityActivityTest.java   
@Test
public void signOutButtonShouldBeDisabledWhenNotSignedIn() throws Exception {
    authenticationGateway.signOut();
    TestMenu menu = new TestMenu();

    activity.onPrepareOptionsMenu(menu);

    TestMenuItem signOutMenuItem = (TestMenuItem) menu.getItem(0);
    assertThat(signOutMenuItem.isEnabled(), equalTo(false));
    assertThat(signOutMenuItem.getTitle().toString(), equalTo("Sign Out"));
}
项目:FullRobolectricTestSample    文件:MenuInflaterTest.java   
@Test
public void shouldInflateComplexMenu() throws Exception {
  TestMenu testMenu = new TestMenu();
  new MenuInflater(context).inflate(R.menu.test_withchilds, testMenu);
  assertThat(testMenu.size()).isEqualTo(4);
}
项目:FullRobolectricTestSample    文件:MenuInflaterTest.java   
@Test(expected=I18nException.class)
public void shouldThrowExceptionOnI18nStrictModeInflateMenu() throws Exception {
  shadowOf(context).setStrictI18n(true);
  new MenuInflater(context).inflate(R.menu.test, new TestMenu());
}
项目:open    文件:TestHelper.java   
public static TestBaseActivity initBaseActivity() {
    return initBaseActivityWithMenu(new TestMenu());
}