package com.dkarv.jdcallgraph.callgraph;

import com.dkarv.jdcallgraph.callgraph.writer.DotFileWriter;
import com.dkarv.jdcallgraph.util.Target;
import com.dkarv.jdcallgraph.util.config.Config;
import com.dkarv.jdcallgraph.util.config.ConfigUtils;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

public class CallGraphTest {

  @Test
  public void testCreateWriter() {
    Config c = Mockito.mock(Config.class);
    ConfigUtils.inject(c);
    CallGraph graph = new CallGraph(1);

    Mockito.when(c.writeTo()).thenReturn(Target.DOT);
    graph.createWriter();
    Assert.assertThat(graph.writer, CoreMatchers.instanceOf(DotFileWriter.class));
  }
}

@@ -96,16 +96,120 @@
 Writer;%0A
+import com.dkarv.jdcallgraph.callgraph.writer.GraphWriter;%0Aimport com.dkarv.jdcallgraph.util.StackItem;%0A
 import c
@@ -242,16 +242,16 @@
 Target;%0A
-
 import c
@@ -456,16 +456,45 @@
 ckito;%0A%0A
+import java.io.IOException;%0A%0A
 public c
@@ -749,16 +749,16 @@
 iter();%0A
-
     Asse
@@ -835,11 +835,399 @@
 s));%0A  %7D
+%0A%0A  @Test%0A  public void testFinish() throws IOException %7B%0A    CallGraph graph = new CallGraph(1);%0A    GraphWriter writer = Mockito.mock(GraphWriter.class);%0A    StackItem item = Mockito.mock(StackItem.class);%0A    graph.writer = writer;%0A%0A%0A    graph.finish();%0A    Mockito.verifyNoMoreInteractions(writer);%0A    graph.calls.push(item);%0A    graph.finish();%0A    Mockito.verify(writer).end();%0A  %7D
 %0A%7D%0A

add test for finish