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));
}
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());
}
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));
}
Aggregations