package com.google.sps.servlets;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.After;
import static org.mockito.Mockito.*;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.appengine.tools.development.testing.LocalUserServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;

import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.Test;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.google.sps.tool.GoogleTranslationAPI;
import com.google.sps.tool.Tool;
import com.google.gson.Gson;
import java.util.Map;
import java.util.HashMap;

@RunWith(JUnit4.class)
public class TranslationServletTest {
  private final LocalServiceTestHelper helper = 
    new LocalServiceTestHelper(
      new LocalUserServiceTestConfig())
      .setEnvIsAdmin(true).setEnvIsLoggedIn(true)
      .setEnvEmail("test@gmail.com").setEnvAuthDomain("gmail.com");
  
  private Map<String, String> expectedJsonInfo = new HashMap<>();
  private HttpServletRequest mockRequest;
  private HttpServletResponse mockResponse;
  private StringWriter responseWriter;
  private TranslationServlet servlet;

  @Before
  public void setUp() throws Exception {
    helper.setUp();
    servlet = new TranslationServlet();
    mockRequest = mock(HttpServletRequest.class);
    mockResponse = mock(HttpServletResponse.class);
    
    // Set up a fake HTTP response 
    responseWriter = new StringWriter();
    when(mockResponse.getWriter()).thenReturn(new PrintWriter(responseWriter));
  }

  @After
  public void tearDown() throws Exception {
    helper.setEnvIsLoggedIn(true);
    helper.tearDown();
  }

  @Test
  public void TranslateHelloToSpanish() throws Exception {

    when(mockRequest.getParameter("rawText")).thenReturn("hello");
    when(mockRequest.getParameter("toLang")).thenReturn("es");
    when(mockRequest.getParameter("fromLang")).thenReturn("en");
    expectedJsonInfo.put("translation", "Hola");

    servlet.doGet(mockRequest, mockResponse);
    String response = responseWriter.toString();
    String expectedResponse = new Gson().toJson(expectedJsonInfo);
    assertTrue(Tool.compareJson(response, expectedResponse));
  }
}
@@ -833,14 +833,9 @@
 slat
-ionAPI
+e
 ;%0Aim
@@ -1994,17 +1994,17 @@
 ic void 
-T
+t
 ranslate
@@ -2039,17 +2039,16 @@
 ption %7B%0A
-%0A
     when

Fix styling issue