Search in sources :

Example 1 with KiwixApplication

use of org.kiwix.kiwixmobile.KiwixApplication in project kiwix-android by kiwix.

the class NetworkTest method setUp.

@Before
public void setUp() {
    TestComponent component = DaggerTestComponent.builder().applicationModule(new ApplicationModule((KiwixApplication) getInstrumentation().getTargetContext().getApplicationContext())).build();
    ((KiwixApplication) getInstrumentation().getTargetContext().getApplicationContext()).setApplicationComponent(component);
    new ZimContentProvider().setupDagger();
    component.inject(this);
    InputStream library = NetworkTest.class.getClassLoader().getResourceAsStream("library.xml");
    InputStream metalinks = NetworkTest.class.getClassLoader().getResourceAsStream("test.zim.meta4");
    InputStream testzim = NetworkTest.class.getClassLoader().getResourceAsStream("testzim.zim");
    try {
        byte[] libraryBytes = IOUtils.toByteArray(library);
        mockWebServer.enqueue(new MockResponse().setBody(new String(libraryBytes)));
        byte[] metalinkBytes = IOUtils.toByteArray(metalinks);
        mockWebServer.enqueue(new MockResponse().setBody(new String(metalinkBytes)));
        mockWebServer.enqueue(new MockResponse().setHeader("Content-Length", 357269));
        Buffer buffer = new Buffer();
        buffer.write(IOUtils.toByteArray(testzim));
        buffer.close();
        mockWebServer.enqueue(new MockResponse().setBody(buffer));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Buffer(okio.Buffer) ZimContentProvider(org.kiwix.kiwixmobile.ZimContentProvider) MockResponse(okhttp3.mockwebserver.MockResponse) DaggerTestComponent(org.kiwix.kiwixmobile.di.components.DaggerTestComponent) TestComponent(org.kiwix.kiwixmobile.di.components.TestComponent) InputStream(java.io.InputStream) IOException(java.io.IOException) KiwixApplication(org.kiwix.kiwixmobile.KiwixApplication) ApplicationModule(org.kiwix.kiwixmobile.di.modules.ApplicationModule) Before(org.junit.Before)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Buffer (okio.Buffer)1 Before (org.junit.Before)1 KiwixApplication (org.kiwix.kiwixmobile.KiwixApplication)1 ZimContentProvider (org.kiwix.kiwixmobile.ZimContentProvider)1 DaggerTestComponent (org.kiwix.kiwixmobile.di.components.DaggerTestComponent)1 TestComponent (org.kiwix.kiwixmobile.di.components.TestComponent)1 ApplicationModule (org.kiwix.kiwixmobile.di.modules.ApplicationModule)1