package ru.apetrov.controller;

import org.junit.Test;
import ru.apetrov.model.User;
import ru.apetrov.model.UserStore;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class AddUserTest {

    @Test
    public void addUser() throws IOException, SQLException {
        AddUser addUser = new AddUser();

        HttpServletRequest request = mock(HttpServletRequest.class);
        HttpServletResponse response = mock(HttpServletResponse.class);

        when(request.getParameter("login")).thenReturn("test");
        when(request.getParameter("password")).thenReturn("test");
        when(request.getParameter("name")).thenReturn("test");
        when(request.getParameter("email")).thenReturn("test@test");
        when(request.getParameter("role")).thenReturn("admin");

        addUser.doPost(request, response);

        UserStore store = UserStore.getInstance();
        List<User> list = store.getAll();

        assertThat(list.get(0).getLogin(), is("test"));
    }
}
@@ -1201,25 +1201,54 @@
     
-List%3CUser%3E list =
+boolean res = false;%0A%0A        for (User user :
  sto
@@ -1258,18 +1258,19 @@
 getAll()
-;%0A
+) %7B
 %0A       
@@ -1274,30 +1274,20 @@
     
-assertThat(list.get(0)
+    if (user
 .get
@@ -1297,11 +1297,14 @@
 in()
-, i
+.equal
 s(%22t
@@ -1309,16 +1309,105 @@
 %22test%22))
+ %7B%0A                res = true;%0A            %7D%0A        %7D%0A%0A        assertThat(res, is(true))
 ;%0A    %7D%0A

add Lesson-9.7 (update Test: add user)