package com.google.step.snippet.external;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import com.google.step.snippet.data.Card;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public final class StackOverflowClientTest {
  private final Client client = new StackOverflowClient("CSE_ID");

  @Test
  public void questionIdTest() {
    Card card1 = client.search("https://stackoverflow.com/questions");
    Card card2 = client.search("https://stackoverflow.com/questions/dhwiurgewi");
    Card card3 = client.search("https://stackoverflow.com/tagged/java");
    Card card4 = client.search("https://stackoverflow.com/answer/2841892");

    assertNull(card1);
    assertNull(card2);
    assertNull(card3);
    assertNull(card4);
  }

  @Test
  public void validCardTest1() {
    Card actual =
        client.search(
            "https://stackoverflow.com/questions/22250067/how-to-get-address-of-a-pointer-in-c-c");

    assertEquals("How to get address of a pointer in c/c++?", actual.getTitle());
    assertNull(actual.getCode());
    assertEquals(
        "https://stackoverflow.com/questions/22250067/how-to-get-address-of-a-pointer-in-c-c",
        actual.getLink());
    assertEquals(
        "<p>To get the address of p do:</p>\n\n<pre><code>int **pp = &amp;p;\n</code></pre>\n\n<p>and"
            + " you can go on:</p>\n\n<pre><code>int ***ppp = &amp;pp;\nint ****pppp = &amp;ppp;\n...\n</code>"
            + "</pre>\n\n<p>or, only in C++11, you can do:</p>\n\n<pre><code>auto pp = std::addressof(p);\n</co"
            + "de></pre>\n\n<p>To print the addre",
        actual.getDescription().substring(0, 300));
  }

  @Test
  public void validCardTest2() {
    Card actual =
        client.search("https://stackoverflow.com/questions/11928566/img-vs-image-tag-in-html");

    assertEquals("&lt;img&gt; vs &lt;image&gt; tag in HTML", actual.getTitle());
    assertNull(actual.getCode());
    assertEquals(
        "https://stackoverflow.com/questions/11928566/img-vs-image-tag-in-html", actual.getLink());
    assertEquals(
        "<p>Yes and no. As you point out <code>&lt;image&gt;</code> has been a synonym for "
            + "<code>&lt;img&gt;</code> for a long time. I believe it was an early Netscape browser "
            + "that first did this, possibly to compensate for user error, or possibly because there "
            + "was dispute at the time whether the element sho",
        actual.getDescription().substring(0, 300));
  }

  @Test
  public void noAnswerTest() {
    Card actual =
            client.search("https://stackoverflow.com/questions/44686609/implementing-a-neural-network-in-haskell");
    assertNull(actual);
  }

  @Test
  public void fakeLinkTest() {
    Card actual = client.search("https://softwareengineering.stackexchange.com/questions/100/what-website-are-yo");
    assertNull(actual);
  }
}

@@ -1286,33 +1286,24 @@
 ssertEquals(
-%0A        
 %22%3Cp%3ETo get t
@@ -1321,32 +1321,57 @@
 of p do:%3C/p%3E%5Cn%5Cn
+%22%0A                    + %22
 %3Cpre%3E%3Ccode%3Eint *
@@ -1385,16 +1385,41 @@
 amp;p;%5Cn
+%22%0A                    + %22
 %3C/code%3E%3C
@@ -1431,16 +1431,12 @@
 %5Cn%5Cn
-%3Cp%3Eand
 %22%0A
+  
     
@@ -1443,19 +1443,31 @@
         
-+ %22
+      + %22%3Cp%3Eand
  you can
@@ -1473,32 +1473,57 @@
 n go on:%3C/p%3E%5Cn%5Cn
+%22%0A                    + %22
 %3Cpre%3E%3Ccode%3Eint *
@@ -1540,16 +1540,41 @@
 mp;pp;%5Cn
+%22%0A                    + %22
 int ****
@@ -1595,22 +1595,47 @@
 p;%5Cn
-...%5Cn%3C/code%3E%22%0A
+%22%0A                    + %22...%5Cn%22%0A       
     
@@ -1646,21 +1646,29 @@
     
+ 
 + %22%3C/
+code%3E%3C/
 pre%3E%5Cn%5Cn
 %3Cp%3Eo
@@ -1663,16 +1663,41 @@
 pre%3E%5Cn%5Cn
+%22%0A                    + %22
 %3Cp%3Eor, o
@@ -1729,16 +1729,41 @@
 %3C/p%3E%5Cn%5Cn
+%22%0A                    + %22
 %3Cpre%3E%3Cco
@@ -1799,14 +1799,14 @@
 );%5Cn
-%3C/co%22%0A
+%22%0A    
     
@@ -1813,19 +1813,27 @@
         
-+ %22
+    + %22%3C/co
 de%3E%3C/pre
@@ -1837,16 +1837,41 @@
 pre%3E%5Cn%5Cn
+%22%0A                    + %22
 %3Cp%3ETo pr
@@ -2831,28 +2831,24 @@
 l =%0A        
-    
 client.searc
@@ -2841,32 +2841,45 @@
   client.search(
+%0A            
 %22https://stackov
@@ -3037,16 +3037,24 @@
 actual =
+%0A       
  client.
@@ -3052,32 +3052,45 @@
   client.search(
+%0A            
 %22https://softwar

reformat java