1 package com.mockobjects.examples.password; 2 3 import java.io.IOException ; 4 import javax.servlet.ServletConfig ; 5 import javax.servlet.ServletException ; 6 import com.mockobjects.servlet.MockHttpServletRequest; 7 import com.mockobjects.servlet.MockHttpServletResponse; 8 import com.mockobjects.util.TestCaseMo; 9 10 public class TestForgotPasswordServlet extends TestCaseMo { 11 public static final String SENT_URI = "sent_uri"; 12 public static final String EMAIL_FAILED_URI = "bad_email_uri"; 13 public static final String EMAIL_NOT_FOUND_URI = "no_email_uri"; 14 public static final String EMAIL = "email@an.address"; 15 16 public TestForgotPasswordServlet(String name) { 17 super(name); 18 } 19 20 private MockHttpServletRequest mockRequest = new MockHttpServletRequest(); 21 private MockHttpServletResponse mockResponse = new MockHttpServletResponse(); 22 private MockPasswordReminder mockReminder = new MockPasswordReminder(); 23 private ForgotPasswordServlet passwordServlet; 24 25 public void setUp() throws ServletException , IOException { 26 passwordServlet = new ForgotPasswordServlet(mockReminder); 27 28 mockRequest.setupAddParameter(ForgotPasswordServlet.EMAIL_PARAM, EMAIL); 29 } 30 31 public void testReminderEmailSent() throws ServletException , IOException { 32 mockReminder.setExpectedEmailAddress(EMAIL); 33 mockResponse.setExpectedRedirect( 34 SENT_URI + "?" + ForgotPasswordServlet.EMAIL_PARAM + "=" + EMAIL); 35 36 passwordServlet.doGet(mockRequest, mockResponse); 37 38 mockResponse.verify(); 39 mockReminder.verify(); 40 } 41 42 69 } 70 71 | Popular Tags |