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 GeeksForGeeksClientTest {

  private final GeeksForGeeksClient client = new GeeksForGeeksClient("CSE_ID");

  @Test
  public void htmlCodeCard() {
    Card actual =
        client.search(
            "https://www.geeksforgeeks.org/how-to-change-the-height-of-br-tag/", "html br");
    Card expected =
        new Card(
            "How to change the height of br tag?",
            "Customized break example     \n"
                + "&lt;h3&gt;This page shows different break height between lines&lt;/h3&gt; \n"
                + "&lt;p&gt; Hi User &lt;span&gt;&lt;/span&gt; Welcome to &lt;span&gt;&lt;/span&gt;"
                + " Geeks for geeks. &lt;span&gt;&lt;/span&gt; Hope you have enjoyed your stay."
                + " &lt;/p&gt;",
            "https://www.geeksforgeeks.org/how-to-change-the-height-of-br-tag/",
            "You can&rsquo;t change the height of \n"
                + "&lt;br&gt; tag as its not an HTML element, it is just an instruction which"
                + " enforces a line break. br does not take up any space in the page.");
    assertEquals(expected, actual);
  }

  @Test
  public void dataStructuresCard() {
    Card actual =
        client.search(
            "https://www.geeksforgeeks.org/array-rotation/", "Program for array rotation");
    assertEquals("Program for array rotation", actual.title);
    assertEquals(
        "// C++ program to rotate an array by // d elements #include  using namespace std;"
            + " /*Function to left Rotate arr[] of size n by 1*/ void leftRotatebyOne(int arr[],"
            + " int n) { int temp = arr[0], i; for (i = 0; i &lt; n - 1; i++) arr[i] = arr[i + 1];"
            + " arr[i] = temp; } /*Function to left rotate arr[] of size n by d*/ void"
            + " leftRotate(int arr[], int d, int n) { for (int i = 0; i &lt; d; i++)"
            + " leftRotatebyOne(arr, n); } /* utility function to print an array */ void"
            + " printArray(int arr[], int n) { for (int i = 0; i &lt; n; i++) cout &lt;&lt; arr[i]"
            + " &lt;&lt; \" \"; } /* Driver program to test above functions */ int main() { int"
            + " arr[] = { 1, 2, 3, 4, 5, 6, 7 }; int n = sizeof(arr) / sizeof(arr[0]); // Function"
            + " calling leftRotate(arr, 2, n); printArray(arr, n); return 0; }",
        actual.code);
    assertEquals(
        "Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements.",
        actual.description);
    Card expected =
        new Card(
            "Program for array rotation",
            "// C++ program to rotate an array by // d elements #include  using namespace std;"
                + " /*Function to left Rotate arr[] of size n by 1*/ void leftRotatebyOne(int"
                + " arr[], int n) { int temp = arr[0], i; for (i = 0; i &lt; n - 1; i++) arr[i] ="
                + " arr[i + 1]; arr[i] = temp; } /*Function to left rotate arr[] of size n by d*/"
                + " void leftRotate(int arr[], int d, int n) { for (int i = 0; i &lt; d; i++)"
                + " leftRotatebyOne(arr, n); } /* utility function to print an array */ void"
                + " printArray(int arr[], int n) { for (int i = 0; i &lt; n; i++) cout &lt;&lt;"
                + " arr[i] &lt;&lt; \" \"; } /* Driver program to test above functions */ int"
                + " main() { int arr[] = { 1, 2, 3, 4, 5, 6, 7 }; int n = sizeof(arr) /"
                + " sizeof(arr[0]); // Function calling leftRotate(arr, 2, n); printArray(arr, n);"
                + " return 0; }",
            "https://www.geeksforgeeks.org/array-rotation/",
            "Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements.");
    assertEquals(expected, actual);
  }

  @Test
  public void partiallyFilledCard() {
    Card actual =
        client.search("https://www.geeksforgeeks.org/category/geek-on-the-top/", "geek on top");
    assertNull(actual);
  }

  @Test
  public void nonexistentLink() {
    Card actual =
        client.search(
            "https://www.geeksforgeeks.org/analysis-of-algorithms-set-3asymptotic-notations/dijkstra",
            null);
    assertNull(actual);
  }

  @Test
  public void blankPageLink() {
    Card actual = client.search("https://www.geeksforgeeks.org/", "geeksforgeeks");
    assertNull(actual);
  }
}

@@ -1585,1180 +1585,8 @@
 %22);%0A
-    assertEquals(%22Program for array rotation%22, actual.title);%0A    assertEquals(%0A        %22// C++ program to rotate an array by // d elements #include  using namespace std;%22%0A            + %22 /*Function to left Rotate arr%5B%5D of size n by 1*/ void leftRotatebyOne(int arr%5B%5D,%22%0A            + %22 int n) %7B int temp = arr%5B0%5D, i; for (i = 0; i &lt; n - 1; i++) arr%5Bi%5D = arr%5Bi + 1%5D;%22%0A            + %22 arr%5Bi%5D = temp; %7D /*Function to left rotate arr%5B%5D of size n by d*/ void%22%0A            + %22 leftRotate(int arr%5B%5D, int d, int n) %7B for (int i = 0; i &lt; d; i++)%22%0A            + %22 leftRotatebyOne(arr, n); %7D /* utility function to print an array */ void%22%0A            + %22 printArray(int arr%5B%5D, int n) %7B for (int i = 0; i &lt; n; i++) cout &lt;&lt; arr%5Bi%5D%22%0A            + %22 &lt;&lt; %5C%22 %5C%22; %7D /* Driver program to test above functions */ int main() %7B int%22%0A            + %22 arr%5B%5D = %7B 1, 2, 3, 4, 5, 6, 7 %7D; int n = sizeof(arr) / sizeof(arr%5B0%5D); // Function%22%0A            + %22 calling leftRotate(arr, 2, n); printArray(arr, n); return 0; %7D%22,%0A        actual.code);%0A    assertEquals(%0A        %22Write a function rotate(ar%5B%5D, d, n) that rotates arr%5B%5D of size n by d elements.%22,%0A        actual.description);%0A
     

remove seperate tests