Search in sources :

Example 1 with IConversationStore

use of com.waz.zclient.core.stores.conversation.IConversationStore in project wire-android by wireapp.

the class FileUploadTest method assertFileUploadIntentInOneToOneConversation.

@Test
@SuppressLint("NewApi")
public void assertFileUploadIntentInOneToOneConversation() throws InterruptedException {
    // Mock conversation
    IConversation mockConversation = mock(IConversation.class);
    when(mockConversation.getType()).thenReturn(IConversation.Type.ONE_TO_ONE);
    when(mockConversation.isMemberOfConversation()).thenReturn(true);
    when(mockConversation.isActive()).thenReturn(true);
    MockHelper.setupConversationMocks(mockConversation, activity);
    IConversationStore mockConversationStore = activity.getStoreFactory().getConversationStore();
    // Mock intent result
    String action;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        action = Intent.ACTION_OPEN_DOCUMENT;
    } else {
        action = Intent.ACTION_GET_CONTENT;
    }
    Matcher<Intent> expectedIntent = allOf(hasAction(action), hasType("*/*"));
    Intent intent = new Intent();
    intent.setData(Uri.parse("file:///tmp/whatever.txt"));
    Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, intent);
    intending(expectedIntent).respondWith(result);
    // attach fragment
    attachFragment(ConversationFragment.newInstance(), ConversationFragment.TAG);
    // verify stuff
    Thread.sleep(500);
    onView(withId(R.id.cursor_menu_item_more)).perform(click());
    Thread.sleep(500);
    onView(withId(R.id.cursor_menu_item_file)).perform(click());
    Thread.sleep(200);
    verify(mockConversationStore).sendMessage(any(AssetForUpload.class), any(MessageContent.Asset.ErrorHandler.class));
}
Also used : MessageContent(com.waz.api.MessageContent) IConversationStore(com.waz.zclient.core.stores.conversation.IConversationStore) Instrumentation(android.app.Instrumentation) AssetForUpload(com.waz.api.AssetForUpload) IConversation(com.waz.api.IConversation) Intent(android.content.Intent) FragmentTest(com.waz.zclient.testutils.FragmentTest) Test(org.junit.Test) SuppressLint(android.annotation.SuppressLint)

Example 2 with IConversationStore

use of com.waz.zclient.core.stores.conversation.IConversationStore in project wire-android by wireapp.

the class FileUploadTest method assertFileIsLargeWarningShowed.

@Test
@SuppressLint("NewApi")
public void assertFileIsLargeWarningShowed() throws InterruptedException {
    IConversation mockConversation = mock(IConversation.class);
    when(mockConversation.getType()).thenReturn(IConversation.Type.ONE_TO_ONE);
    when(mockConversation.isMemberOfConversation()).thenReturn(true);
    when(mockConversation.isActive()).thenReturn(true);
    MockHelper.setupConversationMocks(mockConversation, activity);
    IConversationStore mockConversationStore = activity.getStoreFactory().getConversationStore();
    // Mock intent result
    String action;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        action = Intent.ACTION_OPEN_DOCUMENT;
    } else {
        action = Intent.ACTION_GET_CONTENT;
    }
    Matcher<Intent> expectedIntent = allOf(hasAction(action), hasType("*/*"));
    Intent intent = new Intent();
    intent.setData(Uri.parse("file:///tmp/whatever.txt"));
    Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, intent);
    intending(expectedIntent).respondWith(result);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            MessageContent.Asset.ErrorHandler errorHandler = (MessageContent.Asset.ErrorHandler) args[1];
            errorHandler.noWifiAndFileIsLarge(20 * 1024 * 1024, NetworkMode._3G, mock(MessageContent.Asset.Answer.class));
            return null;
        }
    }).when(mockConversationStore).sendMessage(any(AssetForUpload.class), any(MessageContent.Asset.ErrorHandler.class));
    // attach fragment
    attachFragment(ConversationFragment.newInstance(), ConversationFragment.TAG);
    // verify stuff
    Thread.sleep(500);
    onView(withId(R.id.cursor_menu_item_more)).perform(click());
    Thread.sleep(500);
    onView(withId(R.id.cursor_menu_item_file)).perform(click());
    Thread.sleep(200);
    onView(withText(activity.getString(R.string.asset_upload_warning__large_file__title))).check(isVisible());
}
Also used : MessageContent(com.waz.api.MessageContent) IConversationStore(com.waz.zclient.core.stores.conversation.IConversationStore) Instrumentation(android.app.Instrumentation) IConversation(com.waz.api.IConversation) Intent(android.content.Intent) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AssetForUpload(com.waz.api.AssetForUpload) FragmentTest(com.waz.zclient.testutils.FragmentTest) Test(org.junit.Test) SuppressLint(android.annotation.SuppressLint)

Example 3 with IConversationStore

use of com.waz.zclient.core.stores.conversation.IConversationStore in project wire-android by wireapp.

the class MockHelper method setupConversationMocks.

public static void setupConversationMocks(final IConversation mockConversation, final TestActivity activity) {
    IConversationStore mockConversationStore = activity.getStoreFactory().getConversationStore();
    when(mockConversationStore.getCurrentConversation()).thenReturn(mockConversation);
    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();
            ConversationStoreObserver o = (ConversationStoreObserver) args[0];
            o.onCurrentConversationHasChanged(null, mockConversation, ConversationChangeRequester.UPDATER);
            return null;
        }
    }).when(mockConversationStore).addConversationStoreObserverAndUpdate(any(ConversationStoreObserver.class));
    doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            ConversationStoreObserver o = (ConversationStoreObserver) args[0];
            o.onCurrentConversationHasChanged(null, mockConversation, ConversationChangeRequester.UPDATER);
            return null;
        }
    }).when(mockConversationStore).addConversationStoreObserver(any(ConversationStoreObserver.class));
}
Also used : ConversationStoreObserver(com.waz.zclient.core.stores.conversation.ConversationStoreObserver) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IConversationStore(com.waz.zclient.core.stores.conversation.IConversationStore) UpdateListener(com.waz.api.UpdateListener)

Aggregations

IConversationStore (com.waz.zclient.core.stores.conversation.IConversationStore)3 SuppressLint (android.annotation.SuppressLint)2 Instrumentation (android.app.Instrumentation)2 Intent (android.content.Intent)2 AssetForUpload (com.waz.api.AssetForUpload)2 IConversation (com.waz.api.IConversation)2 MessageContent (com.waz.api.MessageContent)2 FragmentTest (com.waz.zclient.testutils.FragmentTest)2 Test (org.junit.Test)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 UpdateListener (com.waz.api.UpdateListener)1 ConversationStoreObserver (com.waz.zclient.core.stores.conversation.ConversationStoreObserver)1