// Path: capstone/src/main/java/com/google/sps/data/AssociationData.java
// public final class AssociationData {
// 
//   private ArrayList<String> positive;
//   private ArrayList<String> negative;
// 
//   public AssociationData(ArrayList<String> positive, ArrayList<String> negative) {
//     this.positive = positive;
//     this.negative = negative;
//   }
// 
//   public ArrayList<String> getPositive() {
//     return positive;
//   }
// 
//   public ArrayList<String> getNegative() {
//     return negative;
//   }
// }
// 
// Path: capstone/src/main/java/com/google/sps/servlets/AssociationServlet.java
// @WebServlet("/associations")
// public class AssociationServlet extends HttpServlet {
// 
//   private static final String OUTPUT_TYPE = "applications/json;";
//   public static final int MAX_ASSOCIATIONS = 3;
// 
//   private DatastoreService datastore;
// 
//   public void init() throws ServletException {
//     datastore = DatastoreServiceFactory.getDatastoreService();
//   }
// 
//   @Override
//   public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
//     response.setContentType(OUTPUT_TYPE);
// 
//     String scope = request.getParameter("scope");
//     if (scope == null) {
//       scope = "SF";
//     }
// 
//     FetchOptions fetchOptions = FetchOptions.Builder.withDefaults();
// 
//     Query posQuery =
//         new Query(AssociationResult.ENTITY_KIND).addSort("score", SortDirection.DESCENDING);
//     ArrayList<String> positive =
//         extractContent(datastore.prepare(posQuery).asQueryResultList(fetchOptions), scope);
// 
//     Query negQuery =
//         new Query(AssociationResult.ENTITY_KIND).addSort("score", SortDirection.ASCENDING);
//     ArrayList<String> negative =
//         extractContent(datastore.prepare(negQuery).asQueryResultList(fetchOptions), scope);
// 
//     AssociationData output = new AssociationData(positive, negative);
//     Gson gson = new Gson();
//     response.getWriter().println(gson.toJson(output));
//   }
// 
//   /**
//    * Adds the names of the associations to the arraylist passed in
//    *
//    * @param query the entities to get the names from
//    * @return the arraylist to add the names of the entities to
//    */
//   private ArrayList<String> extractContent(QueryResultList<Entity> query, String scope) {
//     ArrayList<String> output = new ArrayList<String>();
//     for (Entity entity : query) {
//       if (!scope.equals((String) entity.getProperty("scope"))) {
//         continue;
//       } else if (output.size() >= MAX_ASSOCIATIONS) {
//         break;
//       }
//       output.add((String) entity.getProperty("name"));
//     }
//     return output;
//   }
// }


import static org.junit.Assert.assertEquals;
import com.google.gson.Gson;
import com.google.sps.data.AssociationData;
import com.google.sps.servlets.AssociationServlet;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
import org.mockito.Mockito;
package com.google.sps.servlet;



public class AssociationServletTest extends Mockito {

  @Test
  public void testServlet() throws Exception {
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);

// Path: capstone/src/main/java/com/google/sps/data/AssociationData.java
// public final class AssociationData {
// 
//   private ArrayList<String> positive;
//   private ArrayList<String> negative;
// 
//   public AssociationData(ArrayList<String> positive, ArrayList<String> negative) {
//     this.positive = positive;
//     this.negative = negative;
//   }
// 
//   public ArrayList<String> getPositive() {
//     return positive;
//   }
// 
//   public ArrayList<String> getNegative() {
//     return negative;
//   }
// }
// 
// Path: capstone/src/main/java/com/google/sps/servlets/AssociationServlet.java
// @WebServlet("/associations")
// public class AssociationServlet extends HttpServlet {
// 
//   private static final String OUTPUT_TYPE = "applications/json;";
//   public static final int MAX_ASSOCIATIONS = 3;
// 
//   private DatastoreService datastore;
// 
//   public void init() throws ServletException {
//     datastore = DatastoreServiceFactory.getDatastoreService();
//   }
// 
//   @Override
//   public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
//     response.setContentType(OUTPUT_TYPE);
// 
//     String scope = request.getParameter("scope");
//     if (scope == null) {
//       scope = "SF";
//     }
// 
//     FetchOptions fetchOptions = FetchOptions.Builder.withDefaults();
// 
//     Query posQuery =
//         new Query(AssociationResult.ENTITY_KIND).addSort("score", SortDirection.DESCENDING);
//     ArrayList<String> positive =
//         extractContent(datastore.prepare(posQuery).asQueryResultList(fetchOptions), scope);
// 
//     Query negQuery =
//         new Query(AssociationResult.ENTITY_KIND).addSort("score", SortDirection.ASCENDING);
//     ArrayList<String> negative =
//         extractContent(datastore.prepare(negQuery).asQueryResultList(fetchOptions), scope);
// 
//     AssociationData output = new AssociationData(positive, negative);
//     Gson gson = new Gson();
//     response.getWriter().println(gson.toJson(output));
//   }
// 
//   /**
//    * Adds the names of the associations to the arraylist passed in
//    *
//    * @param query the entities to get the names from
//    * @return the arraylist to add the names of the entities to
//    */
//   private ArrayList<String> extractContent(QueryResultList<Entity> query, String scope) {
//     ArrayList<String> output = new ArrayList<String>();
//     for (Entity entity : query) {
//       if (!scope.equals((String) entity.getProperty("scope"))) {
//         continue;
//       } else if (output.size() >= MAX_ASSOCIATIONS) {
//         break;
//       }
//       output.add((String) entity.getProperty("name"));
//     }
//     return output;
//   }
// }


// Path: capstone/src/main/webapp/test/java/com/google/sps/servlets/AssociationServletTest.java
import static org.junit.Assert.assertEquals;
import com.google.gson.Gson;
import com.google.sps.data.AssociationData;
import com.google.sps.servlets.AssociationServlet;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
import org.mockito.Mockito;

package com.google.sps.servlet;



public class AssociationServletTest extends Mockito {

  @Test
  public void testServlet() throws Exception {
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);

    StringWriter stringWriter = new StringWriter();