@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); }
@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"); }
@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); }
@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)); }
@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")); }
@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); }
public static TestBaseActivity initBaseActivityWithMenu(TestMenu menu) { TestHelper.initLastKnownLocation(); TestBaseActivity activity = buildActivity(TestBaseActivity.class) .create() .start() .resume() .visible() .get(); activity.onCreateOptionsMenu(menu); return activity; }
@Before public void setUp() throws Exception { ((TestMapzenApplication) Robolectric.application).inject(this); menu = new TestMenu(); activity = initBaseActivityWithMenu(menu); savedSearch.clear(); }
@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"); }
@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(); }
@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(); }
@Test public void shouldInflateComplexMenu() throws Exception { TestMenu testMenu = new TestMenu(); new MenuInflater(context).inflate(R.menu.test_withchilds, testMenu); assertThat(testMenu.size()).isEqualTo(4); }
@Test(expected=I18nException.class) public void shouldThrowExceptionOnI18nStrictModeInflateMenu() throws Exception { shadowOf(context).setStrictI18n(true); new MenuInflater(context).inflate(R.menu.test, new TestMenu()); }
public static TestBaseActivity initBaseActivity() { return initBaseActivityWithMenu(new TestMenu()); }