use of android.support.test.annotation.UiThreadTest in project material-components-android by material-components.
the class TabLayoutTest method testMultipleTabsWithCustomLayoutSelection1.
@Test
@UiThreadTest
public void testMultipleTabsWithCustomLayoutSelection1() {
final TabLayout.OnTabSelectedListener mockListener = mock(TabLayout.OnTabSelectedListener.class);
final LayoutInflater inflater = LayoutInflater.from(activityTestRule.getActivity());
final TabLayout tabs = (TabLayout) inflater.inflate(R.layout.design_tabs, null);
tabs.addOnTabSelectedListener(mockListener);
final TabLayout.Tab tab1 = tabs.newTab().setCustomView(R.layout.design_tab_item_custom);
tabs.addTab(tab1);
verify(mockListener, times(1)).onTabSelected(eq(tab1));
verify(mockListener, times(0)).onTabUnselected(any(TabLayout.Tab.class));
final TabLayout.Tab tab2 = tabs.newTab().setCustomView(R.layout.design_tab_item_custom);
tabs.addTab(tab2, true);
verify(mockListener, times(1)).onTabSelected(eq(tab2));
verify(mockListener, times(1)).onTabUnselected(eq(tab1));
final TabLayout.Tab tab3 = tabs.newTab().setCustomView(R.layout.design_tab_item_custom);
tabs.addTab(tab3);
verifyNoMoreInteractions(mockListener);
assertEquals("Second tab is selected", 1, tabs.getSelectedTabPosition());
assertTabCustomViewSelected(tabs);
}
use of android.support.test.annotation.UiThreadTest in project material-components-android by material-components.
the class TextInputLayoutTest method testExtractUiHintSet.
@UiThreadTest
@Test
public void testExtractUiHintSet() {
final Activity activity = activityTestRule.getActivity();
// Set a hint on the TextInputLayout
final TextInputLayout layout = (TextInputLayout) activity.findViewById(R.id.textinput);
layout.setHint(INPUT_TEXT);
final EditText editText = (EditText) activity.findViewById(R.id.textinput_edittext);
// Now manually pass in a EditorInfo to the EditText and make sure it updates the
// hintText to our known value
final EditorInfo info = new EditorInfo();
editText.onCreateInputConnection(info);
assertEquals(INPUT_TEXT, info.hintText);
}
use of android.support.test.annotation.UiThreadTest in project material-components-android by material-components.
the class TextInputLayoutTest method testSaveRestoreStateAnimation.
@UiThreadTest
@Test
public void testSaveRestoreStateAnimation() {
final Activity activity = activityTestRule.getActivity();
final TestTextInputLayout layout = new TestTextInputLayout(activity);
layout.setId(R.id.textinputlayout);
final TextInputEditText editText = new TextInputEditText(activity);
editText.setText(INPUT_TEXT);
editText.setId(R.id.textinputedittext);
layout.addView(editText);
SparseArray<Parcelable> container = new SparseArray<>();
layout.saveHierarchyState(container);
layout.restoreHierarchyState(container);
assertEquals("Expected no animations since we simply saved/restored state", 0, layout.animateToExpansionFractionCount);
editText.setText("");
assertEquals("Expected one call to animate because we cleared text in editText", 1, layout.animateToExpansionFractionCount);
assertEquals(0f, layout.animateToExpansionFractionRecentValue, 0f);
container = new SparseArray<>();
layout.saveHierarchyState(container);
layout.restoreHierarchyState(container);
assertEquals("Expected no additional animations since we simply saved/restored state", 1, layout.animateToExpansionFractionCount);
}
use of android.support.test.annotation.UiThreadTest in project material-components-android by material-components.
the class TextInputLayoutTest method testMaintainsStartEndCompoundDrawables.
@UiThreadTest
@Test
public void testMaintainsStartEndCompoundDrawables() throws Throwable {
final Activity activity = activityTestRule.getActivity();
// Set a known set of test compound drawables on the EditText
final Drawable start = new ColorDrawable(Color.RED);
final Drawable top = new ColorDrawable(Color.GREEN);
final Drawable end = new ColorDrawable(Color.BLUE);
final Drawable bottom = new ColorDrawable(Color.BLACK);
final TextInputEditText editText = new TextInputEditText(activity);
TextViewCompat.setCompoundDrawablesRelative(editText, start, top, end, bottom);
// Now add the EditText to a TextInputLayout
TextInputLayout til = (TextInputLayout) activity.findViewById(R.id.textinput_noedittext);
til.addView(editText);
// Finally assert that all of the drawables are untouched
final Drawable[] compoundDrawables = TextViewCompat.getCompoundDrawablesRelative(editText);
assertSame(start, compoundDrawables[0]);
assertSame(top, compoundDrawables[1]);
assertSame(end, compoundDrawables[2]);
assertSame(bottom, compoundDrawables[3]);
}
use of android.support.test.annotation.UiThreadTest in project material-components-android by material-components.
the class TextInputLayoutTest method testMaintainsLeftRightCompoundDrawables.
@UiThreadTest
@Test
public void testMaintainsLeftRightCompoundDrawables() throws Throwable {
final Activity activity = activityTestRule.getActivity();
// Set a known set of test compound drawables on the EditText
final Drawable left = new ColorDrawable(Color.RED);
final Drawable top = new ColorDrawable(Color.GREEN);
final Drawable right = new ColorDrawable(Color.BLUE);
final Drawable bottom = new ColorDrawable(Color.BLACK);
final TextInputEditText editText = new TextInputEditText(activity);
editText.setCompoundDrawables(left, top, right, bottom);
// Now add the EditText to a TextInputLayout
TextInputLayout til = (TextInputLayout) activity.findViewById(R.id.textinput_noedittext);
til.addView(editText);
// Finally assert that all of the drawables are untouched
final Drawable[] compoundDrawables = editText.getCompoundDrawables();
assertSame(left, compoundDrawables[0]);
assertSame(top, compoundDrawables[1]);
assertSame(right, compoundDrawables[2]);
assertSame(bottom, compoundDrawables[3]);
}
Aggregations