private void refreshContactList() { new InteractorExecution<>(getContactsInteractor).result(new InteractorResult<List<Contact>>() { @Override public void onResult(List<Contact> result) { List<PresentationContact> presentationContacts = listMapper.map(result); getView().refreshContactsList(presentationContacts); } }).error(GetContactsError.class, new InteractorResult<GetContactsError>() { @Override public void onResult(GetContactsError error) { getView().showGetContactsError(); } }).execute(interactorInvoker); } }
public void execute(InteractorInvoker interactorInvoker) { interactorInvoker.execute(this); }
@Override public Object answer(InvocationOnMock invocation) throws Throwable { InteractorExecution execution = (InteractorExecution) invocation.getArguments()[0]; InteractorResponse response = execution.getInteractor().call(); InteractorError error = response.getError(); if (response.hasError() && execution.getInteractorErrorResult(error.getClass()) != null) { execution.getInteractorErrorResult(error.getClass()).onResult(error); } else if (execution.getInteractorResult() != null) { execution.getInteractorResult().onResult(response.getResult()); } return null; } }).when(interactorInvoker).execute(anyInteractorExecution());
public void obtainContact() { getContactInteractor.setData(contactMd5); new InteractorExecution<>(getContactInteractor).result(new InteractorResult<Contact>() { @Override public void onResult(Contact result) { getView().showContactData(presentationContactMapper.map(result)); } }).error(GetContactError.class, new InteractorResult<InteractorError>() { @Override public void onResult(InteractorError result) { getView().showGetContactError(); } }).execute(interactorInvoker); } }
public static InteractorInvoker create() { InteractorInvoker interactorInvoker = mock(InteractorInvoker.class); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { InteractorExecution execution = (InteractorExecution) invocation.getArguments()[0]; InteractorResponse response = execution.getInteractor().call(); InteractorError error = response.getError(); if (response.hasError() && execution.getInteractorErrorResult(error.getClass()) != null) { execution.getInteractorErrorResult(error.getClass()).onResult(error); } else if (execution.getInteractorResult() != null) { execution.getInteractorResult().onResult(response.getResult()); } return null; } }).when(interactorInvoker).execute(anyInteractorExecution()); return interactorInvoker; }