From b8afe2b41f97bb544433da91eaeb272b3429aa65 Mon Sep 17 00:00:00 2001 From: isabellekim Date: Thu, 19 Dec 2019 12:11:36 -0500 Subject: [PATCH] Add types to Matchers to avoid warnings about raw types and unchecked method invocations. PiperOrigin-RevId: 286404247 --- .../material/appbar/AppBarLayoutBaseTest.java | 9 +++++---- .../material/navigation/NavigationViewTest.java | 14 +++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/javatests/com/google/android/material/appbar/AppBarLayoutBaseTest.java b/tests/javatests/com/google/android/material/appbar/AppBarLayoutBaseTest.java index 607bf6f12..bb2f1e5ab 100644 --- a/tests/javatests/com/google/android/material/appbar/AppBarLayoutBaseTest.java +++ b/tests/javatests/com/google/android/material/appbar/AppBarLayoutBaseTest.java @@ -39,6 +39,7 @@ import androidx.core.view.ViewCompat; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import android.text.TextUtils; +import android.view.View; import android.widget.TextView; import com.google.android.material.internal.BaseDynamicCoordinatorLayoutTest; import com.google.android.material.resources.TextAppearanceConfig; @@ -113,16 +114,16 @@ public abstract class AppBarLayoutBaseTest extends BaseDynamicCoordinatorLayoutT onView(withId(R.id.collapsing_app_bar)).check(matches(withScrimAlpha(alpha))); } - static Matcher withScrimAlpha(final int alpha) { - return new TypeSafeMatcher() { + static Matcher withScrimAlpha(final int alpha) { + return new TypeSafeMatcher(CollapsingToolbarLayout.class) { @Override public void describeTo(Description description) { description.appendText("CollapsingToolbarLayout has content scrim with alpha: " + alpha); } @Override - protected boolean matchesSafely(CollapsingToolbarLayout view) { - return alpha == view.getScrimAlpha(); + protected boolean matchesSafely(View view) { + return alpha == ((CollapsingToolbarLayout) view).getScrimAlpha(); } }; } diff --git a/tests/javatests/com/google/android/material/navigation/NavigationViewTest.java b/tests/javatests/com/google/android/material/navigation/NavigationViewTest.java index bb8247531..eead54cba 100644 --- a/tests/javatests/com/google/android/material/navigation/NavigationViewTest.java +++ b/tests/javatests/com/google/android/material/navigation/NavigationViewTest.java @@ -249,7 +249,7 @@ public class NavigationViewTest { // direct child of RecyclerView which is expected to have the background set // on it. If the internal implementation of NavigationView changes, the second // Matcher below will need to be tweaked. - Matcher menuItemMatcher = + Matcher menuItemMatcher = allOf( hasDescendant(withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i]))), isChildOfA(isAssignableFrom(RecyclerView.class)), @@ -265,7 +265,7 @@ public class NavigationViewTest { // And check that all the menu items have the new fill final @ColorInt int newFillColorBlue = ResourcesCompat.getColor(res, R.color.test_blue, null); for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) { - Matcher menuItemMatcher = + Matcher menuItemMatcher = allOf( hasDescendant(withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i]))), isChildOfA(isAssignableFrom(RecyclerView.class)), @@ -283,7 +283,7 @@ public class NavigationViewTest { // And check that all the menu items have the new fill final @ColorInt int newFillColorGreen = ResourcesCompat.getColor(res, R.color.test_green, null); for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) { - Matcher menuItemMatcher = + Matcher menuItemMatcher = allOf( hasDescendant(withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i]))), isChildOfA(isAssignableFrom(RecyclerView.class)), @@ -575,7 +575,7 @@ public class NavigationViewTest { // For the background fill check we need to select a view that has its background // set by the current implementation (see disclaimer in testBackground) - Matcher menuItemMatcher = + Matcher menuItemMatcher = allOf( hasDescendant(withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i]))), isChildOfA(isAssignableFrom(RecyclerView.class)), @@ -583,7 +583,7 @@ public class NavigationViewTest { onView(menuItemMatcher).check(matches(withBackgroundFill(expectedItemBackground))); // And for the foreground color check we need to select a view with the text content - Matcher menuItemTextMatcher = + Matcher menuItemTextMatcher = allOf( withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i])), isDescendantOfA(withId(R.id.start_drawer))); @@ -684,7 +684,7 @@ public class NavigationViewTest { // details of the NavigationMenu, while conditions 3 and 4 aim to be as generic as // possible and to not rely on the internal details of the current layout implementation // of an individual menu item in NavigationMenu. - Matcher menuItemMatcher = + Matcher menuItemMatcher = allOf( isDescendantOfA(withId(R.id.start_drawer)), isChildOfA(isAssignableFrom(RecyclerView.class)), @@ -698,7 +698,7 @@ public class NavigationViewTest { // Check that the full custom view is displayed without title and icon. final Resources res = activityTestRule.getActivity().getResources(); - Matcher customItemMatcher = + Matcher customItemMatcher = allOf( isDescendantOfA(withId(R.id.start_drawer)), isChildOfA(isAssignableFrom(RecyclerView.class)),