1. HUGE Androidforums.com UPDATE! Learn what's new (and download the new app!)
    Dismiss Notice

MockResources trouble

Last Updated:

  1. josipj

    josipj Member This Topic's Starter

    Feb 8, 2009
    Likes Received:
    Hi all,

    I'm having trouble mocking a resource. What I want to do is to parse a web page using Htmlcleaner. Parsing the webpage works but now I want to use mocks. This is what i do:

    I have a class MyMockResources which extends from MockResources. MyMockResources has a overriden method openRawResource. I instantiate MyMockResources in a unit. An example file of the web page resides in the test project in 'res/raw/list'. When running the unit test I get a UnsupportedOperationException mock object, not implemented.

    Does anybody now what causes this and how to fix the problem? Class example are posted below.



    public class MyMockResources extends MockResources{

    public InputStream openRawResource(int id) throws NotFoundException {
    // TODO Auto-generated method stub
    return super.openRawResource(id);

    public class MyUnitTest extends AndroidTestCase {

    private MyMockResources mockResources;
    private FeedParserImpl parser;

    public void setUp() {
    mockResources = new MyMockResources();
    parser = new FeedParserImpl();

    public void testClass() throws FileNotFoundException {

    MyMockResources resources = AndroidMock.createMock(MyMockResources.class);
    parser.parseTrafficInformation(mockResources.openR awResource(R.raw.list));


Share This Page