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:
Julian Harty 2017-08-15 10:39:38 -04:00 committed by Isaac Hutt
parent 58ebdce8ab
commit b9c009a2e0
4 changed files with 30 additions and 4 deletions

View File

@ -1,8 +1,13 @@
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.utils.TestNetworkInterceptor;
import org.mockito.Mockito;
import java.io.IOException;
@ -13,6 +18,8 @@ import dagger.Provides;
import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockWebServer;
import static org.mockito.Mockito.doReturn;
/**
* Created by mhutti1 on 14/04/17.
*/
@ -47,4 +54,14 @@ public class TestNetworkModule {
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;
}
}

View File

@ -2,6 +2,7 @@ package org.kiwix.kiwixmobile.di.modules;
import android.app.NotificationManager;
import android.content.Context;
import android.net.ConnectivityManager;
import org.kiwix.kiwixmobile.KiwixApplication;
import org.kiwix.kiwixmobile.utils.BookUtils;

View File

@ -1,5 +1,8 @@
package org.kiwix.kiwixmobile.di.modules;
import android.content.Context;
import android.net.ConnectivityManager;
import org.kiwix.kiwixmobile.BuildConfig;
import org.kiwix.kiwixmobile.network.KiwixService;
import org.kiwix.kiwixmobile.network.UserAgentInterceptor;
@ -23,4 +26,10 @@ import okhttp3.OkHttpClient;
@Provides @Singleton KiwixService provideKiwixService(OkHttpClient okHttpClient) {
return KiwixService.ServiceCreator.newHacklistService(okHttpClient, KIWIX_DOWNLOAD_URL);
}
@Provides @Singleton
ConnectivityManager provideConnectivityManager(Context context) {
return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
}
}

View File

@ -87,7 +87,7 @@ public class LibraryFragment extends Fragment
private DownloadServiceConnection mConnection = new DownloadServiceConnection();
private ConnectivityManager conMan;
@Inject ConnectivityManager conMan;
private ZimManageActivity faActivity;
@ -123,8 +123,7 @@ public class LibraryFragment extends Fragment
presenter.attachView(this);
DownloadService.setDownloadFragment(faActivity.mSectionsPagerAdapter.getDownloadFragment());
conMan =
(ConnectivityManager) super.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = conMan.getActiveNetworkInfo();
if (network == null || !network.isConnected()) {
noNetworkConnection();