package com.episode6.hackit.chop;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(ChopTestTestRunner.class)
public class DefaultTaggerTest {

  @Mock Chop.Tree mTree;

  @Before
  public void setUp() {
    when(mTree.supportsLevel(any(Chop.Level.class)))
        .thenReturn(true);

    Chop.plantTree(mTree);
  }

  @Test
  public void testOuterClass() {
    String expectedTag = DefaultTaggerTest.class.getSimpleName();

    Chop.d("Test Message");

    verifyExpectedTag(expectedTag);
  }

  @Test
  public void testAnonymousClass() {
    String expectedTag = DefaultTaggerTest.class.getSimpleName();

    new Runnable() {

      @Override
      public void run() {
        Chop.d("Test message");
      }
    }.run();

    verifyExpectedTag(expectedTag);
  }

  @Test
  public void testInnerClass() {
    String expectedTag = DefaultTaggerTest.class.getSimpleName() + "$" +
        InnerTestClass.class.getSimpleName();

    new InnerTestClass().printLog();

    verifyExpectedTag(expectedTag);
  }

  @After
  public void cleanUp() {
    ChopInternals.TREE_FARM.digUpTree(mTree);
  }

  private void verifyExpectedTag(String expectedTag) {
    verify(mTree).chopLog(
        any(Chop.Level.class),
        eq(expectedTag),
        anyString());
  }

  private class InnerTestClass {
    public void printLog() {
      Chop.d("Test Message");
    }
  }
}

@@ -601,32 +601,118 @@
 ee(mTree);%0A  %7D%0A%0A
+  @After%0A  public void cleanUp() %7B%0A    ChopInternals.TREE_FARM.digUpTree(mTree);%0A  %7D%0A%0A
   @Test%0A  public
@@ -1388,94 +1388,8 @@
  %7D%0A%0A
-  @After%0A  public void cleanUp() %7B%0A    ChopInternals.TREE_FARM.digUpTree(mTree);%0A  %7D%0A%0A
   pr

move cleanup to top of tests since if someone needs to copy the setup they probably also want the cleanup