package org.ngrinder.security;

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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.junit.Test;
import org.ngrinder.AbstractNGrinderTransactionalTest;
import org.ngrinder.model.User;
import org.ngrinder.user.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;

public class NgrinderUsernamePasswordAuthenticationFilterTest extends AbstractNGrinderTransactionalTest {
	private MockNgrinderUsernamePasswordAuthenticationFilter filter = new MockNgrinderUsernamePasswordAuthenticationFilter();

	private class MockNgrinderUsernamePasswordAuthenticationFilter extends NgrinderUsernamePasswordAuthenticationFilter {
		protected org.springframework.security.core.Authentication getAuthentification(
						javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) {
			Authentication auth = mock(Authentication.class);
			when(auth.getPrincipal()).thenReturn(new SecuredUser(getTestUser(), null));
			return auth;
		};

<<<<<<< OURS
		public void setUserRepository(UserRepository userRepository) {
			this.userRepository = userRepository;
		}
=======
>>>>>>> THEIRS
	};

	@Autowired
	private UserRepository userRepository;

	@Test
	public void testFilter() {
		filter.setUserRepository(userRepository);
		HttpServletRequest req = mock(HttpServletRequest.class);
		when(req.getParameter("user_timezone")).thenReturn("Korean");
		when(req.getParameter("native_language")).thenReturn("KoreanLang");
		HttpServletResponse res = mock(HttpServletResponse.class);
		filter.attemptAuthentication(req, res);
		User findOne = userRepository.findOne(getTestUser().getId());
		assertThat(findOne.getUserLanguage(), is("KoreanLang"));
		assertThat(findOne.getTimeZone(), is("Korean"));

	}
}

@@ -1259,153 +1259,8 @@
 %7D;%0A%0A
-%3C%3C%3C%3C%3C%3C%3C OURS%0A%09%09public void setUserRepository(UserRepository userRepository) %7B%0A%09%09%09this.userRepository = userRepository;%0A%09%09%7D%0A=======%0A%3E%3E%3E%3E%3E%3E%3E THEIRS
 %0A%09%7D;

clean up checkstyle errors.