Skip to content

Commit b8afe2b

Browse files
ikim24dsn5ft
authored andcommitted
Add types to Matchers to avoid warnings about raw types and unchecked
method invocations. PiperOrigin-RevId: 286404247
1 parent 8dd8ace commit b8afe2b

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

tests/javatests/com/google/android/material/appbar/AppBarLayoutBaseTest.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import androidx.appcompat.app.AppCompatActivity;
4040
import androidx.appcompat.widget.Toolbar;
4141
import android.text.TextUtils;
42+
import android.view.View;
4243
import android.widget.TextView;
4344
import com.google.android.material.internal.BaseDynamicCoordinatorLayoutTest;
4445
import com.google.android.material.resources.TextAppearanceConfig;
@@ -113,16 +114,16 @@ protected void assertScrimAlpha(@IntRange(from = 0, to = 255) int alpha) {
113114
onView(withId(R.id.collapsing_app_bar)).check(matches(withScrimAlpha(alpha)));
114115
}
115116

116-
static Matcher withScrimAlpha(final int alpha) {
117-
return new TypeSafeMatcher<CollapsingToolbarLayout>() {
117+
static Matcher<View> withScrimAlpha(final int alpha) {
118+
return new TypeSafeMatcher<View>(CollapsingToolbarLayout.class) {
118119
@Override
119120
public void describeTo(Description description) {
120121
description.appendText("CollapsingToolbarLayout has content scrim with alpha: " + alpha);
121122
}
122123

123124
@Override
124-
protected boolean matchesSafely(CollapsingToolbarLayout view) {
125-
return alpha == view.getScrimAlpha();
125+
protected boolean matchesSafely(View view) {
126+
return alpha == ((CollapsingToolbarLayout) view).getScrimAlpha();
126127
}
127128
};
128129
}

tests/javatests/com/google/android/material/navigation/NavigationViewTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public void testBackground() {
249249
// direct child of RecyclerView which is expected to have the background set
250250
// on it. If the internal implementation of NavigationView changes, the second
251251
// Matcher below will need to be tweaked.
252-
Matcher menuItemMatcher =
252+
Matcher<View> menuItemMatcher =
253253
allOf(
254254
hasDescendant(withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i]))),
255255
isChildOfA(isAssignableFrom(RecyclerView.class)),
@@ -265,7 +265,7 @@ public void testBackground() {
265265
// And check that all the menu items have the new fill
266266
final @ColorInt int newFillColorBlue = ResourcesCompat.getColor(res, R.color.test_blue, null);
267267
for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) {
268-
Matcher menuItemMatcher =
268+
Matcher<View> menuItemMatcher =
269269
allOf(
270270
hasDescendant(withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i]))),
271271
isChildOfA(isAssignableFrom(RecyclerView.class)),
@@ -283,7 +283,7 @@ public void testBackground() {
283283
// And check that all the menu items have the new fill
284284
final @ColorInt int newFillColorGreen = ResourcesCompat.getColor(res, R.color.test_green, null);
285285
for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) {
286-
Matcher menuItemMatcher =
286+
Matcher<View> menuItemMatcher =
287287
allOf(
288288
hasDescendant(withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i]))),
289289
isChildOfA(isAssignableFrom(RecyclerView.class)),
@@ -575,15 +575,15 @@ private void verifyCheckedAppearance(
575575

576576
// For the background fill check we need to select a view that has its background
577577
// set by the current implementation (see disclaimer in testBackground)
578-
Matcher menuItemMatcher =
578+
Matcher<View> menuItemMatcher =
579579
allOf(
580580
hasDescendant(withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i]))),
581581
isChildOfA(isAssignableFrom(RecyclerView.class)),
582582
isDescendantOfA(withId(R.id.start_drawer)));
583583
onView(menuItemMatcher).check(matches(withBackgroundFill(expectedItemBackground)));
584584

585585
// And for the foreground color check we need to select a view with the text content
586-
Matcher menuItemTextMatcher =
586+
Matcher<View> menuItemTextMatcher =
587587
allOf(
588588
withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i])),
589589
isDescendantOfA(withId(R.id.start_drawer)));
@@ -684,7 +684,7 @@ public void testActionLayout() {
684684
// details of the NavigationMenu, while conditions 3 and 4 aim to be as generic as
685685
// possible and to not rely on the internal details of the current layout implementation
686686
// of an individual menu item in NavigationMenu.
687-
Matcher menuItemMatcher =
687+
Matcher<View> menuItemMatcher =
688688
allOf(
689689
isDescendantOfA(withId(R.id.start_drawer)),
690690
isChildOfA(isAssignableFrom(RecyclerView.class)),
@@ -698,7 +698,7 @@ public void testActionLayout() {
698698

699699
// Check that the full custom view is displayed without title and icon.
700700
final Resources res = activityTestRule.getActivity().getResources();
701-
Matcher customItemMatcher =
701+
Matcher<View> customItemMatcher =
702702
allOf(
703703
isDescendantOfA(withId(R.id.start_drawer)),
704704
isChildOfA(isAssignableFrom(RecyclerView.class)),

0 commit comments

Comments
 (0)