package com.google.sps;

import com.google.sps.servlets.PrefilledInformationServlet;
import com.google.sps.utilities.CommonUtils;
import com.google.sps.utilities.PrefilledInformationConstants;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.After;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mockito;

/** */
@RunWith(JUnit4.class)
public final class PrefilledInformationTest {
  private static final String REQUEST_CATEGORY = "category";
  private static final String INTERESTS = "interests";
  private static final String SKILLS = "skills";

  private static final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);       
  private static final HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  private static final StringWriter stringWriter = new StringWriter();
  private static final PrintWriter writer = new PrintWriter(stringWriter);

  @BeforeClass
  public static void setUp() throws Exception {
    Mockito.when(response.getWriter()).thenReturn(writer);
  }

  @After
  public void flushWriter() {
    Mockito.reset(request);
    stringWriter.getBuffer().setLength(0);
  }

  @Test
  public void requestInterests() throws IOException {
    // Verify that returned interests is the provided interest constant
    Mockito.when(request.getParameter(REQUEST_CATEGORY)).thenReturn(INTERESTS);
    new PrefilledInformationServlet().doGet(request, response);
    Assert.assertEquals(
        CommonUtils.convertToJson(PrefilledInformationConstants.INTERESTS).trim(),
        stringWriter.toString().trim());
  }

  @Test
  public void requestSkills() throws IOException {
    // Verify that returned skills is the provided skills constant
    Mockito.when(request.getParameter(REQUEST_CATEGORY)).thenReturn(SKILLS);
    new PrefilledInformationServlet().doGet(request, response);
    Assert.assertEquals(
        CommonUtils.convertToJson(PrefilledInformationConstants.SKILLS).trim(),
        stringWriter.toString().trim());
  }
}

@@ -801,16 +801,77 @@
 skills%22;
+%0A  private static final String INVALID_PARAMETER = %22invalid%22;
 %0A%0A  priv
@@ -2295,11 +2295,386 @@
 ());%0A  %7D
+%0A%0A  @Test%0A  public void requestInvalid() throws IOException %7B%0A    // Verify that an error code is returned if invalid request parameter is passed%0A    Mockito.when(request.getParameter(REQUEST_CATEGORY)).thenReturn(INVALID_PARAMETER);%0A    new PrefilledInformationServlet().doGet(request, response);%0A    Mockito.verify(response).sendError(HttpServletResponse.SC_NOT_FOUND);%0A  %7D
 %0A%7D%0A

Add test for invalid prefilled constant input