use of com.stanfy.enroscar.net.ContentUriConnection in project enroscar by stanfy.
the class RetrofitClientTest method init.
@Before
public void init() throws Exception {
EnroscarConnectionsEngine.config().treatFileScheme(false).setup(Robolectric.application);
testThing = new Thing();
testThing.name = "foo!";
mockResponse = new Gson().toJson(testThing);
File f = new File(Robolectric.application.getFilesDir(), "resp");
FileOutputStream out = new FileOutputStream(f);
out.write(mockResponse.getBytes());
out.close();
testResponseInput = new FileInputStream(f);
mockResolver = mock(ContentResolver.class);
doReturn("application/json").when(mockResolver).getType(any(Uri.class));
AssetFileDescriptor mockDescriptor = mock(AssetFileDescriptor.class);
doReturn(testResponseInput).when(mockDescriptor).createInputStream();
doReturn(mockDescriptor).when(mockResolver).openAssetFileDescriptor(any(Uri.class), any(String.class));
client = new RetrofitClient(new UrlConnectionBuilderFactory() {
@Override
public UrlConnectionBuilder newUrlConnectionBuilder() {
return new UrlConnectionBuilder() {
@Override
public URLConnection create() throws IOException {
URL url = getUrl();
if ("content".equals(url.getProtocol())) {
return new ContentUriConnection(url, mockResolver);
}
return super.create();
}
};
}
});
}
Aggregations