package com.kickstarter;

import android.content.Context;
import android.support.annotation.NonNull;

import com.kickstarter.libs.Environment;
import com.kickstarter.libs.KSString;
import com.kickstarter.libs.Koala;
import com.kickstarter.libs.MockCurrentConfig;
import com.kickstarter.libs.MockTrackingClient;
import com.kickstarter.services.MockApiClient;
import com.kickstarter.services.MockWebClient;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.multidex.ShadowMultiDex;

import rx.observers.TestSubscriber;

@RunWith(KSRobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, shadows = ShadowMultiDex.class, sdk = KSRobolectricGradleTestRunner.DEFAULT_SDK)
public abstract class KSRobolectricTestCase extends TestCase {
  private TestKSApplication application;
  public TestSubscriber<String> koalaTest;
  private Environment environment;

  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    final MockTrackingClient testTrackingClient = new MockTrackingClient();
    koalaTest = new TestSubscriber<>();
    testTrackingClient.eventNames.subscribe(koalaTest);

    environment = application().component().environment().toBuilder()
      .apiClient(new MockApiClient())
      .currentConfig(new MockCurrentConfig())
      .webClient(new MockWebClient())
      .koala(new Koala(testTrackingClient))
      .build();
  }

  protected @NonNull TestKSApplication application() {
    if (application != null) {
      return application;
    }

    application = (TestKSApplication) RuntimeEnvironment.application;
    return application;
  }

  protected @NonNull Context context() {
    return application().getApplicationContext();
  }

  protected @NonNull Environment environment() {
    return environment;
  }

  protected @NonNull KSString ksString() {
    return new KSString(application().getPackageName(), application().getResources());
  }
}

@@ -433,16 +433,107 @@
 tCase;%0A%0A
+import org.joda.time.DateTime;%0Aimport org.joda.time.DateTimeUtils;%0Aimport org.junit.After;%0A
 import o
@@ -1364,16 +1364,85 @@
 laTest);
+%0A    DateTimeUtils.setCurrentMillisFixed(new DateTime().getMillis());
 %0A%0A    en
@@ -1906,24 +1906,160 @@
 ation;%0A  %7D%0A%0A
+  @Override%0A  @After%0A  public void tearDown() throws Exception %7B%0A    super.tearDown();%0A    DateTimeUtils.setCurrentMillisSystem();%0A  %7D%0A%0A
   protected 

Use setCurrentMillisFixed for timing test???? (#138)