@@ -0,0 +1,3322 @@
+package com.google.sps;%0A%0Aimport com.google.appengine.tools.development.testing.LocalServiceTestHelper;%0Aimport com.google.appengine.tools.development.testing.LocalUserServiceTestConfig;%0Aimport com.google.sps.data.VolunteeringOpportunity;%0Aimport com.google.sps.servlets.VolunteeringFormHandlerServlet;%0Aimport com.google.sps.utilities.SpannerClient;%0Aimport com.google.sps.utilities.SpannerTasks;%0Aimport com.google.sps.utilities.SpannerTestTasks;%0Aimport com.google.sps.utilities.TestUtils;%0Aimport java.io.IOException;%0Aimport javax.servlet.ServletContextEvent;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.JUnit4;%0Aimport org.mockito.Mockito;%0Aimport org.springframework.mock.web.MockServletContext;%0A%0A%0A/** Test that tests the opportunity signup form functionality. */%0A@RunWith(JUnit4.class)%0Apublic final class VolunteeringFormHandlerTest %7B%0A  private static final String PARAMETER_OPPORTUNITY_ID = %22opportunity-id%22;%0A  private static final String PARAMETER_EVENT_ID = %22event-id%22;%0A  private static final String PARAMETER_NAME = %22name%22;%0A  private static final String NAME = %22Performer%22;%0A  private VolunteeringFormHandlerServlet eventVolunteeringFormHandlerServlet;%0A  private HttpServletRequest request;%0A  private HttpServletResponse response;%0A%0A  @Before%0A  public void setUp() throws Exception %7B%0A    // Mock a request to trigger the SpannerClient setup to run.%0A    MockServletContext mockServletContext = new MockServletContext();%0A    new SpannerClient().contextInitialized(new ServletContextEvent(mockServletContext));%0A    SpannerTestTasks.setup();%0A%0A    eventVolunteeringFormHandlerServlet = new VolunteeringFormHandlerServlet();%0A%0A    request = Mockito.mock(HttpServletRequest.class);%0A    response = Mockito.mock(HttpServletResponse.class);%0A  %7D%0A%0A  @After%0A  public void tearDown() %7B%0A    SpannerTestTasks.cleanup();%0A  %7D%0A%0A  @Test%0A  public void testAddOpportunity() throws IOException %7B%0A    String eventId = TestUtils.newRandomId();%0A    Mockito.when(request.getParameter(PARAMETER_NAME)).thenReturn(NAME);%0A    Mockito.when(request.getParameter(PARAMETER_EVENT_ID)).thenReturn(eventId);%0A%0A    eventVolunteeringFormHandlerServlet.doPost(request, response);%0A%0A    Mockito.verify(response).sendRedirect(String.format(%22/event-details.html?eventId=%25s%22, eventId));%0A  %7D%0A%0A  @Test%0A  public void testAddOpportunitySignup_NameNotSpecified_sendErrorResponse() throws IOException %7B%0A    Mockito.when(request.getParameter(PARAMETER_NAME)).thenReturn(null);%0A    Mockito.when(request.getParameter(PARAMETER_EVENT_ID)).thenReturn(TestUtils.newRandomId());%0A%0A    eventVolunteeringFormHandlerServlet.doPost(request, response);%0A%0A    Mockito.verify(response)%0A        .sendError(HttpServletResponse.SC_BAD_REQUEST, %22Name not specified.%22);%0A  %7D%0A%0A  @Test%0A  public void testAddOpportunitySignup_EventNotSpecified_sendErrorResponse() throws IOException %7B%0A    Mockito.when(request.getParameter(PARAMETER_NAME)).thenReturn(NAME);%0A    Mockito.when(request.getParameter(PARAMETER_EVENT_ID)).thenReturn(null);%0A%0A    eventVolunteeringFormHandlerServlet.doPost(request, response);%0A%0A    Mockito.verify(response)%0A        .sendError(HttpServletResponse.SC_BAD_REQUEST, %22Event ID not specified.%22);%0A  %7D%0A%7D

Add test for opportunity form handler.