Search in sources :

Example 1 with UserServices

use of io.github.hidroh.materialistic.accounts.UserServices in project materialistic by hidroh.

the class SubmitActivityTest method testSubmitError.

@Test
public void testSubmitError() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    verify(userServices).submit(any(Context.class), eq("title"), eq("http://example.com"), eq(true), submitCallback.capture());
    Uri redirect = Uri.parse(BuildConfig.APPLICATION_ID + "://item?id=1234");
    UserServices.Exception exception = new UserServices.Exception(R.string.item_exist);
    exception.data = redirect;
    submitCallback.getValue().onError(exception);
    assertEquals(activity.getString(R.string.item_exist), ShadowToast.getTextOfLatestToast());
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW).hasData(redirect);
}
Also used : EditText(android.widget.EditText) Context(android.content.Context) UserServices(io.github.hidroh.materialistic.accounts.UserServices) Uri(android.net.Uri) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Context (android.content.Context)1 Uri (android.net.Uri)1 EditText (android.widget.EditText)1 UserServices (io.github.hidroh.materialistic.accounts.UserServices)1 IOException (java.io.IOException)1 Test (org.junit.Test)1