Skip to content

Instantly share code, notes, and snippets.

Created November 14, 2019 15:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Exemplo de teste de servlet usando mocks
import javax.servlet.*;
import javax.servlet.http.*;
import org.junit.*;
import org.junit.Test;
import static org.junit.Assert.*;
import org.mockito.Mockito;
import static org.mockito.Mockito.when;
public class IMCServletTest {
HttpServletRequest req;
HttpServletResponse res;
StringWriter sw;
public void init() {
try {
req = Mockito.mock(HttpServletRequest.class);
res = Mockito.mock(HttpServletResponse.class);
sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
catch (Exception e) {}
public void testDoGet() {
try {
new IMCServlet().doGet(req,res);
assertEquals("IMC: 25.3\n", sw.toString());
catch (Exception e) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment