Search in sources :

Example 31 with UiThreadTest

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);
}
Also used : TabLayoutActions.selectTab(android.support.design.testutils.TabLayoutActions.selectTab) LayoutInflater(android.view.LayoutInflater) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 32 with UiThreadTest

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);
}
Also used : EditText(android.widget.EditText) EditorInfo(android.view.inputmethod.EditorInfo) TextInputLayoutActivity(android.support.design.testapp.TextInputLayoutActivity) Activity(android.app.Activity) UiThreadTest(android.support.test.annotation.UiThreadTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 33 with UiThreadTest

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);
}
Also used : SparseArray(android.util.SparseArray) TextInputLayoutActivity(android.support.design.testapp.TextInputLayoutActivity) Activity(android.app.Activity) Parcelable(android.os.Parcelable) UiThreadTest(android.support.test.annotation.UiThreadTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 34 with UiThreadTest

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]);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TestUtilsMatchers.withCompoundDrawable(android.support.design.testutils.TestUtilsMatchers.withCompoundDrawable) TextInputLayoutActivity(android.support.design.testapp.TextInputLayoutActivity) Activity(android.app.Activity) UiThreadTest(android.support.test.annotation.UiThreadTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 35 with UiThreadTest

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]);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TestUtilsMatchers.withCompoundDrawable(android.support.design.testutils.TestUtilsMatchers.withCompoundDrawable) TextInputLayoutActivity(android.support.design.testapp.TextInputLayoutActivity) Activity(android.app.Activity) UiThreadTest(android.support.test.annotation.UiThreadTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Aggregations

UiThreadTest (android.support.test.annotation.UiThreadTest)51 Test (org.junit.Test)48 RecordingObserver (com.jakewharton.rxbinding2.RecordingObserver)15 Action1 (rx.functions.Action1)14 Activity (android.app.Activity)9 SmallTest (android.support.test.filters.SmallTest)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 Action0 (rx.functions.Action0)7 LargeTest (android.support.test.filters.LargeTest)6 LayoutInflater (android.view.LayoutInflater)6 Menu (android.view.Menu)6 AllTypes (io.realm.entities.AllTypes)6 TextInputLayoutActivity (android.support.design.testapp.TextInputLayoutActivity)5 MediumTest (android.support.test.filters.MediumTest)5 MenuItem (android.view.MenuItem)5 TabLayoutActions.selectTab (android.support.design.testutils.TabLayoutActions.selectTab)4 Bundle (android.os.Bundle)3 KeyEvent (android.view.KeyEvent)3 Before (org.junit.Before)3 ColorDrawable (android.graphics.drawable.ColorDrawable)2