package org.ngrinder.infra.spring;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.ngrinder.AbstractNGrinderTransactionalTest;
import org.ngrinder.model.User;
import org.ngrinder.user.service.MockUserContext;
import org.ngrinder.user.service.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.WebRequest;

public class UserHandlerMethodArgumentResolverTest extends AbstractNGrinderTransactionalTest {

	private UserHandlerMethodArgumentResolver resolver;

	@Autowired
	private MockUserContext mockUserContext;

	@Test
	public void testUserHandlerMethodArgument() throws Exception {
		resolver = new UserHandlerMethodArgumentResolver();
		MethodParameter parameter = mock(MethodParameter.class);
		final Class<?> class1 = User.class;
		when(parameter.getParameterType()).thenAnswer(new Answer<Class<?>>() {
			@Override
			public Class<?> answer(InvocationOnMock invocation) throws Throwable {
				return class1;
			}
		});
		assertThat(resolver.supportsParameter(parameter), is(true));
		NativeWebRequest webRequest = mock(NativeWebRequest.class);
		when(webRequest.getParameter("ownerId")).thenReturn("admin");
		resolver.setUserContext(mockUserContext);
		Object resolveArgument = resolver.resolveArgument(parameter, null, webRequest, null);
		assertThat(((User)resolveArgument).getUserId(), is("admin"));
	}
}

@@ -441,54 +441,8 @@
 xt;%0A
-import org.ngrinder.user.service.UserContext;%0A
 impo
@@ -617,67 +617,8 @@
 est;
-%0Aimport org.springframework.web.context.request.WebRequest;
 %0A%0Apu
@@ -1573,16 +1573,17 @@
 (((User)
+ 
 resolveA
@@ -1607,23 +1607,41 @@
 d(), is(
-%22admin%22
+getTestUser().getUserId()
 ));%0A%09%7D%0A%7D

Fix test failure