Created
June 22, 2017 14:54
-
-
Save prfarlow1/e2b3ea0933ab190ed90665a749824744 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package intrepid.io.fable; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.mockito.ArgumentCaptor; | |
import org.mockito.Captor; | |
import org.mockito.Mock; | |
import org.mockito.MockitoAnnotations; | |
import intrepid.io.fable.rest.CreateStoryRequest; | |
import intrepid.io.fable.rest.CreateStoryResponse; | |
import intrepid.io.fable.rest.RestApi; | |
import retrofit2.Call; | |
import retrofit2.Callback; | |
import retrofit2.Response; | |
import static org.mockito.ArgumentMatchers.any; | |
import static org.mockito.ArgumentMatchers.eq; | |
import static org.mockito.Mockito.verify; | |
import static org.mockito.Mockito.when; | |
public class NewFablePresenterTest { | |
@Mock | |
NewFableContract.View mockView; | |
@Mock | |
RestApi mockRestApi; | |
@Mock | |
Call<CreateStoryResponse> mockCall; | |
@Captor | |
ArgumentCaptor<Callback<CreateStoryResponse>> responseArgumentCaptor; | |
@Before | |
public void setup() { | |
MockitoAnnotations.initMocks(this); | |
} | |
@Test | |
public void onSubmitClickedTest() { | |
NewFablePresenter presenter = new NewFablePresenter(mockView, mockRestApi); | |
when(mockRestApi.createStory(any(CreateStoryRequest.class))).thenReturn(mockCall); | |
presenter.onSubmitClicked(); | |
verify(mockCall).enqueue(responseArgumentCaptor.capture()); | |
final Response<CreateStoryResponse> success = Response.success(new CreateStoryResponse()); | |
responseArgumentCaptor.getValue().onResponse(mockCall, success); | |
verify(mockView).fableCreated(eq(success.body())); | |
responseArgumentCaptor.getValue().onFailure(mockCall, any(Throwable.class)); | |
verify(mockView).showErrorMessage(R.string.error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment