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 com.google.step.snippet.external.StackOverflowClient;
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 validCardTest() {
    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));
  }
}

@@ -171,69 +171,8 @@
 rd;%0A
-import com.google.step.snippet.external.StackOverflowClient;%0A
 impo
@@ -190,16 +190,16 @@
 t.Test;%0A
+
 import o
@@ -865,24 +865,25 @@
 alidCardTest
+1
 () %7B%0A    Car
@@ -1671,16 +1671,16 @@
 addre%22,%0A
-
         
@@ -1726,11 +1726,1271 @@
 0));%0A  %7D
+%0A%0A  @Test%0A  public void validCardTest2() %7B%0A    Card actual =%0A        client.search(%22https://stackoverflow.com/questions/11928566/img-vs-image-tag-in-html%22);%0A%0A    assertEquals(%22&lt;img&gt; vs &lt;image&gt; tag in HTML%22, actual.getTitle());%0A    assertNull(actual.getCode());%0A    assertEquals(%0A        %22https://stackoverflow.com/questions/11928566/img-vs-image-tag-in-html%22, actual.getLink());%0A    assertEquals(%0A        %22%3Cp%3EYes and no. As you point out %3Ccode%3E&lt;image&gt;%3C/code%3E has been a synonym for %22%0A            + %22%3Ccode%3E&lt;img&gt;%3C/code%3E for a long time. I believe it was an early Netscape browser %22%0A            + %22that first did this, possibly to compensate for user error, or possibly because there %22%0A            + %22was dispute at the time whether the element sho%22,%0A        actual.getDescription().substring(0, 300));%0A  %7D%0A%0A  @Test%0A  public void  validCardTest3() %7B%0A%0A  %7D%0A  @Test%0A  public void noAnswerTest() %7B%0A    Card actual =%0A            client.search(%22https://stackoverflow.com/questions/44686609/implementing-a-neural-network-in-haskell%22);%0A    assertNull(actual);%0A  %7D%0A%0A  @Test%0A  public void fakeLinkTest() %7B%0A    Card actual = client.search(%22https://softwareengineering.stackexchange.com/questions/100/what-website-are-yo%22);%0A    assertNull(actual);%0A  %7D
 %0A%7D%0A

save change