Search in sources :

Example 1 with INetworkStore

use of com.waz.zclient.core.stores.network.INetworkStore in project wire-android by wireapp.

the class MockHelper method setupParticipantsMocks.

public static void setupParticipantsMocks(final IConversation mockConversation, final TestActivity activity) {
    IParticipantsStore mockParticipantsStore = activity.getStoreFactory().getParticipantsStore();
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            UpdateListener u = (UpdateListener) args[0];
            u.updated();
            return null;
        }
    }).when(mockConversation).addUpdateListener(any(UpdateListener.class));
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            ParticipantsStoreObserver o = (ParticipantsStoreObserver) args[0];
            o.conversationUpdated(mockConversation);
            return null;
        }
    }).when(mockParticipantsStore).addParticipantsStoreObserver(any(ParticipantsStoreObserver.class));
    INetworkStore mockNetworkStore = activity.getStoreFactory().getNetworkStore();
    when(mockNetworkStore.hasInternetConnection()).thenReturn(true);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            NetworkAction a = (NetworkAction) args[0];
            a.execute(NetworkMode.WIFI);
            return null;
        }
    }).when(mockNetworkStore).doIfHasInternetOrNotifyUser(any(NetworkAction.class));
}
Also used : ParticipantsStoreObserver(com.waz.zclient.core.stores.participants.ParticipantsStoreObserver) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IParticipantsStore(com.waz.zclient.core.stores.participants.IParticipantsStore) INetworkStore(com.waz.zclient.core.stores.network.INetworkStore) UpdateListener(com.waz.api.UpdateListener) NetworkAction(com.waz.zclient.core.stores.network.NetworkAction)

Example 2 with INetworkStore

use of com.waz.zclient.core.stores.network.INetworkStore in project wire-android by wireapp.

the class DeveloperPreferences method updateNetworkDebugInfo.

private void updateNetworkDebugInfo() {
    StringBuilder info = new StringBuilder();
    ConnectivityManager connectivityManager = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    info.append(connectivityManager == null ? "ConnectivityManager is null" : "ConnectivityManager:");
    NetworkInfo networkInfo = connectivityManager == null ? null : connectivityManager.getActiveNetworkInfo();
    if (networkInfo == null) {
        info.append("\nNetworkInfo is null");
    } else {
        info.append("\nnetworkInfo.isAvailable(): ");
        info.append(networkInfo.isAvailable());
        info.append("\nnetworkInfo.isConnected(): ");
        info.append(networkInfo.isConnected());
        info.append("\nnetworkInfo.isConnectedOrConnecting(): ");
        info.append(networkInfo.isConnectedOrConnecting());
        info.append("\nnetworkInfo.isFailover(): ");
        info.append(networkInfo.isFailover());
        info.append("\nnetworkInfo.isRoaming(): ");
        info.append(networkInfo.isRoaming());
        info.append("\nnetworkInfo.getDetailedState(): ");
        info.append(networkInfo.getDetailedState().name());
    }
    if (getStoreFactory() == null || getStoreFactory().isTornDown()) {
        info.append("\nStoreFactory is torn down");
    } else {
        INetworkStore ns = getStoreFactory().getNetworkStore();
        info.append("\nNetworkStore.hasInternetConnection(): ");
        info.append(ns.hasInternetConnection());
        info.append("\nNetworkStore.hasWifiConnection(): ");
        info.append(ns.hasWifiConnection());
    }
    Timber.i(info.toString());
    networkDebugInfoPreference.setSummary(info.toString());
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) INetworkStore(com.waz.zclient.core.stores.network.INetworkStore)

Aggregations

INetworkStore (com.waz.zclient.core.stores.network.INetworkStore)2 ConnectivityManager (android.net.ConnectivityManager)1 NetworkInfo (android.net.NetworkInfo)1 UpdateListener (com.waz.api.UpdateListener)1 NetworkAction (com.waz.zclient.core.stores.network.NetworkAction)1 IParticipantsStore (com.waz.zclient.core.stores.participants.IParticipantsStore)1 ParticipantsStoreObserver (com.waz.zclient.core.stores.participants.ParticipantsStoreObserver)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1