Reputation: 31530
My class needs a bitmap but mockito's mock context object is not capable of doing that is seems:
public class PlayerTest {
@Mock // Mocking the android context class
Context mMockContext;
// intantiating object from that mocked class
Context mContext;
private Player player;
private Bitmap playerBitmap;
private int screenX;
private int screenY;
@Before
public void setupPlayer(){
playerBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.player);
player = new Player(mContext, screenX, screenY,playerBitmap);
}
...
Upvotes: 4
Views: 5222
Reputation: 1081
Can't you just annotate private Bitmap playerBitmap
with @Mock
?
I can't see the rest of the class, but I presume you're using the Mockito JUnit runner. If not, you'll need to either use that, or call MockitoAnnotations.initMocks(this)
in your setup method.
Upvotes: 7