package ca.six.todo.biz.add_task;

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 java.io.IOException;

import ca.six.todo.model.ToRequest;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

/**
 * Created by songzhw on 2017-03-05
 */
public class AddTaskViewModelTest {
    @Captor
    private ArgumentCaptor<Callback> captor;
    @Mock
    private IAddTaskView view;

    @Before
    public void init(){
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void addedNewTask_Succ() throws Exception {
        AddTaskViewModel vm = new AddTaskViewModel(view);
        ToRequest req = mock(ToRequest.class);
        vm.req = req;

        vm.addedNewTask(null);

        verify(req).sendRequest(anyString(), captor.capture());
        captor.getValue().onResponse(any(Call.class), any(Response.class));

        verify(view).addedTask(anyString(), anyString());
    }

}
@@ -1240,9 +1240,390 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void addedNewTask_Fail() throws Exception %7B%0A        AddTaskViewModel vm = new AddTaskViewModel(view);%0A        ToRequest req = mock(ToRequest.class);%0A        vm.req = req;%0A%0A        vm.addedNewTask(null);%0A%0A        verify(req).sendRequest(anyString(), captor.capture());%0A        captor.getValue().onFailure(null, null);%0A%0A        verify(view).addedFailed();%0A    %7D%0A
 %7D

add test