package com.karateca.jstoolbox.generatemethod;

import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.impl.DocumentImpl;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Andres Dominguez.
 */
public class HierarchyFinderTest extends LightCodeInsightFixtureTestCase {

  @Override
  protected String getTestDataPath() {
    return new File("testData").getPath();
  }

  public void testFindParents() throws Exception {
    List<VirtualFile> virtualFiles = prepareScenarioWithTestFiles("child.js", "parent.js", "grandpa.js");

    HierarchyFinder hierarchyFinder = new HierarchyFinder(getProject(), getDocument(virtualFiles.get(0))) {
      @Override
      protected Document getDocument(VirtualFile virtualFile) {
        try {
          String s = new String(virtualFile.contentsToByteArray());
          return new DocumentImpl(s);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
    };

    HierarchyResults parents = hierarchyFinder.findParents();

    List<Document> hierarchy = parents.getHierarchy();
    assertEquals(2, hierarchy.size());
  }

  private List<VirtualFile> prepareScenarioWithTestFiles(String... fileNames) throws IOException {
    List<VirtualFile> virtualFiles = new ArrayList<VirtualFile>();

    for (String fileName : fileNames) {
      VirtualFile virtualFile = myFixture.copyFileToProject(fileName);
      virtualFiles.add(virtualFile);
    }

    return virtualFiles;
  }

  private Document getDocument(VirtualFile virtualFile) throws IOException {
    String s = new String(virtualFile.contentsToByteArray());
    return new DocumentImpl(s);
  }
}

@@ -1163,21 +1163,21 @@
 Results 
-paren
+resul
 ts = hie
@@ -1236,21 +1236,21 @@
 archy = 
-paren
+resul
 ts.getHi
@@ -1299,16 +1299,130 @@
 ize());%0A
+    assertEquals(%22Yo.child%22, results.getCurrentClass());%0A    assertEquals(%22Yo.parent%22, results.getParentClass());%0A
   %7D%0A%0A  p

Add more assertions