package com.karateca.jstoolbox.generatemethod;

import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.vfs.VirtualFile;

import java.util.List;

/**
 * @author Andres Dominguez.
 */
public class ClassFinderTest extends BaseTestCase {

  private ClassFinder classFinder;

  public void testGetClassNameClassFound() {
    // Given a file with a constructor.
    givenAFile("child.js");

    // When you get the class name.
    String className = classFinder.getClassName();

    // Then ensure the class name was found.
    assertEquals("Yo.child", className);
  }

  public void testGetClassNameClassNotFound() {
    // Given a file without constructor annotation.
    givenAFile("noConstructor.js");

    // When you get the class name.
    String className = classFinder.getClassName();

    // Then ensure the class name was not found.
    assertNull(className);
  }

  public void testGetParentClassName() {
    // Given a file with extends annotation.
    givenAFile("child.js");

    // When you get the parent class name.
    String parentClassName = classFinder.getParentClassName();

    // Then ensure the name was found.
    assertEquals("Yo.parent", parentClassName);
  }

  public void testGetParentClassNameNotFound() {
    // Given a class without a parent.
    givenAFile("grandpa.js");

    // When you get the parent class name.
    String parentClassName = classFinder.getParentClassName();

    // Then ensure it is null.
    assertNull(parentClassName);
  }

  public void testFindMethods() {
    // Given a file with functions.
    givenAFile("child.js");

    // When you get the functions.
    List<Function> methods = classFinder.getMethods();

    // Then ensure all the functions were found.
    assertEquals(4, methods.size());
  }

  private void givenAFile(String fileName) {
    prepareScenarioWithTestFile(fileName);
    classFinder = new ClassFinder(getDocument(virtualFile));
  }

  private Document getDocument(VirtualFile virtualFile) {
    return FileDocumentManager.getInstance().getDocument(virtualFile);
  }
}


@@ -1822,24 +1822,530 @@
 ds.size());%0A
+    assertEquals(%22plainMethod%22, methods.get(0).getName());%0A    assertEquals(%22%22, methods.get(0).getArguments());%0A%0A    assertEquals(%22withArguments%22, methods.get(1).getName());%0A    assertEquals(%22one, two%22, methods.get(1).getArguments());%0A%0A    assertEquals(%22withManyLines%22, methods.get(2).getName());%0A    assertEquals(%22one, two,%5Cn              three%22, methods.get(2).getArguments());%0A%0A    assertEquals(%22withJsDoc%22, methods.get(3).getName());%0A    assertEquals(%22one, two, three%22, methods.get(3).getArguments());%0A
   %7D%0A%0A  priva

add assertions