Skip to content

Commit

Permalink
We now inject the network state so that the rest of the test is able to
Browse files Browse the repository at this point in the history
run. See #227 for more
detail.
  • Loading branch information
julianharty committed Aug 15, 2017
1 parent 58ebdce commit 1783d81
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,6 +18,8 @@
import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockWebServer;

import static org.mockito.Mockito.doReturn;

/**
* Created by mhutti1 on 14/04/17.
*/
Expand Down Expand Up @@ -47,4 +54,14 @@ public void run() {

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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.NotificationManager;
import android.content.Context;
import android.net.ConnectivityManager;

import org.kiwix.kiwixmobile.KiwixApplication;
import org.kiwix.kiwixmobile.utils.BookUtils;
Expand All @@ -22,7 +23,7 @@ public ApplicationModule(KiwixApplication application) {
return this.application;
}

@Provides @Singleton NotificationManager provideNotificationManager(Context context){
@Provides @Singleton NotificationManager provideNotificationManager(Context context) {
return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,4 +26,10 @@
@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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class LibraryFragment extends Fragment

private DownloadServiceConnection mConnection = new DownloadServiceConnection();

private ConnectivityManager conMan;
@Inject ConnectivityManager conMan;

private ZimManageActivity faActivity;

Expand Down Expand Up @@ -123,8 +123,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
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();
Expand Down

0 comments on commit 1783d81

Please sign in to comment.