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;

/**
 * Tests usage of Chop.withTag()
 */
@RunWith(ChopTestTestRunner.class)
public class SettableTaggerTest {

  @Mock Chop.Tree mTree;

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

    Chop.plantTree(mTree);
  }

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

  @Test
  public void testSettableTagger() {
    String expectedTag = "MYTESTTAG";

    Chop.withTag(expectedTag).d("Test message");

    verify(mTree).chopLog(
        any(Chop.Level.class),
        eq(expectedTag),
        anyString());
  }
}

@@ -159,16 +159,53 @@
 .Mock;%0A%0A
+import static org.junit.Assert.fail;%0A
 import s
@@ -1016,11 +1016,406 @@
 ());%0A  %7D
+%0A%0A  @Test%0A  public void testImpossibleDefault() %7B%0A    Chop.ChoppingToolsAdapter adapter = Chop.withTag(%22testTag%22);%0A%0A    try %7B%0A      Chop.DefaultableChoppingToolsAdapter defaultableAdapter = (Chop.DefaultableChoppingToolsAdapter)adapter;%0A      defaultableAdapter.byDefault();%0A    %7D catch (ClassCastException e) %7B%0A      // Success%0A      return;%0A    %7D%0A    fail(%22Expected a ClassCastException%22);%0A  %7D
 %0A%7D%0A

add a test to makes sure I never do that again (you should never be able to call withTag().byDefault();