From d0c4b675f47a45a3cd2b0b49aa53610cb1b88b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Muller?= Date: Wed, 27 Aug 2025 10:46:39 +0200 Subject: [PATCH] Fix some warnings and formatting issues in `:tests` --- .../material/animation/MotionSpecTest.java | 39 ++-- .../material/appbar/AppBarLayoutBaseTest.java | 42 ++-- .../bottomsheet/BottomSheetBehaviorTest.java | 22 +- .../BottomSheetBehaviorTouchTest.java | 2 +- .../BottomSheetDialogFragmentDismissTest.java | 2 +- .../bottomsheet/BottomSheetDialogTest.java | 2 +- .../MaterialDatePickerPagesTest.java | 4 +- .../MaterialDatePickerTestUtils.java | 14 +- .../datepicker/RecyclerIdlingResource.java | 2 +- .../FloatingActionButtonTest.java | 14 +- .../navigation/NavigationViewTest.java | 26 +-- .../shape/MaterialShapeDrawableDrawTest.java | 2 +- .../CoordinatorSnackbarWithFabTest.java | 2 +- .../material/snackbar/SnackbarTouchTest.java | 21 +- .../android/material/tabs/TabLayoutTest.java | 2 +- .../tabs/TabLayoutWithViewPagerTest.java | 2 +- .../material/testutils/ActivityUtils.java | 1 + .../testutils/DisableAnimationsRule.java | 3 +- .../material/testutils/NightModeRule.java | 4 +- .../material/testutils/PollingCheck.java | 4 +- .../material/testutils/TestDrawable.java | 4 +- .../material/testutils/TestUtilsActions.java | 3 - .../material/testutils/TestUtilsMatchers.java | 12 +- .../testutils/TextInputLayoutMatchers.java | 4 +- .../textfield/ExposedDropdownMenuTest.java | 13 +- .../textfield/TextInputLayoutIconsTest.java | 193 ++++++++---------- .../textfield/TextInputLayoutTest.java | 6 +- 27 files changed, 188 insertions(+), 257 deletions(-) diff --git a/tests/javatests/com/google/android/material/animation/MotionSpecTest.java b/tests/javatests/com/google/android/material/animation/MotionSpecTest.java index 4082fa8b18b..57fb695f991 100644 --- a/tests/javatests/com/google/android/material/animation/MotionSpecTest.java +++ b/tests/javatests/com/google/android/material/animation/MotionSpecTest.java @@ -22,20 +22,15 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import android.animation.Animator; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.animation.ValueAnimator; import android.content.res.TypedArray; import android.graphics.drawable.ColorDrawable; -import android.os.Build.VERSION; -import android.os.Build.VERSION_CODES; -import androidx.appcompat.app.AppCompatActivity; import android.util.Property; import android.view.View; import android.view.animation.PathInterpolator; -import androidx.interpolator.view.animation.FastOutLinearInInterpolator; -import androidx.interpolator.view.animation.FastOutSlowInInterpolator; +import androidx.appcompat.app.AppCompatActivity; import androidx.test.rule.ActivityTestRule; import androidx.test.runner.AndroidJUnit4; import com.google.android.material.testapp.animation.R; @@ -96,11 +91,7 @@ public void validateSetOfObjectAnimatorAlphaMotionTiming() { assertEquals(3, alpha.getDelay()); assertEquals(5, alpha.getDuration()); - if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { - assertThat(alpha.getInterpolator(), instanceOf(PathInterpolator.class)); - } else { - assertThat(alpha.getInterpolator(), instanceOf(FastOutLinearInInterpolator.class)); - } + assertThat(alpha.getInterpolator(), instanceOf(PathInterpolator.class)); assertEquals(7, alpha.getRepeatCount()); assertEquals(ValueAnimator.RESTART, alpha.getRepeatMode()); } @@ -111,8 +102,8 @@ public void validateSetOfObjectAnimatorAlphaMotionValues() { MotionSpec.createFromResource( activityTestRule.getActivity(), R.animator.valid_set_of_object_animator_motion_spec); View view = new View(activityTestRule.getActivity()); - Animator alphaAnimator = spec.getAnimator("alpha", view, View.ALPHA); - PropertyValuesHolder propertyValuesHolder = ((ObjectAnimator) alphaAnimator).getValues()[0]; + ObjectAnimator alphaAnimator = spec.getAnimator("alpha", view, View.ALPHA); + PropertyValuesHolder propertyValuesHolder = alphaAnimator.getValues()[0]; assertTrue(fromAndToValuesMatch(propertyValuesHolder, "0.2", "0.8")); } @@ -125,11 +116,7 @@ public void validateSetOfObjectAnimatorTranslationMotionTiming() { assertEquals(11, translation.getDelay()); assertEquals(13, translation.getDuration()); - if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { - assertThat(translation.getInterpolator(), instanceOf(PathInterpolator.class)); - } else { - assertThat(translation.getInterpolator(), instanceOf(FastOutSlowInInterpolator.class)); - } + assertThat(translation.getInterpolator(), instanceOf(PathInterpolator.class)); assertEquals(17, translation.getRepeatCount()); assertEquals(ValueAnimator.REVERSE, translation.getRepeatMode()); } @@ -140,9 +127,8 @@ public void validateSetOfObjectAnimatorTranslationMotionValues() { MotionSpec.createFromResource( activityTestRule.getActivity(), R.animator.valid_set_of_object_animator_motion_spec); View view = new View(activityTestRule.getActivity()); - Animator translationAnimator = spec.getAnimator("translation", view, View.TRANSLATION_X); - PropertyValuesHolder propertyValuesHolder = - ((ObjectAnimator) translationAnimator).getValues()[0]; + ObjectAnimator translationAnimator = spec.getAnimator("translation", view, View.TRANSLATION_X); + PropertyValuesHolder propertyValuesHolder = translationAnimator.getValues()[0]; assertTrue(fromAndToValuesMatch(propertyValuesHolder, "0", "101")); } @@ -152,9 +138,8 @@ public void validateSetOfObjectAnimatorEmptyMotionValues() { MotionSpec.createFromResource( activityTestRule.getActivity(), R.animator.valid_set_of_object_animator_motion_spec); View view = new View(activityTestRule.getActivity()); - Animator translationAnimator = spec.getAnimator("foo", view, View.TRANSLATION_X); - PropertyValuesHolder propertyValuesHolder = - ((ObjectAnimator) translationAnimator).getValues()[0]; + ObjectAnimator translationAnimator = spec.getAnimator("foo", view, View.TRANSLATION_X); + PropertyValuesHolder propertyValuesHolder = translationAnimator.getValues()[0]; assertTrue(fromAndToValuesMatch(propertyValuesHolder, "0.0", "0.0")); } @@ -164,8 +149,8 @@ public void getAnimatorForNonViewTarget() { MotionSpec.createFromResource( activityTestRule.getActivity(), R.animator.valid_set_of_object_animator_motion_spec); ColorDrawable drawable = new ColorDrawable(); - Animator alphaAnimator = spec.getAnimator("alpha", drawable, ALPHA); - PropertyValuesHolder propertyValuesHolder = ((ObjectAnimator) alphaAnimator).getValues()[0]; + ObjectAnimator alphaAnimator = spec.getAnimator("alpha", drawable, ALPHA); + PropertyValuesHolder propertyValuesHolder = alphaAnimator.getValues()[0]; assertTrue(fromAndToValuesMatch(propertyValuesHolder, "0.2", "0.8")); } @@ -173,7 +158,7 @@ public void getAnimatorForNonViewTarget() { new Property(Integer.class, "alpha") { @Override public void set(Object object, Integer value) { - ((ColorDrawable) object).setAlpha(value.intValue()); + ((ColorDrawable) object).setAlpha(value); } @Override diff --git a/tests/javatests/com/google/android/material/appbar/AppBarLayoutBaseTest.java b/tests/javatests/com/google/android/material/appbar/AppBarLayoutBaseTest.java index 995314b10f8..6ea45ff52d2 100644 --- a/tests/javatests/com/google/android/material/appbar/AppBarLayoutBaseTest.java +++ b/tests/javatests/com/google/android/material/appbar/AppBarLayoutBaseTest.java @@ -29,11 +29,7 @@ import static org.junit.Assert.assertEquals; import android.graphics.Color; -import android.os.Build; -import android.os.Build.VERSION; import android.os.SystemClock; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; import android.text.TextUtils; import android.view.View; import android.widget.TextView; @@ -42,6 +38,8 @@ import androidx.annotation.IntRange; import androidx.annotation.LayoutRes; import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import com.google.android.material.internal.BaseDynamicCoordinatorLayoutTest; @@ -60,8 +58,6 @@ public abstract class AppBarLayoutBaseTest extends BaseDynamicCoordinatorLayoutT protected Toolbar mToolbar; - protected TextView mTextView; - protected float mDefaultElevationValue; protected static void performVerticalSwipeUpGesture( @@ -106,9 +102,7 @@ protected void configureContent(@LayoutRes final int layoutResId, @StringRes fin } protected void assertAppBarElevation(float expectedValue) { - if (Build.VERSION.SDK_INT >= 21) { - assertEquals(expectedValue, ViewCompat.getElevation(mAppBar), 0.05f); - } + assertEquals(expectedValue, ViewCompat.getElevation(mAppBar), 0.05f); } protected void assertScrimAlpha(@IntRange(from = 0, to = 255) int alpha) { @@ -131,27 +125,21 @@ protected boolean matchesSafely(View view) { } protected void assertAccessibilityHasScrollForwardAction(boolean hasScrollForward) { - if (VERSION.SDK_INT >= 21) { - AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); - ViewCompat.onInitializeAccessibilityNodeInfo(mCoordinatorLayout, info); - assertThat( - AccessibilityUtils.hasAction( - info, - AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_SCROLL_FORWARD)) - .isEqualTo(hasScrollForward); - } + AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); + ViewCompat.onInitializeAccessibilityNodeInfo(mCoordinatorLayout, info); + assertThat( + AccessibilityUtils.hasAction( + info, AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_SCROLL_FORWARD)) + .isEqualTo(hasScrollForward); } protected void assertAccessibilityHasScrollBackwardAction(boolean hasScrollBackward) { - if (VERSION.SDK_INT >= 21) { - AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); - ViewCompat.onInitializeAccessibilityNodeInfo(mCoordinatorLayout, info); - assertThat( - AccessibilityUtils.hasAction( - info, - AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_SCROLL_BACKWARD)) - .isEqualTo(hasScrollBackward); - } + AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); + ViewCompat.onInitializeAccessibilityNodeInfo(mCoordinatorLayout, info); + assertThat( + AccessibilityUtils.hasAction( + info, AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_SCROLL_BACKWARD)) + .isEqualTo(hasScrollBackward); } protected void assertAccessibilityScrollable(boolean isScrollable) { diff --git a/tests/javatests/com/google/android/material/bottomsheet/BottomSheetBehaviorTest.java b/tests/javatests/com/google/android/material/bottomsheet/BottomSheetBehaviorTest.java index 3a8c707da4f..1d695ba6af5 100644 --- a/tests/javatests/com/google/android/material/bottomsheet/BottomSheetBehaviorTest.java +++ b/tests/javatests/com/google/android/material/bottomsheet/BottomSheetBehaviorTest.java @@ -234,7 +234,7 @@ public void perform(UiController uiController, View view) { } int duration = ViewConfiguration.getPressedStateDuration(); if (duration > 0) { - uiController.loopMainThreadForAtLeast((long) duration); + uiController.loopMainThreadForAtLeast(duration); } } finally { downEvent.recycle(); @@ -483,7 +483,7 @@ private void testSkipCollapsed_smallSwipe(int expectedState, float swipeViewHeig @MediumTest public void testSkipCollapsed_smallSwipe_remainsExpanded() throws Throwable { testSkipCollapsed_smallSwipe( - BottomSheetBehavior.STATE_EXPANDED, /* swipeViewHeightPercentage = */ 0.5f); + BottomSheetBehavior.STATE_EXPANDED, /* swipeViewHeightPercentage= */ 0.5f); } @Test @@ -491,14 +491,14 @@ public void testSkipCollapsed_smallSwipe_remainsExpanded() throws Throwable { public void testSkipCollapsedFullyExpanded_smallSwipe_remainsExpanded() throws Throwable { getBehavior().setFitToContents(false); testSkipCollapsed_smallSwipe( - BottomSheetBehavior.STATE_HALF_EXPANDED, /* swipeViewHeightPercentage = */ 0.5f); + BottomSheetBehavior.STATE_HALF_EXPANDED, /* swipeViewHeightPercentage= */ 0.5f); } @Test @MediumTest public void testSkipCollapsed_smallSwipePastThreshold_getsHidden() throws Throwable { testSkipCollapsed_smallSwipe( - BottomSheetBehavior.STATE_HIDDEN, /* swipeViewHeightPercentage = */ 0.75f); + BottomSheetBehavior.STATE_HIDDEN, /* swipeViewHeightPercentage= */ 0.75f); } @Test @@ -506,7 +506,7 @@ public void testSkipCollapsed_smallSwipePastThreshold_getsHidden() throws Throwa public void testSkipCollapsedFullyExpanded_smallSwipePastThreshold_getsHidden() throws Throwable { getBehavior().setFitToContents(false); testSkipCollapsed_smallSwipe( - BottomSheetBehavior.STATE_HIDDEN, /* swipeViewHeightPercentage = */ 0.75f); + BottomSheetBehavior.STATE_HIDDEN, /* swipeViewHeightPercentage= */ 0.75f); } @Test @@ -969,7 +969,7 @@ public void testFindScrollingChildEnabled() { disabledParent.addView(enabledChild); View scrollingChild = getBehavior().findScrollingChild(disabledParent); - assertThat(scrollingChild, is((View) enabledChild)); + assertThat(scrollingChild, is(enabledChild)); } @Test @@ -999,8 +999,7 @@ private void checkSetState(final int state, Matcher matcher) throws Throwa } } - private void checkSlideOffset(final int state, float slideOffset) - throws Throwable { + private void checkSlideOffset(final int state, float slideOffset) throws Throwable { registerIdlingResourceCallback(); try { activityTestRule.runOnUiThread(() -> getBehavior().setState(state)); @@ -1052,15 +1051,12 @@ private static void assertAccessibilityActions( state == BottomSheetBehavior.STATE_EXPANDED || state == BottomSheetBehavior.STATE_HALF_EXPANDED; boolean hasDismissAction = state != BottomSheetBehavior.STATE_HIDDEN && behavior.isHideable(); - assertThat( - hasCustomAccessibilityAction(behavior.expandActionIds), - equalTo(hasExpandAction)); + assertThat(hasCustomAccessibilityAction(behavior.expandActionIds), equalTo(hasExpandAction)); assertThat( hasCustomAccessibilityAction(behavior.expandHalfwayActionIds), equalTo(hasHalfExpandAction)); assertThat( - hasCustomAccessibilityAction(behavior.collapseActionIds), - equalTo(hasCollapseAction)); + hasCustomAccessibilityAction(behavior.collapseActionIds), equalTo(hasCollapseAction)); assertThat( AccessibilityUtils.hasAction(bottomSheet, AccessibilityNodeInfoCompat.ACTION_DISMISS), equalTo(hasDismissAction)); diff --git a/tests/javatests/com/google/android/material/bottomsheet/BottomSheetBehaviorTouchTest.java b/tests/javatests/com/google/android/material/bottomsheet/BottomSheetBehaviorTouchTest.java index 336d720e4c3..e8635713cc9 100644 --- a/tests/javatests/com/google/android/material/bottomsheet/BottomSheetBehaviorTouchTest.java +++ b/tests/javatests/com/google/android/material/bottomsheet/BottomSheetBehaviorTouchTest.java @@ -97,7 +97,7 @@ public void testSetUp() { public void testTouchCoordinatorLayout() { final CoordinatorLayoutActivity activity = activityTestRule.getActivity(); down = false; - Espresso.onView(sameInstance((View) activity.mCoordinatorLayout)) + Espresso.onView(sameInstance(activity.mCoordinatorLayout)) .perform(ViewActions.click()) // Click outside the bottom sheet .check( (view, e) -> { diff --git a/tests/javatests/com/google/android/material/bottomsheet/BottomSheetDialogFragmentDismissTest.java b/tests/javatests/com/google/android/material/bottomsheet/BottomSheetDialogFragmentDismissTest.java index 60d26ac6e76..46fb5bdc187 100644 --- a/tests/javatests/com/google/android/material/bottomsheet/BottomSheetDialogFragmentDismissTest.java +++ b/tests/javatests/com/google/android/material/bottomsheet/BottomSheetDialogFragmentDismissTest.java @@ -27,12 +27,12 @@ import android.content.DialogInterface; import android.os.Bundle; -import androidx.appcompat.widget.AppCompatTextView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatTextView; import androidx.test.espresso.Espresso; import androidx.test.filters.MediumTest; import androidx.test.rule.ActivityTestRule; diff --git a/tests/javatests/com/google/android/material/bottomsheet/BottomSheetDialogTest.java b/tests/javatests/com/google/android/material/bottomsheet/BottomSheetDialogTest.java index 39d0ddd8719..b7b86e8c838 100644 --- a/tests/javatests/com/google/android/material/bottomsheet/BottomSheetDialogTest.java +++ b/tests/javatests/com/google/android/material/bottomsheet/BottomSheetDialogTest.java @@ -34,9 +34,9 @@ import android.content.Context; import android.content.DialogInterface; import android.os.SystemClock; -import androidx.appcompat.widget.AppCompatTextView; import android.view.View; import android.widget.FrameLayout; +import androidx.appcompat.widget.AppCompatTextView; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.test.espresso.Espresso; import androidx.test.espresso.UiController; diff --git a/tests/javatests/com/google/android/material/datepicker/MaterialDatePickerPagesTest.java b/tests/javatests/com/google/android/material/datepicker/MaterialDatePickerPagesTest.java index 5ac0ba7e6d8..8743d0da302 100644 --- a/tests/javatests/com/google/android/material/datepicker/MaterialDatePickerPagesTest.java +++ b/tests/javatests/com/google/android/material/datepicker/MaterialDatePickerPagesTest.java @@ -27,12 +27,12 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; -import androidx.fragment.app.FragmentManager; -import androidx.appcompat.app.AppCompatActivity; import android.view.View; +import androidx.appcompat.app.AppCompatActivity; import androidx.arch.core.executor.testing.InstantTaskExecutorRule; import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; +import androidx.fragment.app.FragmentManager; import androidx.test.espresso.IdlingRegistry; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.ActivityTestRule; diff --git a/tests/javatests/com/google/android/material/datepicker/MaterialDatePickerTestUtils.java b/tests/javatests/com/google/android/material/datepicker/MaterialDatePickerTestUtils.java index 71b62fba475..65c20938f65 100644 --- a/tests/javatests/com/google/android/material/datepicker/MaterialDatePickerTestUtils.java +++ b/tests/javatests/com/google/android/material/datepicker/MaterialDatePickerTestUtils.java @@ -25,17 +25,17 @@ import static org.hamcrest.core.IsEqual.equalTo; import android.app.Activity; -import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; -import androidx.appcompat.app.AppCompatActivity; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import androidx.annotation.VisibleForTesting; +import androidx.appcompat.app.AppCompatActivity; import androidx.core.util.Pair; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import androidx.test.espresso.ViewInteraction; import androidx.test.espresso.action.CoordinatesProvider; import androidx.test.espresso.action.GeneralLocation; @@ -171,7 +171,7 @@ public static void clickDay(Month month, int day) { onView( allOf( isDescendantOfA(withTagValue(equalTo(MaterialCalendar.MONTHS_VIEW_GROUP_TAG))), - withTagValue(IsEqual.equalTo(month)), + withTagValue(IsEqual.equalTo(month)), withText(String.valueOf(day)))) .perform(click()); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); diff --git a/tests/javatests/com/google/android/material/datepicker/RecyclerIdlingResource.java b/tests/javatests/com/google/android/material/datepicker/RecyclerIdlingResource.java index cc250727a63..49628911eb8 100644 --- a/tests/javatests/com/google/android/material/datepicker/RecyclerIdlingResource.java +++ b/tests/javatests/com/google/android/material/datepicker/RecyclerIdlingResource.java @@ -15,9 +15,9 @@ */ package com.google.android.material.datepicker; +import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.OnScrollListener; -import androidx.annotation.NonNull; import androidx.test.espresso.IdlingResource; public class RecyclerIdlingResource implements IdlingResource { diff --git a/tests/javatests/com/google/android/material/floatingactionbutton/FloatingActionButtonTest.java b/tests/javatests/com/google/android/material/floatingactionbutton/FloatingActionButtonTest.java index 7069c76b554..2ce8ceb7008 100644 --- a/tests/javatests/com/google/android/material/floatingactionbutton/FloatingActionButtonTest.java +++ b/tests/javatests/com/google/android/material/floatingactionbutton/FloatingActionButtonTest.java @@ -257,15 +257,15 @@ public void testClickableTouchAndDragOffView() { @Test @MediumTest public void testOnClickListener() { - final View.OnClickListener listener = mock(View.OnClickListener.class); - final View view = activityTestRule.getActivity().findViewById(R.id.fab_standard); - view.setOnClickListener(listener); + final View.OnClickListener listener = mock(View.OnClickListener.class); + final View view = activityTestRule.getActivity().findViewById(R.id.fab_standard); + view.setOnClickListener(listener); - // Click on the fab - onView(withId(R.id.fab_standard)).perform(click()); + // Click on the fab + onView(withId(R.id.fab_standard)).perform(click()); - // And verify that the listener was invoked once - verify(listener, times(1)).onClick(view); + // And verify that the listener was invoked once + verify(listener, times(1)).onClick(view); } @Test diff --git a/tests/javatests/com/google/android/material/navigation/NavigationViewTest.java b/tests/javatests/com/google/android/material/navigation/NavigationViewTest.java index 578dc84a087..0d9a1490b84 100644 --- a/tests/javatests/com/google/android/material/navigation/NavigationViewTest.java +++ b/tests/javatests/com/google/android/material/navigation/NavigationViewTest.java @@ -15,7 +15,6 @@ */ package com.google.android.material.navigation; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.assertion.ViewAssertions.matches; @@ -64,11 +63,7 @@ import android.content.res.Resources; import android.graphics.Typeface; -import android.os.Build; -import android.os.Build.VERSION; import android.os.Parcelable; -import androidx.recyclerview.widget.RecyclerView; -import androidx.appcompat.widget.SwitchCompat; import android.util.SparseArray; import android.view.LayoutInflater; import android.view.Menu; @@ -77,6 +72,7 @@ import android.widget.TextView; import androidx.annotation.ColorInt; import androidx.annotation.IdRes; +import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.res.ResourcesCompat; import androidx.core.view.GravityCompat; import androidx.core.view.ViewCompat; @@ -84,6 +80,7 @@ import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionInfoCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionItemInfoCompat; import androidx.drawerlayout.widget.DrawerLayout; +import androidx.recyclerview.widget.RecyclerView; import androidx.test.espresso.matcher.ViewMatchers.Visibility; import androidx.test.filters.MediumTest; import androidx.test.rule.ActivityTestRule; @@ -166,12 +163,8 @@ public void testWillNotDraw() { // Open our drawer onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START)); - if (Build.VERSION.SDK_INT >= 21) { - if (navigationView.hasSystemWindowInsets()) { - assertFalse(navigationView.willNotDraw()); - } else { - assertTrue(navigationView.willNotDraw()); - } + if (navigationView.hasSystemWindowInsets()) { + assertFalse(navigationView.willNotDraw()); } else { assertTrue(navigationView.willNotDraw()); } @@ -206,9 +199,7 @@ public void testTextAppearance() { withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i])), isDescendantOfA(withId(R.id.start_drawer))); onView(menuItemMatcher).check(matches(withTextSize(newTextSize))); - if (VERSION.SDK_INT >= LOLLIPOP) { - onView(menuItemMatcher).check(matches(withTypefaceStyle(Typeface.NORMAL))); - } + onView(menuItemMatcher).check(matches(withTypefaceStyle(Typeface.NORMAL))); } } @@ -586,8 +577,7 @@ private void verifyCheckedAppearance( expectedToBeChecked ? checkedItemForeground : uncheckedItemForeground; final @ColorInt int expectedItemBackground = expectedToBeChecked ? checkedItemBackground : uncheckedItemBackground; - final int expectedItemTypefaceStyle = - expectedToBeChecked ? Typeface.BOLD : Typeface.NORMAL; + final int expectedItemTypefaceStyle = expectedToBeChecked ? Typeface.BOLD : Typeface.NORMAL; // For the background fill check we need to select a view that has its background // set by the current implementation (see disclaimer in testBackground) @@ -606,9 +596,7 @@ private void verifyCheckedAppearance( onView(menuItemTextMatcher).check(matches(withTextColor(expectedItemForeground))); // Check typeface style - if (VERSION.SDK_INT >= LOLLIPOP) { - onView(menuItemTextMatcher).check(matches(withTypefaceStyle(expectedItemTypefaceStyle))); - } + onView(menuItemTextMatcher).check(matches(withTypefaceStyle(expectedItemTypefaceStyle))); } } diff --git a/tests/javatests/com/google/android/material/shape/MaterialShapeDrawableDrawTest.java b/tests/javatests/com/google/android/material/shape/MaterialShapeDrawableDrawTest.java index 6ff8a87b56d..3d55acd3eca 100644 --- a/tests/javatests/com/google/android/material/shape/MaterialShapeDrawableDrawTest.java +++ b/tests/javatests/com/google/android/material/shape/MaterialShapeDrawableDrawTest.java @@ -67,7 +67,7 @@ public void createNewDrawable_notRoundRect_pathIsCalculated() { } @Test - public void newDrawableFromContstantState() { + public void newDrawableFromConstantState() { Drawable copy = copyMaterialShapeDrawable(); copy.draw(new Canvas()); diff --git a/tests/javatests/com/google/android/material/snackbar/CoordinatorSnackbarWithFabTest.java b/tests/javatests/com/google/android/material/snackbar/CoordinatorSnackbarWithFabTest.java index 054e027ef0e..119d68d202b 100644 --- a/tests/javatests/com/google/android/material/snackbar/CoordinatorSnackbarWithFabTest.java +++ b/tests/javatests/com/google/android/material/snackbar/CoordinatorSnackbarWithFabTest.java @@ -24,9 +24,9 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; -import androidx.appcompat.widget.AppCompatTextView; import android.view.View; import android.view.ViewGroup; +import androidx.appcompat.widget.AppCompatTextView; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.test.espresso.UiController; import androidx.test.espresso.ViewAction; diff --git a/tests/javatests/com/google/android/material/snackbar/SnackbarTouchTest.java b/tests/javatests/com/google/android/material/snackbar/SnackbarTouchTest.java index e8e2ef9efa8..349c81cc9ef 100644 --- a/tests/javatests/com/google/android/material/snackbar/SnackbarTouchTest.java +++ b/tests/javatests/com/google/android/material/snackbar/SnackbarTouchTest.java @@ -57,16 +57,17 @@ public void setupAndShowSnackbar() { Snackbar.make(container, "Test Snackbar", Snackbar.LENGTH_INDEFINITE) .setAction("Do Action", mock(View.OnClickListener.class)); - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - CheckBox checkBox = new CheckBox(activity); - checkBox.setText("test checkbox"); - container.addView(checkBox); - checkBox.setLayoutParams( - new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); - } - }); + activity.runOnUiThread( + new Runnable() { + @Override + public void run() { + CheckBox checkBox = new CheckBox(activity); + checkBox.setText("test checkbox"); + container.addView(checkBox); + checkBox.setLayoutParams( + new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + } + }); snackbar.show(); } diff --git a/tests/javatests/com/google/android/material/tabs/TabLayoutTest.java b/tests/javatests/com/google/android/material/tabs/TabLayoutTest.java index cec75564ac6..2e64b7512d6 100644 --- a/tests/javatests/com/google/android/material/tabs/TabLayoutTest.java +++ b/tests/javatests/com/google/android/material/tabs/TabLayoutTest.java @@ -42,12 +42,12 @@ import android.animation.AnimatorListenerAdapter; import android.annotation.TargetApi; import android.os.Build; -import androidx.appcompat.app.AppCompatActivity; import android.view.InflateException; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.PointerIcon; import android.view.View; +import androidx.appcompat.app.AppCompatActivity; import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat; diff --git a/tests/javatests/com/google/android/material/tabs/TabLayoutWithViewPagerTest.java b/tests/javatests/com/google/android/material/tabs/TabLayoutWithViewPagerTest.java index f4954aee096..7d3d67ad7cc 100644 --- a/tests/javatests/com/google/android/material/tabs/TabLayoutWithViewPagerTest.java +++ b/tests/javatests/com/google/android/material/tabs/TabLayoutWithViewPagerTest.java @@ -381,7 +381,7 @@ public void testBasics() { verifyViewPagerSelection(); } - @Test + @Test @SmallTest public void testBadge() { setupTabLayoutWithViewPager(); diff --git a/tests/javatests/com/google/android/material/testutils/ActivityUtils.java b/tests/javatests/com/google/android/material/testutils/ActivityUtils.java index 251c4ac23b2..72e2492d7cd 100644 --- a/tests/javatests/com/google/android/material/testutils/ActivityUtils.java +++ b/tests/javatests/com/google/android/material/testutils/ActivityUtils.java @@ -53,6 +53,7 @@ private static void runOnUiThreadRethrow( } } } + /** * Restarts the RecreatedAppCompatActivity and waits for the new activity to be resumed. * diff --git a/tests/javatests/com/google/android/material/testutils/DisableAnimationsRule.java b/tests/javatests/com/google/android/material/testutils/DisableAnimationsRule.java index baf355db385..facdbfc3141 100644 --- a/tests/javatests/com/google/android/material/testutils/DisableAnimationsRule.java +++ b/tests/javatests/com/google/android/material/testutils/DisableAnimationsRule.java @@ -23,7 +23,7 @@ import org.junit.runner.Description; import org.junit.runners.model.Statement; -public class DisableAnimationsRule implements TestRule { +public class DisableAnimationsRule implements TestRule { @Override public Statement apply(Statement base, Description description) { @@ -40,4 +40,3 @@ public void evaluate() throws Throwable { }; } } - diff --git a/tests/javatests/com/google/android/material/testutils/NightModeRule.java b/tests/javatests/com/google/android/material/testutils/NightModeRule.java index 76437f115e8..34a0ca03e00 100644 --- a/tests/javatests/com/google/android/material/testutils/NightModeRule.java +++ b/tests/javatests/com/google/android/material/testutils/NightModeRule.java @@ -23,9 +23,7 @@ import org.junit.runner.Description; import org.junit.runners.model.Statement; -/** - * Runs tests for multiple night modes. - */ +/** Runs tests for multiple night modes. */ public final class NightModeRule implements TestRule { private static final int[] DEFAULT_NIGHT_MODES_TO_TEST = { diff --git a/tests/javatests/com/google/android/material/testutils/PollingCheck.java b/tests/javatests/com/google/android/material/testutils/PollingCheck.java index 28a65564c49..a026e596243 100644 --- a/tests/javatests/com/google/android/material/testutils/PollingCheck.java +++ b/tests/javatests/com/google/android/material/testutils/PollingCheck.java @@ -28,7 +28,9 @@ public abstract class PollingCheck { /** The condition that the PollingCheck should use to proceed successfully. */ public interface PollingCheckCondition { - /** @return Whether the polling condition has been met. */ + /** + * @return Whether the polling condition has been met. + */ boolean canProceed(); } diff --git a/tests/javatests/com/google/android/material/testutils/TestDrawable.java b/tests/javatests/com/google/android/material/testutils/TestDrawable.java index 91b00d97e1b..92943dd8d34 100644 --- a/tests/javatests/com/google/android/material/testutils/TestDrawable.java +++ b/tests/javatests/com/google/android/material/testutils/TestDrawable.java @@ -22,8 +22,8 @@ /** * Custom drawable class that provides a reliable way for testing various tinting scenarios across a * range of platform versions. ColorDrawable doesn't support tinting on Kitkat. Using - * GradientDrawable allows doing reliable tests at the level of individual channels - * (alpha / red / green / blue) for tinted and untinted icons in the testIconTinting method. + * GradientDrawable allows doing reliable tests at the level of individual channels (alpha / red / + * green / blue) for tinted and untinted icons in the testIconTinting method. */ public class TestDrawable extends GradientDrawable { private int width; diff --git a/tests/javatests/com/google/android/material/testutils/TestUtilsActions.java b/tests/javatests/com/google/android/material/testutils/TestUtilsActions.java index 7560a6a6bd3..1a56c8ad957 100644 --- a/tests/javatests/com/google/android/material/testutils/TestUtilsActions.java +++ b/tests/javatests/com/google/android/material/testutils/TestUtilsActions.java @@ -23,7 +23,6 @@ import static org.hamcrest.Matchers.any; import android.graphics.drawable.Drawable; -import android.os.Build.VERSION_CODES; import android.os.Parcelable; import android.util.SparseArray; import android.view.LayoutInflater; @@ -33,7 +32,6 @@ import androidx.annotation.LayoutRes; import androidx.annotation.MenuRes; import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; import androidx.core.view.ViewCompat; import androidx.core.widget.TextViewCompat; import androidx.test.espresso.UiController; @@ -506,7 +504,6 @@ public void perform(UiController uiController, View view) { } /** Sets system ui visibility to edge to edge config and waits for the change to complete. */ - @RequiresApi(VERSION_CODES.LOLLIPOP) public static ViewAction setSystemUiVisibilityEdgeToEdge() { return setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); diff --git a/tests/javatests/com/google/android/material/testutils/TestUtilsMatchers.java b/tests/javatests/com/google/android/material/testutils/TestUtilsMatchers.java index 191ab8c02c6..58d1f4bdd49 100644 --- a/tests/javatests/com/google/android/material/testutils/TestUtilsMatchers.java +++ b/tests/javatests/com/google/android/material/testutils/TestUtilsMatchers.java @@ -24,7 +24,6 @@ import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Build; -import androidx.appcompat.view.menu.MenuItemImpl; import android.text.TextUtils; import android.view.Gravity; import android.view.Menu; @@ -37,6 +36,7 @@ import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.view.menu.MenuItemImpl; import androidx.core.view.GravityCompat; import androidx.core.view.ViewCompat; import androidx.core.widget.TextViewCompat; @@ -380,10 +380,7 @@ public boolean matchesSafely(View view) { if (!(viewParent instanceof View)) { return false; } - if (parentMatcher.matches(viewParent)) { - return true; - } - return false; + return parentMatcher.matches(viewParent); } }; } @@ -544,10 +541,11 @@ public void describeTo(Description description) { @Override public boolean matchesSafely(View view) { - return Build.VERSION.SDK_INT < 21 || ViewCompat.getZ(view) > 0f; + return ViewCompat.getZ(view) > 0f; } }; } + /** * Returns a matcher that matches views which have a translationZ-value greater than 0. Also * matches if the platform we're running on does not support translationZ-values. @@ -561,7 +559,7 @@ public void describeTo(Description description) { @Override public boolean matchesSafely(View view) { - return Build.VERSION.SDK_INT < 21 || ViewCompat.getTranslationZ(view) > 0f; + return ViewCompat.getTranslationZ(view) > 0f; } }; } diff --git a/tests/javatests/com/google/android/material/testutils/TextInputLayoutMatchers.java b/tests/javatests/com/google/android/material/testutils/TextInputLayoutMatchers.java index 52c621a86fc..322af1958aa 100644 --- a/tests/javatests/com/google/android/material/testutils/TextInputLayoutMatchers.java +++ b/tests/javatests/com/google/android/material/testutils/TextInputLayoutMatchers.java @@ -28,8 +28,8 @@ public class TextInputLayoutMatchers { /** - * Returns a matcher that matches TextInputLayouts with non-empty content descriptions for the - * end icon. + * Returns a matcher that matches TextInputLayouts with non-empty content descriptions for the end + * icon. */ public static Matcher endIconHasContentDescription() { return new TypeSafeMatcher(TextInputLayout.class) { diff --git a/tests/javatests/com/google/android/material/textfield/ExposedDropdownMenuTest.java b/tests/javatests/com/google/android/material/textfield/ExposedDropdownMenuTest.java index bff8f61d74d..26d7d357038 100644 --- a/tests/javatests/com/google/android/material/textfield/ExposedDropdownMenuTest.java +++ b/tests/javatests/com/google/android/material/textfield/ExposedDropdownMenuTest.java @@ -69,7 +69,6 @@ public class ExposedDropdownMenuTest { public final ActivityTestRule activityTestRule = new ActivityTestRule<>(ExposedDropdownMenuActivity.class); - @Test public void testMenuIsNonEditableWithInputTypeNone() { final Activity activity = activityTestRule.getActivity(); @@ -147,8 +146,7 @@ public void testSetSimpleItemSelectedRippleColor_succeeds() { editText.setSimpleItemSelectedRippleColor(ColorStateList.valueOf(Color.BLUE)); - assertThat( - editText.getSimpleItemSelectedRippleColor(), is(ColorStateList.valueOf(Color.BLUE))); + assertThat(editText.getSimpleItemSelectedRippleColor(), is(ColorStateList.valueOf(Color.BLUE))); } @Test @@ -196,7 +194,6 @@ public void testLayoutClickHidesDropdownPopup() { onView(withId(R.id.filled_dropdown)).perform(click()); onView(withId(R.id.filled_dropdown)).perform(skipAnimations()); - // Hide dropdown. onView(withId(R.id.filled_dropdown)).perform(click()); onView(withId(R.id.filled_dropdown)).perform(skipAnimations()); @@ -238,9 +235,11 @@ public void testEndIconHasDefaultContentDescription() { @Test public void testEndIconIsAccessible() { - onView(allOf(withId(R.id.text_input_end_icon), - withContentDescription(R.string.exposed_dropdown_menu_content_description), - isDescendantOfA(withId(R.id.filled_dropdown)))) + onView( + allOf( + withId(R.id.text_input_end_icon), + withContentDescription(R.string.exposed_dropdown_menu_content_description), + isDescendantOfA(withId(R.id.filled_dropdown)))) .check(accessibilityAssertion()); } diff --git a/tests/javatests/com/google/android/material/textfield/TextInputLayoutIconsTest.java b/tests/javatests/com/google/android/material/textfield/TextInputLayoutIconsTest.java index 3db46d0d90e..eb346aad09a 100644 --- a/tests/javatests/com/google/android/material/textfield/TextInputLayoutIconsTest.java +++ b/tests/javatests/com/google/android/material/textfield/TextInputLayoutIconsTest.java @@ -120,8 +120,7 @@ public void testSetPasswordToggleProgrammatically() { .perform(setEndIconMode(TextInputLayout.END_ICON_PASSWORD_TOGGLE)); final Activity activity = activityTestRule.getActivity(); - final TextInputLayout textInputLayout = - activity.findViewById(R.id.textinput_no_icon); + final TextInputLayout textInputLayout = activity.findViewById(R.id.textinput_no_icon); // Assert the end icon is the password toggle icon assertEquals(TextInputLayout.END_ICON_PASSWORD_TOGGLE, textInputLayout.getEndIconMode()); @@ -134,8 +133,7 @@ public void testPasswordToggleClick() { .perform(typeText(INPUT_TEXT)); final Activity activity = activityTestRule.getActivity(); - final EditText textInput = - activity.findViewById(R.id.textinput_edittext_pwd); + final EditText textInput = activity.findViewById(R.id.textinput_edittext_pwd); // Assert that the password is disguised assertNotEquals(INPUT_TEXT, textInput.getLayout().getText().toString()); @@ -150,8 +148,7 @@ public void testPasswordToggleClick() { @Test public void testPasswordToggleDisable() { final Activity activity = activityTestRule.getActivity(); - final EditText textInput = - activity.findViewById(R.id.textinput_edittext_pwd); + final EditText textInput = activity.findViewById(R.id.textinput_edittext_pwd); // Set some text on the EditText onView(withId(R.id.textinput_edittext_pwd)) @@ -173,8 +170,7 @@ public void testPasswordToggleDisable() { @Test public void testPasswordToggleDisableWhenVisible() { final Activity activity = activityTestRule.getActivity(); - final EditText textInput = - activity.findViewById(R.id.textinput_edittext_pwd); + final EditText textInput = activity.findViewById(R.id.textinput_edittext_pwd); // Type some text on the EditText onView(withId(R.id.textinput_edittext_pwd)) @@ -195,8 +191,7 @@ public void testPasswordToggleDisableWhenVisible() { @Test public void testPasswordToggleIsHiddenAfterReenable() { final Activity activity = activityTestRule.getActivity(); - final EditText textInput = - activity.findViewById(R.id.textinput_edittext_pwd); + final EditText textInput = activity.findViewById(R.id.textinput_edittext_pwd); // Type some text on the EditText and then click the toggle button onView(withId(R.id.textinput_edittext_pwd)) @@ -249,10 +244,10 @@ public void testPasswordToggleHasDefaultContentDescription() { @Test public void testPasswordToggleIsAccessible() { onView( - allOf( - withId(R.id.text_input_end_icon), - withContentDescription(R.string.password_toggle_content_description), - isDescendantOfA(withId(R.id.textinput_password)))) + allOf( + withId(R.id.text_input_end_icon), + withContentDescription(R.string.password_toggle_content_description), + isDescendantOfA(withId(R.id.textinput_password)))) .check(accessibilityAssertion()); } @@ -294,8 +289,7 @@ public void testSetClearTextEndIconProgrammatically() { .perform(setEndIconMode(TextInputLayout.END_ICON_CLEAR_TEXT)); final Activity activity = activityTestRule.getActivity(); - final TextInputLayout textInputLayout = - activity.findViewById(R.id.textinput_no_icon); + final TextInputLayout textInputLayout = activity.findViewById(R.id.textinput_no_icon); // Assert the end icon is the clear button icon assertEquals(TextInputLayout.END_ICON_CLEAR_TEXT, textInputLayout.getEndIconMode()); @@ -307,8 +301,7 @@ public void testClearTextEndIconClick() { onView(withId(R.id.textinput_edittext_clear)) .perform(typeText(INPUT_TEXT)); final Activity activity = activityTestRule.getActivity(); - final EditText textInput = - activity.findViewById(R.id.textinput_edittext_clear); + final EditText textInput = activity.findViewById(R.id.textinput_edittext_clear); // Click clear button onView(withId(R.id.textinput_clear)).perform(clickIcon(true)); @@ -370,20 +363,18 @@ public void testClearTextEndIconHasDefaultContentDescription() { @Test public void testClearTextEndIconIsAccessible() { onView( - allOf( - withId(R.id.text_input_end_icon), - withContentDescription(R.string.clear_text_end_icon_content_description), - isDescendantOfA(withId(R.id.textinput_clear)))) + allOf( + withId(R.id.text_input_end_icon), + withContentDescription(R.string.clear_text_end_icon_content_description), + isDescendantOfA(withId(R.id.textinput_clear)))) .check(accessibilityAssertion()); } @Test public void testSwitchEndIconFromPasswordToggleToClearText() { final Activity activity = activityTestRule.getActivity(); - final TextInputLayout textInputLayoutPassword = - activity.findViewById(R.id.textinput_password); - final TextInputLayout textInputLayoutClear = - activity.findViewById(R.id.textinput_clear); + final TextInputLayout textInputLayoutPassword = activity.findViewById(R.id.textinput_password); + final TextInputLayout textInputLayoutClear = activity.findViewById(R.id.textinput_clear); String clearTextContentDesc = textInputLayoutClear.getEndIconContentDescription().toString(); // Set end icon as the clear button on the text field that has the password toggle set @@ -442,11 +433,9 @@ public void testSwitchEndIcon_clearTextToPasswordToggle_succeeds() { @Test public void testSetCustomEndIconProgrammatically() { final Activity activity = activityTestRule.getActivity(); - final TextInputLayout textInputCustomEndIcon = - activity.findViewById(R.id.textinput_custom); + final TextInputLayout textInputCustomEndIcon = activity.findViewById(R.id.textinput_custom); String expectedContentDesc = textInputCustomEndIcon.getEndIconContentDescription().toString(); - final TextInputLayout textInputLayout = - activity.findViewById(R.id.textinput_no_icon); + final TextInputLayout textInputLayout = activity.findViewById(R.id.textinput_no_icon); // Set end icon mode to custom end icon onView(withId(R.id.textinput_no_icon)) @@ -463,8 +452,7 @@ public void testSetCustomEndIconProgrammatically() { @Test public void testCustomEndIconOnClickListener() { final Activity activity = activityTestRule.getActivity(); - final TextInputLayout textInputCustomEndIcon = - activity.findViewById(R.id.textinput_custom); + final TextInputLayout textInputCustomEndIcon = activity.findViewById(R.id.textinput_custom); // Set custom on click listener onView(withId(R.id.textinput_custom)) .perform( @@ -558,7 +546,7 @@ public void testEndIconMaintainsCompoundDrawables() { } @Test - public void testSetStartIconProgrammatically() { + public void testSetStartIconProgrammatically() { final Activity activity = activityTestRule.getActivity(); final TextInputLayout textInputLayout = activity.findViewById(R.id.textinput_no_icon); Drawable drawable = new ColorDrawable(Color.BLACK); @@ -644,34 +632,32 @@ public void testStartIconOnLongClickListener() { assertEquals("Start icon on long click", textInputLayout.getEditText().getText().toString()); } - /** - * Simple test that uses AccessibilityChecks to check that the start icon is 'accessible'. - */ + /** Simple test that uses AccessibilityChecks to check that the start icon is 'accessible'. */ @Test public void testStartIconToggleIsAccessible() { onView( - allOf( - withId(R.id.text_input_start_icon), - isDescendantOfA(withId(R.id.textinput_starticon)))) + allOf( + withId(R.id.text_input_start_icon), + isDescendantOfA(withId(R.id.textinput_starticon)))) .check(accessibilityAssertion()); } @Test - public void testErrorIconAppears() { + public void testErrorIconAppears() { // Set error onView(withId(R.id.textinput_no_icon)).perform(setError("Error")); // Check the icon is visible onView( - allOf( - withId(R.id.text_input_error_icon), - withContentDescription(R.string.error_icon_content_description), - isDescendantOfA(withId(R.id.textinput_no_icon)))) + allOf( + withId(R.id.text_input_error_icon), + withContentDescription(R.string.error_icon_content_description), + isDescendantOfA(withId(R.id.textinput_no_icon)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); } @Test - public void testErrorIconDisappears() { + public void testErrorIconDisappears() { // Set error onView(withId(R.id.textinput_no_icon)).perform(setError("Error")); @@ -715,16 +701,16 @@ public void testErrorIconMaintainsEndIcon() { onView(withId(R.id.textinput_password)).perform(setError("Error")); // Check icon showing is error icon only onView( - allOf( - withId(R.id.text_input_error_icon), - withContentDescription(R.string.error_icon_content_description), - isDescendantOfA(withId(R.id.textinput_password)))) + allOf( + withId(R.id.text_input_error_icon), + withContentDescription(R.string.error_icon_content_description), + isDescendantOfA(withId(R.id.textinput_password)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); onView( - allOf( - withId(R.id.text_input_end_icon), - withContentDescription(R.string.password_toggle_content_description), - isDescendantOfA(withId(R.id.textinput_password)))) + allOf( + withId(R.id.text_input_end_icon), + withContentDescription(R.string.password_toggle_content_description), + isDescendantOfA(withId(R.id.textinput_password)))) .check(matches(withEffectiveVisibility(Visibility.GONE))); // Unset error @@ -732,24 +718,23 @@ public void testErrorIconMaintainsEndIcon() { // Check end icon is back onView( - allOf( - withId(R.id.text_input_error_icon), - withContentDescription(R.string.error_icon_content_description), - isDescendantOfA(withId(R.id.textinput_password)))) + allOf( + withId(R.id.text_input_error_icon), + withContentDescription(R.string.error_icon_content_description), + isDescendantOfA(withId(R.id.textinput_password)))) .check(matches(withEffectiveVisibility(Visibility.GONE))); onView( - allOf( - withId(R.id.text_input_end_icon), - withContentDescription(R.string.password_toggle_content_description), - isDescendantOfA(withId(R.id.textinput_password)))) + allOf( + withId(R.id.text_input_end_icon), + withContentDescription(R.string.password_toggle_content_description), + isDescendantOfA(withId(R.id.textinput_password)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); } @Test public void testErrorIconMaintainsDisguisedInputText() { final Activity activity = activityTestRule.getActivity(); - final EditText editText = - activity.findViewById(R.id.textinput_edittext_pwd); + final EditText editText = activity.findViewById(R.id.textinput_edittext_pwd); // Set some text on the EditText onView(withId(R.id.textinput_edittext_pwd)).perform(typeText(INPUT_TEXT)); // Assert that the password is disguised @@ -768,8 +753,7 @@ public void testSetPrefixProgrammatically() { onView(withId(R.id.textinput_no_icon)).perform(setPrefixText("$")); final Activity activity = activityTestRule.getActivity(); - final TextInputLayout textInputLayout = - activity.findViewById(R.id.textinput_no_icon); + final TextInputLayout textInputLayout = activity.findViewById(R.id.textinput_no_icon); // Assert the prefix is set assertEquals("$", textInputLayout.getPrefixText().toString()); @@ -781,8 +765,7 @@ public void testClearPrefix() { onView(withId(R.id.textinput_prefix)).perform(setPrefixText(null)); final Activity activity = activityTestRule.getActivity(); - final TextInputLayout textInputLayout = - activity.findViewById(R.id.textinput_prefix); + final TextInputLayout textInputLayout = activity.findViewById(R.id.textinput_prefix); // Assert the prefix is null assertNull(textInputLayout.getPrefixText()); @@ -794,9 +777,9 @@ public void testPrefixIsVisibleOnFocus() { onView(withId(R.id.textinput_prefix)).perform(click()); // Assert prefix is visible - onView(allOf( - withId(R.id.textinput_prefix_text), - isDescendantOfA(withId(R.id.textinput_prefix)))) + onView( + allOf( + withId(R.id.textinput_prefix_text), isDescendantOfA(withId(R.id.textinput_prefix)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); } @@ -806,18 +789,18 @@ public void testPrefixDisappearsIfEditTextIsEmpty() { onView(withId(R.id.textinput_prefix)).perform(click()); // Assert prefix is visible - onView(allOf( - withId(R.id.textinput_prefix_text), - isDescendantOfA(withId(R.id.textinput_prefix)))) + onView( + allOf( + withId(R.id.textinput_prefix_text), isDescendantOfA(withId(R.id.textinput_prefix)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); // Click on another text field onView(withId(R.id.textinput_no_icon)).perform(click()); // Assert prefix is not visible - onView(allOf( - withId(R.id.textinput_prefix_text), - isDescendantOfA(withId(R.id.textinput_prefix)))) + onView( + allOf( + withId(R.id.textinput_prefix_text), isDescendantOfA(withId(R.id.textinput_prefix)))) .check(matches(withEffectiveVisibility(Visibility.GONE))); } @@ -830,9 +813,9 @@ public void testPrefixStaysVisibleWithInputText() { onView(withId(R.id.textinput_no_icon)).perform(click()); // Assert suffix is still visible - onView(allOf( - withId(R.id.textinput_prefix_text), - isDescendantOfA(withId(R.id.textinput_prefix)))) + onView( + allOf( + withId(R.id.textinput_prefix_text), isDescendantOfA(withId(R.id.textinput_prefix)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); } @@ -842,8 +825,7 @@ public void testSetSuffixProgrammatically() { onView(withId(R.id.textinput_no_icon)).perform(setSuffixText("/100")); final Activity activity = activityTestRule.getActivity(); - final TextInputLayout textInputLayout = - activity.findViewById(R.id.textinput_no_icon); + final TextInputLayout textInputLayout = activity.findViewById(R.id.textinput_no_icon); // Assert the prefix is set assertEquals("/100", textInputLayout.getSuffixText().toString()); @@ -855,8 +837,7 @@ public void testClearSuffix() { onView(withId(R.id.textinput_suffix)).perform(setSuffixText(null)); final Activity activity = activityTestRule.getActivity(); - final TextInputLayout textInputLayout = - activity.findViewById(R.id.textinput_suffix); + final TextInputLayout textInputLayout = activity.findViewById(R.id.textinput_suffix); // Assert the suffix is null assertNull(textInputLayout.getSuffixText()); @@ -868,9 +849,9 @@ public void testSuffixIsVisibleOnFocus() { onView(withId(R.id.textinput_suffix)).perform(click()); // Assert suffix is visible - onView(allOf( - withId(R.id.textinput_suffix_text), - isDescendantOfA(withId(R.id.textinput_suffix)))) + onView( + allOf( + withId(R.id.textinput_suffix_text), isDescendantOfA(withId(R.id.textinput_suffix)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); } @@ -880,18 +861,18 @@ public void testSuffixDisappearsIfEditTextIsEmpty() { onView(withId(R.id.textinput_suffix)).perform(click()); // Assert prefix is visible - onView(allOf( - withId(R.id.textinput_suffix_text), - isDescendantOfA(withId(R.id.textinput_suffix)))) + onView( + allOf( + withId(R.id.textinput_suffix_text), isDescendantOfA(withId(R.id.textinput_suffix)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); // Click on another text field onView(withId(R.id.textinput_no_icon)).perform(click()); // Assert suffix is not visible - onView(allOf( - withId(R.id.textinput_suffix_text), - isDescendantOfA(withId(R.id.textinput_suffix)))) + onView( + allOf( + withId(R.id.textinput_suffix_text), isDescendantOfA(withId(R.id.textinput_suffix)))) .check(matches(withEffectiveVisibility(Visibility.GONE))); } @@ -904,9 +885,9 @@ public void testSuffixStaysVisibleWithInputText() { onView(withId(R.id.textinput_no_icon)).perform(click()); // Assert suffix is still visible - onView(allOf( - withId(R.id.textinput_suffix_text), - isDescendantOfA(withId(R.id.textinput_suffix)))) + onView( + allOf( + withId(R.id.textinput_suffix_text), isDescendantOfA(withId(R.id.textinput_suffix)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); } @@ -940,35 +921,33 @@ public void testSuffixMaintainsCompoundDrawables() { @Test public void testStartIconIconSize() { final Activity activity = activityTestRule.getActivity(); - final TextInputLayout textInputLayout = - activity.findViewById(R.id.textinput_starticon); + final TextInputLayout textInputLayout = activity.findViewById(R.id.textinput_starticon); - onView( - withId(R.id.textinput_starticon)).perform(setStartIconMinSize(50)); + onView(withId(R.id.textinput_starticon)).perform(setStartIconMinSize(50)); assertEquals(50, textInputLayout.getStartIconMinSize()); } @Test public void testStartIconInvalidIconSize() { - assertThrows(IllegalArgumentException.class, () -> onView( - withId(R.id.textinput_starticon)).perform(setStartIconMinSize(-1))); + assertThrows( + IllegalArgumentException.class, + () -> onView(withId(R.id.textinput_starticon)).perform(setStartIconMinSize(-1))); } @Test public void testEndIconIconSize() { final Activity activity = activityTestRule.getActivity(); - final TextInputLayout textInputLayout = - activity.findViewById(R.id.textinput_suffix); + final TextInputLayout textInputLayout = activity.findViewById(R.id.textinput_suffix); - onView( - withId(R.id.textinput_suffix)).perform(setEndIconMinSize(50)); + onView(withId(R.id.textinput_suffix)).perform(setEndIconMinSize(50)); assertEquals(50, textInputLayout.getEndIconMinSize()); } @Test public void testEndIconInvalidIconSize() { - assertThrows(IllegalArgumentException.class, () -> onView( - withId(R.id.textinput_suffix)).perform(setEndIconMinSize(-1))); + assertThrows( + IllegalArgumentException.class, + () -> onView(withId(R.id.textinput_suffix)).perform(setEndIconMinSize(-1))); } @Test diff --git a/tests/javatests/com/google/android/material/textfield/TextInputLayoutTest.java b/tests/javatests/com/google/android/material/textfield/TextInputLayoutTest.java index f89c669fd91..60d2c46f75a 100644 --- a/tests/javatests/com/google/android/material/textfield/TextInputLayoutTest.java +++ b/tests/javatests/com/google/android/material/textfield/TextInputLayoutTest.java @@ -383,7 +383,7 @@ public void testDispatchProvideAutofillStructure() { @Test public void testDrawableStateChanged() { final Activity activity = activityTestRule.getActivity(); - final TextInputLayout layout = (TextInputLayout) activity.findViewById(R.id.textinput); + final TextInputLayout layout = activity.findViewById(R.id.textinput); // Force a drawable state change. layout.drawableStateChanged(); @@ -1091,10 +1091,10 @@ private static ViewAssertion isBoxBackgroundColor(@ColorInt final int boxBackgro } private static ViewAssertion isShapeAppearanceModel( - @NonNull ShapeAppearanceModel shapeAppearanceModelt) { + @NonNull ShapeAppearanceModel shapeAppearanceModel) { return (view, noViewFoundException) -> { assertThat(view).isInstanceOf(TextInputLayout.class); - assertEquals(shapeAppearanceModelt, ((TextInputLayout) view).getShapeAppearanceModel()); + assertEquals(shapeAppearanceModel, ((TextInputLayout) view).getShapeAppearanceModel()); }; }