package org.codenergic.theskeleton.registration;

import org.codenergic.theskeleton.tokenstore.TokenStoreService;
import org.codenergic.theskeleton.user.UserEntity;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;

@RunWith(SpringRunner.class)
@EnableSpringDataWebSupport
@WebMvcTest(controllers = {RegistrationController.class}, secure = false)
public class RegistrationControllerTest {
	@Autowired
	private MockMvc mockMvc;
	@MockBean
	private RegistrationService registrationService;
	@MockBean
	private TokenStoreService tokenStoreService;
	@Test
	public void testRegisterUserAlreadyExist() throws Exception {
		String errorMsg = "Username or email already exists";
		when(registrationService.registerUser(any())).thenThrow(new RegistrationException(errorMsg));
		MockHttpServletRequestBuilder request = post("/registration")
			.param("username", "testuser")
			.param("password", "securepassword")
			.param("email", "theskeleton-test@codenergic.org");
		MockHttpServletResponse response = mockMvc.perform(request)
			.andReturn()
			.getResponse();
		assertThat(response.getStatus()).isEqualTo(200);
		assertThat(response.getContentAsString()).contains(errorMsg);
	}

	@Test
	public void testRegisterUser() throws Exception {
		UserEntity user = new UserEntity().setId("123");
		when(registrationService.registerUser(any())).thenReturn(user);
		when(tokenStoreService.sendTokenNotification(any(),any())).thenReturn(any());
		MockHttpServletRequestBuilder request = post("/registration")
			.param("username", "testuser")
			.param("password", "securepassword")
			.param("email", "theskeleton-test@codenergic.org");
		MockHttpServletResponse response = mockMvc.perform(request)
			.andReturn()
			.getResponse();
		assertThat(response.getStatus()).isEqualTo(200);
		assertThat(response.getContentAsString()).contains("We have sent");
	}
}

@@ -544,16 +544,83 @@
 sponse;%0A
+import org.springframework.social.connect.web.ProviderSignInUtils;%0A
 import o
@@ -1373,16 +1373,78 @@
 ervice;%0A
+%09@MockBean%0A%09private ProviderSignInUtils providerSignInUtils;%0A%0A
 %09@Test%0A%09

Add missing mockbean