1. Download our Official Android App: Forums for Android!

MockResources trouble

Discussion in 'Computers' started by josipj, Jun 14, 2010.

  1. josipj

    josipj Lurker
    Thread Starter
    5

    Feb 8, 2009
    6
    0
    5
    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.

    Regards,

    Josip

    public class MyMockResources extends MockResources{

    @Override
    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();
    }

    @UsesMocks(MyMockResources.class)
    public void testClass() throws FileNotFoundException {

    MyMockResources resources = AndroidMock.createMock(MyMockResources.class);
    AndroidMock.replay(resources);
    parser.parseTrafficInformation(mockResources.openRawResource(R.raw.list));
    }
    }
     

    Advertisement

Share This Page

Loading...