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.Assert;
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";

  @Test
  public void requestInterests() throws IOException {
    // Verify that returned interests is the provided interest constant
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    Mockito.when(response.getWriter()).thenReturn(writer);
    Mockito.when(request.getParameter(REQUEST_CATEGORY)).thenReturn(INTERESTS);
    new PrefilledInformationServlet().doGet(request, response);
    writer.flush();
    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
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    Mockito.when(response.getWriter()).thenReturn(writer);
    Mockito.when(request.getParameter(REQUEST_CATEGORY)).thenReturn(SKILLS);
    new PrefilledInformationServlet().doGet(request, response);
    writer.flush();
    Assert.assertEquals(
        CommonUtils.convertToJson(PrefilledInformationConstants.SKILLS).trim(),
        stringWriter.toString().trim());
  }
}

@@ -382,21 +382,75 @@
 .junit.A
-ssert
+fter;%0Aimport org.junit.Assert;%0Aimport org.junit.BeforeClass
 ;%0Aimport
@@ -809,143 +809,28 @@
 %0A%0A  
-@Test%0A  public void requestInterests() throws IOException %7B%0A    // Verify that returned interests is the provided interest constant%0A   
+private static final
  Htt
@@ -886,36 +886,62 @@
 tRequest.class);
-%0A
    
+    %0A  private static final
  HttpServletResp
@@ -991,33 +991,52 @@
 ponse.class);%0A  
- 
+private static final
  StringWriter st
@@ -1062,33 +1062,52 @@
 ringWriter();%0A  
- 
+private static final
  PrintWriter wri
@@ -1147,66 +1147,384 @@
 r);%0A
-    Mockito.when(response.getWriter()).thenReturn(writer);
+%0A  @BeforeClass%0A  public static void setUp() throws Exception %7B%0A    Mockito.when(response.getWriter()).thenReturn(writer);%0A  %7D%0A%0A  @After%0A  public void flushWriter() %7B%0A    Mockito.reset(request);%0A    stringWriter.getBuffer().setLength(0);%0A  %7D%0A%0A  @Test%0A  public void requestInterests() throws IOException %7B%0A    // Verify that returned interests is the provided interest constant
 %0A   
@@ -1664,36 +1664,16 @@
 ponse);%0A
-    writer.flush();%0A
     Asse
@@ -1948,324 +1948,8 @@
 ant%0A
-    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);%0A    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);%0A    StringWriter stringWriter = new StringWriter();%0A    PrintWriter writer = new PrintWriter(stringWriter);%0A    Mockito.when(response.getWriter()).thenReturn(writer);%0A
     
@@ -2089,28 +2089,8 @@
 e);%0A
-    writer.flush();%0A
     

Move common code up to BeforeClass