/**
 * KEEP MOVING, FOLLOW YOUR HEART.
 */

package com.sundray.wnsBpm.servlet.task;

/**
 * @author yuxinghong
 *
 */
public class TaskTypeServletTest {

}

@@ -83,75 +83,1751 @@
 k;%0A%0A
-/**%0A * @author yuxinghong%0A *%0A */%0Apublic class TaskTypeServletTest %7B
+import java.io.IOException;%0Aimport java.io.PrintWriter;%0Aimport java.io.StringWriter;%0A%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0Aimport javax.servlet.http.HttpSession;%0A%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport static org.junit.Assert.*;%0Aimport static org.mockito.Mockito.*;%0A%0A/**%0A * @author yuxinghong%0A *%0A */%0Apublic class TaskTypeServletTest %7B%0A%09%0A%09private HttpServletRequest req;%09%09// mocked httpRequest%0A%09private HttpServletResponse resp;%09// mocked httpResponse%0A%09private HttpSession httpSession;%09// mocked httpSession%0A%09private StringWriter stringWriter;%09// httpResponse output%0A%09%0A%09%0A%09@Before%0A%09public void setup() throws IOException%7B%0A%09%09req = mock(HttpServletRequest.class);%0A%09%09resp = mock(HttpServletResponse.class);%0A%09%09httpSession = mock(HttpSession.class);%0A%09%09when(req.getSession()).thenReturn(httpSession);%0A%09%09resetHttpResponseBuffer();%0A%09%09%0A%09%7D%0A%09%0A%09%0A%09@After%0A%09public void teardown()%7B%0A%09%09%0A%09%7D%0A%09%0A%09%0A%09@Test%0A%09public void test() throws ServletException, IOException%7B%0A%09%09// mock httpRequest parameters%0A%09%09when(req.getParameter(%22queryCondition%22)).thenReturn(%22%7Bopr: 'list'%7D%22);%0A%09%09// mock httpSession parameters%0A%09%09when(httpSession.getAttribute(%22userId%22)).thenReturn(%2211111%22); %0A%09%09%0A%09%09// execute servlet post%0A%09%09new TaskTypeServlet().doPost(req, resp);%0A%09%09%0A%09%09// verify in http response%0A%09%09assertTrue(stringWriter.toString().contains(%22success%22));%0A%09%7D%0A%09%0A%09%0A%09/**%0A%09 * %E9%87%8D%E7%BD%AEHttpResponseWriter%EF%BC%8C%E4%B8%80%E4%B8%AATest%E4%B8%AD%EF%BC%8C%E5%8C%85%E5%90%AB%E5%A4%9A%E4%B8%AAdoPost%E6%88%96doGet%E7%AD%89%EF%BC%8C%E9%9C%80%E8%A6%81%E6%89%A7%E8%A1%8C%E6%AD%A4%E6%96%B9%E6%B3%95%EF%BC%8C%0A%09 * %E4%BB%A5%E5%85%8D%E6%AF%8F%E6%AC%A1%E5%93%8D%E5%BA%94%E7%9A%84%E6%95%B0%E6%8D%AE%E9%87%8D%E5%A4%8D%E8%BE%93%E5%87%BA%E5%88%B0stringWriter%E4%B8%AD%E3%80%82%0A%09 * @throws IOException%0A%09 */%0A%09private void resetHttpResponseBuffer() throws IOException%7B%0A%09%09stringWriter = new StringWriter();%0A%09%09when(resp.getWriter()).thenReturn(new PrintWriter(stringWriter));%0A%09%7D
 %0A%0A%7D%0A

add servlet test code