use of android.widget.TabHost in project robolectric by robolectric.
the class ShadowTabHostTest method shouldRetrieveTheCurrentViewFromTabContentFactory.
@Test
public void shouldRetrieveTheCurrentViewFromTabContentFactory() {
TabHost tabHost = new TabHost(context);
TabHost.TabSpec foo = tabHost.newTabSpec("Foo").setContent(tag -> {
TextView tv = new TextView(context);
tv.setText("The Text of " + tag);
return tv;
});
tabHost.addTab(foo);
tabHost.setCurrentTabByTag("Foo");
TextView textView = (TextView) tabHost.getCurrentView();
assertThat(textView.getText().toString()).isEqualTo("The Text of Foo");
}
use of android.widget.TabHost in project robolectric by robolectric.
the class ShadowTabHostTest method shouldFireTheTabChangeListenerWhenCurrentTabIsSet.
@Test
public void shouldFireTheTabChangeListenerWhenCurrentTabIsSet() {
TabHost tabHost = new TabHost(context);
TabHost.TabSpec foo = tabHost.newTabSpec("Foo");
TabHost.TabSpec bar = tabHost.newTabSpec("Bar");
TabHost.TabSpec baz = tabHost.newTabSpec("Baz");
tabHost.addTab(foo);
tabHost.addTab(bar);
tabHost.addTab(baz);
TestOnTabChangeListener listener = new TestOnTabChangeListener();
tabHost.setOnTabChangedListener(listener);
tabHost.setCurrentTab(2);
assertThat(listener.tag).isEqualTo("Baz");
}
use of android.widget.TabHost in project robolectric by robolectric.
the class ShadowTabHostTest method shouldGetTabWidget.
@Test
public void shouldGetTabWidget() {
TabActivity activity = Robolectric.buildActivity(TabActivity.class).create().get();
activity.setContentView(R.layout.tab_activity);
TabHost host = new TabHost(activity);
assertThat(host.getTabWidget()).isInstanceOf(TabWidget.class);
}
use of android.widget.TabHost in project robolectric by robolectric.
the class ShadowTabHostTest method canGetCurrentTab.
@Test
public void canGetCurrentTab() {
TabHost tabHost = new TabHost(context);
TabHost.TabSpec foo = tabHost.newTabSpec("Foo");
TabHost.TabSpec bar = tabHost.newTabSpec("Bar");
TabHost.TabSpec baz = tabHost.newTabSpec("Baz");
tabHost.addTab(foo);
tabHost.addTab(bar);
tabHost.addTab(baz);
assertThat(shadowOf(tabHost).getCurrentTabSpec()).isEqualTo(foo);
assertThat(tabHost.getCurrentTab()).isEqualTo(0);
tabHost.setCurrentTabByTag("Bar");
assertThat(tabHost.getCurrentTab()).isEqualTo(1);
assertThat(shadowOf(tabHost).getCurrentTabSpec()).isEqualTo(bar);
tabHost.setCurrentTabByTag("Foo");
assertThat(tabHost.getCurrentTab()).isEqualTo(0);
assertThat(shadowOf(tabHost).getCurrentTabSpec()).isEqualTo(foo);
tabHost.setCurrentTabByTag("Baz");
assertThat(tabHost.getCurrentTab()).isEqualTo(2);
assertThat(shadowOf(tabHost).getCurrentTabSpec()).isEqualTo(baz);
}
use of android.widget.TabHost in project robolectric by robolectric.
the class ShadowTabSpecTest method shouldGetAndSetTheIndicatorLabelAndIcon.
@Test
public void shouldGetAndSetTheIndicatorLabelAndIcon() {
TabHost.TabSpec spec = new TabHost(context).newTabSpec("foo").setContent(R.layout.main).setIndicator("labelText", icon1);
assertThat(shadowOf(spec).getIndicatorLabel()).isEqualTo("labelText");
assertThat(shadowOf(spec).getText()).isEqualTo("labelText");
assertThat(shadowOf(spec).getIndicatorIcon()).isSameInstanceAs(icon1);
}
Aggregations