package org.robolectric;

import org.junit.runners.model.InitializationError;
import org.robolectric.annotation.Config;
import org.robolectric.bytecode.AndroidTranslatorClassInstrumentedTest;
import org.robolectric.bytecode.ClassInfo;
import org.robolectric.bytecode.Setup;
import org.robolectric.bytecode.ShadowMap;
import org.robolectric.internal.ParallelUniverseInterface;
import org.robolectric.res.FsFile;
import org.robolectric.res.ResourceLoader;
import org.robolectric.shadows.ShadowSystemProperties;

import java.lang.reflect.Method;

import static org.robolectric.util.TestUtil.resourceFile;

public class TestRunners {
  public static class WithCustomClassList extends RobolectricTestRunner {
    public WithCustomClassList(@SuppressWarnings("rawtypes") Class testClass) throws InitializationError {
      super(testClass);
    }

    @Override
    protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) {
      return new AndroidManifest(resourceFile("TestAndroidManifest.xml"), resourceFile("res"), resourceFile("assets"));
    }

    @Override
    public Setup createSetup() {
      return new Setup() {
        @Override
        public boolean shouldInstrument(ClassInfo classInfo) {
          String name = classInfo.getName();
          if (name.equals(AndroidTranslatorClassInstrumentedTest.CustomPaint.class.getName())
              || name.equals(AndroidTranslatorClassInstrumentedTest.ClassWithPrivateConstructor.class.getName())) {
            return true;
          }
          return super.shouldInstrument(classInfo);
        }
      };
    }
  }

  public static class WithoutDefaults extends RobolectricTestRunner {
    public WithoutDefaults(Class<?> testClass) throws InitializationError {
      super(testClass);
    }

    @Override protected ShadowMap createShadowMap() {
      // Don't do any class binding except the bare minimum, because that's what we're trying to test here.
      return new ShadowMap.Builder()
          .addShadowClass(ShadowSystemProperties.class)
          .build();
    }

    @Override protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) {
      return null;
    }

    @Override
    protected void setUpApplicationState(Method method, ParallelUniverseInterface parallelUniverseInterface, boolean strictI18n, ResourceLoader systemResourceLoader, AndroidManifest appManifest, Config config) {
      // Don't do any resource loading or app init, because that's what we're trying to test here.
    }
  }

  public static class WithDefaults extends RobolectricTestRunner {
    public WithDefaults(Class<?> testClass) throws InitializationError {
      super(testClass);
    }

    @Override public Setup createSetup() {
      return new Setup() {
        @Override public boolean shouldAcquire(String name) {
          // todo: whyyyyy!?!? if this isn't there, tests after TestRunnerSequenceTest start failing bad.
          if (name.startsWith("org.mockito.")) return false;
          return super.shouldAcquire(name);
        }
      };
    }

    @Override
    protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) {
      return new AndroidManifest(resourceFile("TestAndroidManifest.xml"), resourceFile("res"), resourceFile("assets"));
    }
  }

  public static class RealApisWithoutDefaults extends RobolectricTestRunner {
    public RealApisWithoutDefaults(Class<?> testClass) throws InitializationError {
      super(testClass);
    }

    @Override protected ShadowMap createShadowMap() {
      // Don't do any class binding, because that's what we're trying to test here.
      return ShadowMap.EMPTY;
    }

    @Override public AndroidManifest getAppManifest(Config config) {
      // Don't do any resource loading or app init, because that's what we're trying to test here.
      return null;
    }

    @Override
    protected void setUpApplicationState(Method method,
        ParallelUniverseInterface parallelUniverseInterface, boolean strictI18n,
        ResourceLoader systemResourceLoader, AndroidManifest appManifest, Config config) {
      // Don't do any resource loading or app init, because that's what we're trying to test here.
    }
  }
}

@@ -46,35 +46,127 @@
 nner
-s.model.InitializationError
+.notification.RunNotifier;%0Aimport org.junit.runners.model.InitializationError;%0Aimport org.junit.runners.model.Statement
 ;%0Aim
@@ -627,16 +627,41 @@
 .Method;
+%0Aimport java.util.Locale;
 %0A%0Aimport
@@ -2817,32 +2817,73 @@
 per(testClass);%0A
+      Locale.setDefault(Locale.ENGLISH);%0A
     %7D%0A%0A    @Over

Set default locale for Robolectric's test runner to English to avoid number localization issues. Fixes #737