package toothpick;

import org.junit.After;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;

public class ToothPickTest {

  @Test
  public void getInjector_shouldReturnNull_whenNoInjectorByThisKeyWasCreated() throws Exception {
    //GIVEN

    //WHEN
    Injector injector = ToothPick.getInjector(this);

    //THEN
    assertThat(injector, nullValue());
  }

  @Test
  public void getInjector_shouldReturnAnInjector_whenThisInjectorByThisKeyWasCreated() throws Exception {
    //GIVEN
    Injector injector = ToothPick.createInjector(this);

    //WHEN
    Injector injector2 = ToothPick.getInjector(this);

    //THEN
    assertThat(injector, notNullValue());
    assertThat(injector, sameInstance(injector2));
  }

  @Test
  public void createInjector_shouldReturnAnInjectorWithAParent_whenThisInjectorByThisKeyWasCreatedWithAParent() throws Exception {
    //GIVEN
    Injector injectorParent = ToothPick.createInjector("foo");

    //WHEN
    Injector injector = ToothPick.createInjector(injectorParent, "bar");

    //THEN
    assertThat(injector, notNullValue());
    assertThat(injector.getParent(), sameInstance(injectorParent));
  }

  @Test
  public void reset_shouldClear_WhenSomeInjectorsWereCreated() throws Exception {
    //GIVEN
    ToothPick.createInjector("foo");
    ToothPick.createInjector("bar");

    //WHEN
    ToothPick.reset();
    Injector injector0AfterReset = ToothPick.getInjector("foo");
    Injector injector1AfterReset = ToothPick.getInjector("bar");

    //THEN
    assertThat(injector0AfterReset, nullValue());
    assertThat(injector1AfterReset, nullValue());
  }

  @Test
  public void destroyInjector_shouldClearThisInjector_WhenThisInjectorsWasCreated() throws Exception {
    //GIVEN
    ToothPick.createInjector("foo");

    //WHEN
    ToothPick.destroyInjector("foo");
    Injector injectorAfterReset = ToothPick.getInjector("foo");

    //THEN
    assertThat(injectorAfterReset, nullValue());
  }

  @Test
  public void destroyInjector_shouldClearThisInjector_WhenThisInjectorsWasNotCreated() throws Exception {
    //GIVEN

    //WHEN
    ToothPick.destroyInjector("foo");
    Injector injectorAfterReset = ToothPick.getInjector("foo");

    //THEN
    assertThat(injectorAfterReset, nullValue());
  }

  @After
  public void tearDown() throws Exception {
    ToothPick.reset();
  }
}
@@ -2117,32 +2117,785 @@
 lValue());%0A  %7D%0A%0A
+  @Test%0A  public void getOrCreateInjector_shouldReturnAnInjector_WhenOneWasCreatedWithSameKey() throws Exception %7B%0A    //GIVEN%0A    Injector injector = ToothPick.createInjector(%22foo%22);%0A%0A    //WHEN%0A    Injector injector2 = ToothPick.getOrCreateInjector(null, %22foo%22);%0A%0A    //THEN%0A    assertThat(injector, sameInstance(injector2));%0A  %7D%0A%0A  @Test%0A  public void getOrCreateInjector_shouldReturnANewInjectorInjector_WhenOneWasNotCreatedWithSameKey() throws Exception %7B%0A    //GIVEN%0A    Injector injectorParent = ToothPick.createInjector(%22bar%22);%0A%0A    //WHEN%0A    Injector injector = ToothPick.getOrCreateInjector(injectorParent, %22foo%22);%0A%0A    //THEN%0A    assertThat(injector, notNullValue());%0A    assertThat(injector.getParent(), sameInstance(injectorParent));%0A  %7D%0A%0A
   @Test%0A  public

increase coverage