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 String INVALID_PARAMETER = "invalid";

  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());
  }

  @Test
  public void requestInvalid() throws IOException {
    // Verify that an error code is returned if invalid request parameter is passed
    Mockito.when(request.getParameter(REQUEST_CATEGORY)).thenReturn(INVALID_PARAMETER);
    new PrefilledInformationServlet().doGet(request, response);
    Mockito.verify(response).sendError(HttpServletResponse.SC_NOT_FOUND);
  }
}

@@ -1478,16 +1478,28 @@
 nterests
+ListConstant
 () throw
@@ -1518,80 +1518,8 @@
 n %7B%0A
-    // Verify that returned interests is the provided interest constant%0A
     
@@ -1590,24 +1590,25 @@
 INTERESTS);%0A
+%0A
     new Pref
@@ -1651,32 +1651,33 @@
 est, response);%0A
+%0A
     Assert.asser
@@ -1849,16 +1849,28 @@
 stSkills
+ListConstant
 () throw
@@ -1889,75 +1889,8 @@
 n %7B%0A
-    // Verify that returned skills is the provided skills constant%0A
     
@@ -1962,16 +1962,17 @@
 KILLS);%0A
+%0A
     new 
@@ -2023,24 +2023,25 @@
  response);%0A
+%0A
     Assert.a
@@ -2183,70 +2183,8 @@
  %7D%0A%0A
-  @Test%0A  public void requestInvalid() throws IOException %7B%0A  
   //
@@ -2261,16 +2261,97 @@
  passed%0A
+  @Test%0A  public void requestInvalidListConstantWithError() throws IOException %7B%0A
     Mock
@@ -2430,16 +2430,17 @@
 METER);%0A
+%0A
     new 
@@ -2495,16 +2495,17 @@
 ponse);%0A
+%0A
     Mock

Fix nit comments