Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package ControllersTest; import DAO.Factory; import controllers.CabinetController; import controllers.CommentController; import javax.servlet.http.Cookie; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.MockitoAnnotations; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpSession; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.ui.ModelMap; @WebAppConfiguration @ContextConfiguration("servlet-context.xml") public class CommentControllerTest { @InjectMocks CommentController controller; private MockHttpSession session; private MockHttpServletRequest request; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); request = new MockHttpServletRequest(); session = new MockHttpSession(); } @Test public void commentControllerTest() throws Exception { String viewName = controller.processForm(request, session); assertNull(viewName); session.putValue("User", "TestUser"); request.addParameter("adid", "51"); request.addParameter("comment", "cool"); viewName = controller.processForm(request, session); assertEquals(viewName, "index"); Factory.getInstance().getCommentDAO().deleteCommentsByUserName("TestUser"); } }