package com.google.sps.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.api.mockito.PowerMockito;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;
import com.github.mustachejava.DefaultMustacheFactory;

/** */
@RunWith(PowerMockRunner.class) 
@PrepareForTest({ ResultsServlet.class, DefaultMustacheFactory.class})
public final class ResultsServletTest { 

  private final static ResultsServlet RESULTS_SERVLET = new ResultsServlet();

  @Before
  public void setUpMustacheFactoryMock() throws Exception {
    DefaultMustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache = mf.compile("results.test");

    DefaultMustacheFactory mfMocked = PowerMockito.mock(DefaultMustacheFactory.class);
    PowerMockito.when(mfMocked.compile("results.html")).thenReturn(mustache);

    PowerMockito.whenNew(DefaultMustacheFactory.class).withAnyArguments().thenReturn(mfMocked);
  }

  private String mockServlet(String keyValue) throws IOException {
    HttpServletRequest mockedRequest = PowerMockito.mock(HttpServletRequest.class);
    HttpServletResponse mockedResponse = PowerMockito.mock(HttpServletResponse.class);

    PowerMockito.when(mockedRequest.getParameter("k")).thenReturn(keyValue);

    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    PowerMockito.when(mockedResponse.getWriter()).thenReturn(writer);

    RESULTS_SERVLET.doGet(mockedRequest, mockedResponse);

    Mockito.verify(mockedRequest, Mockito.atLeast(1)).getParameter("k");
    writer.flush();
    return stringWriter.toString();
  }

  @Test
  public void testServlet() throws IOException {
    String expected = "value";
    String actual = mockServlet(expected);
    Assert.assertEquals(expected, actual);
  }

  @Test
  public void testNonAsciiCharacters() throws IOException {
    String expected = "मान";
    String actual = mockServlet(expected);
    Assert.assertEquals(expected, actual);
  }
}

@@ -2185,37 +2185,51 @@
    Assert.assert
-Equal
+True(actual.contain
 s(expected, actu
@@ -2218,32 +2218,25 @@
 ins(expected
-, actual
+)
 );%0A  %7D%0A%0A  @T
@@ -2392,13 +2392,27 @@
 sert
-Equal
+True(actual.contain
 s(ex
@@ -2421,16 +2421,9 @@
 cted
-, actual
+)
 );%0A 

Fix assertion statement