Method being Tested (In Main Activity)
//This Method allows you to set the LeftDrawable Image to a grayed out (drawableDown)
//image for 300 millseconds then returns the LeftDrawable Image back to the orignal
//(drawableUp).On a button.
void buttonPressFeedbackLeft(final Button button, final int drawableDown,
final int drawableUp) {
button.setCompoundDrawablesWithIntrinsicBounds(drawableDown, 0, 0, 0);
button.postDelayed(new Runnable() {
public void run() {
button.setCompoundDrawablesWithIntrinsicBounds(drawableUp, 0,
0, 0);
}
}, 300);
}
Test in Test Project: (activity and i (intent) already set)
public void testbuttonPressFeedback(){
/*
* Start activity
*/
activity = startActivity(i, null, null);
/*
* get the backButton
*/
Button backButton = (Button) activity.findViewById(R.id.bottem_bar_prev);
/*
* get the backButton image (up and down image) as a Drawable
*/
int drawableDown = R.drawable.ic_menu_back_gray;
int drawableUp = R.drawable.ic_menu_back;
/*
* create a Drawable with the ResId
*/
Drawable drawableDownImage = activity.getResources().getDrawable(drawableDown);
Drawable drawableUpImage = activity.getResources().getDrawable(drawableDown);
/*
* Simulate button being pressed (running the buttonPressFeedback() method)
*/
activity.buttonPressFeedbackLeft(prevButton, drawableDown, drawableUp);
/*
* get the drawable array [left, top, right, bottom]
* compare drawable with the drawable found on the button.
*/
Drawable[] d = prevButton.getCompoundDrawables();
assertEquals(drawableDownImage,d[0]);
}
Stack Trace:
junit.framework.AssertionFailedError: expected:android.graphics.drawable.BitmapDrawable@413e7428 but was:android.graphics.drawable.BitmapDrawable@413e75c0
Question
I am assuming that the objects are not the same. So I have tried to look into getting the resource Id and comparing them but I don't think this is possible?
Is there another way to compare the Drawable which is being displayed on the Button?