Sunday, June 22, 2014

Controller Test

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.util.ReflectionTestUtils;



public class UserControllerTest {

 
// Controller
    private ResourceRegistrationEndpoint controller;
    private IService resourceMock;

 

    @Before
    public void setUp() {
        controller = new ResourceRegistrationEndpoint();

        resourceMock = mock(IService.class);
// set Controller with IService with resourceMock
        ReflectionTestUtils.setField(controller, "service", resourceMock);
    }

    @Test
    public void getLoggedInUser() {
    OAuthParams oauthParams=new OAuthParams();
    Resource resource=new Resource();
        when(resourceMock.registerResource(resource)).thenReturn(resource);
        MockHttpServletRequest req=new MockHttpServletRequest();
        controller.authorize(oauthParams, req);

     
    }

 
}

No comments:

Post a Comment