Closed GoogleCodeExporter closed 9 years ago
Original comment by vale...@google.com
on 23 Oct 2014 at 9:55
The link doesn't work, btw.
Original comment by vale...@google.com
on 23 Oct 2014 at 9:55
fixed link — https://gist.github.com/AlexKorovyansky/bb9e832bcb2ee86e4475
Original comment by Alex.Kor...@gmail.com
on 2 Nov 2014 at 2:01
I'm not sure whether testing getConstantState equality is the right approach.
I added the following test for your matcher:
public void testWithDrawable() {
ImageView iv = new ImageView(getInstrumentation().getTargetContext());
iv.setImageResource(android.R.drawable.zoom_plate);
Matcher<View> goodMatcher = withDrawable(android.R.drawable.zoom_plate);
assertThat(goodMatcher.toString(), not(containsString("zoom_plate")));
assertThat(goodMatcher.matches(iv), is(true)); <<<<<<<<<<<<<<<<<<<< FAILS HERE
assertThat(goodMatcher.toString(), containsString("zoom_plate"));
assertThat(withDrawable(android.R.drawable.star_on).matches(iv), is(false));
assertThat(withDrawable(-1).matches(iv), is(false));
}
It fails at the line:
return drawable.getConstantState().equals(resourcesDrawable.getConstantState());
Looking at a couple of implementation of ConstantState (e.g. BitmapState and
VectorDrawableState), they don't implement the equals method, so it would just
fall back to obj and fail. Do you have a test that works?
Original comment by vale...@google.com
on 26 Nov 2014 at 10:40
Yes, it works here —
@SmallTest
public void testLogout() throws Exception {
onView(withId(R.id.custom_actionbar_action_button))
.check(matches(withDrawable(R.drawable.ic_logout)));
}
Where drawable.ic_logout is based on png resource image.
Original comment by Alex.Kor...@gmail.com
on 27 Nov 2014 at 8:54
There is no good way to compare drawable instances across all API levels.
Original comment by nkors...@google.com
on 5 May 2015 at 6:00
Original issue reported on code.google.com by
Alex.Kor...@gmail.com
on 15 Aug 2014 at 2:35