• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps MockResources trouble

josipj

Lurker
Feb 8, 2009
6
0
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.openR awResource(R.raw.list));
}
}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones