package io.crowdcode.flaschenlager.user.controller;

import io.crowdcode.flaschenlager.user.repository.UserRepository;
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.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@WebMvcTest(UserController.class)
public class UserControllerTest {

    public static final String USER_JSON = "{  \"email\": \"email_value\",  \"name\": \"name_value\",  \"password\": \"password_value\"}";

    @Autowired
    private MockMvc mvc;

    @MockBean
    private UserRepository userRepository;


    @Test
    public void testCreateCustomer() throws Exception {
        mvc.perform(MockMvcRequestBuilders.post("/user").content(USER_JSON)
                .contentType(MediaType.APPLICATION_JSON)
                .accept(MediaType.APPLICATION_JSON)).andExpect(status().isCreated());

    }


}
@@ -46,16 +46,127 @@
 oller;%0A%0A
+import io.crowdcode.flaschenlager.user.fixture.UserFixture;%0Aimport io.crowdcode.flaschenlager.user.model.User;%0A
 import i
@@ -711,16 +711,168 @@
 lders;%0A%0A
+import java.util.Arrays;%0A%0Aimport static org.mockito.Mockito.*;%0Aimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;%0A
 import s
@@ -1055,21 +1055,22 @@
 %7B%0A%0A    p
-ublic
+rivate
  static 
@@ -1191,16 +1191,122 @@
 e%5C%22%7D%22;%0A%0A
+    private static final String PASSWORD_JSON = %22%7B%5C%22oldPassword%5C%22:%5C%22secret2%5C%22,%5C%22newPassword%5C%22:%5C%22ZYX%5C%22%7D%22;%0A%0A
     @Aut
@@ -1437,14 +1437,10 @@
 eate
-Custom
+Us
 er()
@@ -1682,14 +1682,13 @@
 ));%0A
-%0A
     %7D%0A%0A%0A
 %7D
@@ -1686,9 +1686,1196 @@
     %7D%0A%0A%0A
+    @Test%0A    public void testUpdatePassword() throws Exception %7B%0A        User user = UserFixture.buildPersistentUser();%0A%0A        when(userRepository.findOne(2L))%0A                .thenReturn(user);%0A%0A        mvc.perform(MockMvcRequestBuilders.put(%22/user/%7BuserId%7D/change-password%22, 2L).content(PASSWORD_JSON)%0A                .contentType(MediaType.APPLICATION_JSON)%0A                .accept(MediaType.APPLICATION_JSON)).andExpect(status().isAccepted());%0A%0A        user.setPassword(%22ZYX%22);%0A%0A        verify(userRepository, times(1))%0A                .save(user);%0A    %7D%0A%0A    @Test%0A    public void testFindCustomer() throws Exception %7B%0A        when(userRepository.findAll())%0A                .thenReturn(Arrays.asList(UserFixture.buildDefaultUser(), UserFixture.buildPersistentUser()));%0A%0A        mvc.perform(MockMvcRequestBuilders.get(%22/user%22, 5l)%0A                .contentType(MediaType.APPLICATION_JSON)%0A                .accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())%0A%0A                .andExpect(content()%0A                        .json(%22 %5B%7B%5C%22id%5C%22:null,%5C%22email%5C%22:%5C%22junit@crowdcode.io%5C%22,%5C%22name%5C%22:%5C%22Name%5C%22%7D,%7B%5C%22id%5C%22:-2,%5C%22email%5C%22:%5C%22junit2@crowdcode.io%5C%22,%5C%22name%5C%22:%5C%22Name2%5C%22%7D%5D%22));%0A    %7D%0A
 %7D

enhance test