mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
We now inject the network state so that the rest of the test is able to
run. See https://github.com/kiwix/kiwix-android/issues/227 for more detail.
This commit is contained in:
parent
58ebdce8ab
commit
b9c009a2e0
@ -1,8 +1,13 @@
|
|||||||
package org.kiwix.kiwixmobile.di.modules;
|
package org.kiwix.kiwixmobile.di.modules;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
|
||||||
import org.kiwix.kiwixmobile.network.KiwixService;
|
import org.kiwix.kiwixmobile.network.KiwixService;
|
||||||
import org.kiwix.kiwixmobile.utils.TestNetworkInterceptor;
|
import org.kiwix.kiwixmobile.utils.TestNetworkInterceptor;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -13,6 +18,8 @@ import dagger.Provides;
|
|||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.mockwebserver.MockWebServer;
|
import okhttp3.mockwebserver.MockWebServer;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mhutti1 on 14/04/17.
|
* Created by mhutti1 on 14/04/17.
|
||||||
*/
|
*/
|
||||||
@ -47,4 +54,14 @@ public class TestNetworkModule {
|
|||||||
|
|
||||||
return mockWebServer;
|
return mockWebServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides @Singleton
|
||||||
|
ConnectivityManager provideConnectivityManager(Context context) {
|
||||||
|
ConnectivityManager connectivityManager = Mockito.mock(ConnectivityManager.class);
|
||||||
|
NetworkInfo networkInfo = Mockito.mock(NetworkInfo.class);
|
||||||
|
doReturn(true).when(networkInfo).isConnected();
|
||||||
|
doReturn(networkInfo).when(connectivityManager).getActiveNetworkInfo();
|
||||||
|
return connectivityManager;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.kiwix.kiwixmobile.di.modules;
|
|||||||
|
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
|
||||||
import org.kiwix.kiwixmobile.KiwixApplication;
|
import org.kiwix.kiwixmobile.KiwixApplication;
|
||||||
import org.kiwix.kiwixmobile.utils.BookUtils;
|
import org.kiwix.kiwixmobile.utils.BookUtils;
|
||||||
@ -22,7 +23,7 @@ import dagger.Provides;
|
|||||||
return this.application;
|
return this.application;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides @Singleton NotificationManager provideNotificationManager(Context context){
|
@Provides @Singleton NotificationManager provideNotificationManager(Context context) {
|
||||||
return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package org.kiwix.kiwixmobile.di.modules;
|
package org.kiwix.kiwixmobile.di.modules;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
|
||||||
import org.kiwix.kiwixmobile.BuildConfig;
|
import org.kiwix.kiwixmobile.BuildConfig;
|
||||||
import org.kiwix.kiwixmobile.network.KiwixService;
|
import org.kiwix.kiwixmobile.network.KiwixService;
|
||||||
import org.kiwix.kiwixmobile.network.UserAgentInterceptor;
|
import org.kiwix.kiwixmobile.network.UserAgentInterceptor;
|
||||||
@ -23,4 +26,10 @@ import okhttp3.OkHttpClient;
|
|||||||
@Provides @Singleton KiwixService provideKiwixService(OkHttpClient okHttpClient) {
|
@Provides @Singleton KiwixService provideKiwixService(OkHttpClient okHttpClient) {
|
||||||
return KiwixService.ServiceCreator.newHacklistService(okHttpClient, KIWIX_DOWNLOAD_URL);
|
return KiwixService.ServiceCreator.newHacklistService(okHttpClient, KIWIX_DOWNLOAD_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides @Singleton
|
||||||
|
ConnectivityManager provideConnectivityManager(Context context) {
|
||||||
|
return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ public class LibraryFragment extends Fragment
|
|||||||
|
|
||||||
private DownloadServiceConnection mConnection = new DownloadServiceConnection();
|
private DownloadServiceConnection mConnection = new DownloadServiceConnection();
|
||||||
|
|
||||||
private ConnectivityManager conMan;
|
@Inject ConnectivityManager conMan;
|
||||||
|
|
||||||
private ZimManageActivity faActivity;
|
private ZimManageActivity faActivity;
|
||||||
|
|
||||||
@ -123,8 +123,7 @@ public class LibraryFragment extends Fragment
|
|||||||
presenter.attachView(this);
|
presenter.attachView(this);
|
||||||
|
|
||||||
DownloadService.setDownloadFragment(faActivity.mSectionsPagerAdapter.getDownloadFragment());
|
DownloadService.setDownloadFragment(faActivity.mSectionsPagerAdapter.getDownloadFragment());
|
||||||
conMan =
|
|
||||||
(ConnectivityManager) super.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
NetworkInfo network = conMan.getActiveNetworkInfo();
|
NetworkInfo network = conMan.getActiveNetworkInfo();
|
||||||
if (network == null || !network.isConnected()) {
|
if (network == null || !network.isConnected()) {
|
||||||
noNetworkConnection();
|
noNetworkConnection();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user