private static RobolectricClassLoader getDefaultLoader() { if (defaultLoader == null) { defaultLoader = new RobolectricClassLoader(ShadowWrangler.getInstance()); } return defaultLoader; }
protected void delegateLoadingOf(final String className) { classLoader.delegateLoadingOf(className); }
@Override public Class loadClass(String name) throws ClassNotFoundException { boolean shouldComeFromThisClassLoader = !(name.startsWith("org.junit") || name.startsWith("org.hamcrest") || name.startsWith("org.specs2") || name.startsWith("scala.")); //org.specs2 and scala. allows for android projects with mixed scala\java tests to be run with Maven Surefire (see the RoboSpecs project on github) Class<?> theClass; if (shouldComeFromThisClassLoader) { theClass = super.loadClass(name); } else { theClass = getParent().loadClass(name); } return theClass; }
public RobolectricClassLoader(ClassHandler classHandler, List<String> customClassNames) { super(RobolectricClassLoader.class.getClassLoader(), null); delegateLoadingOf(AndroidTranslator.class.getName()); delegateLoadingOf(ClassHandler.class.getName()); final String classCachePath = System.getProperty("cached.robolectric.classes.path"); final File classCacheDirectory; if (null == classCachePath || "".equals(classCachePath.trim())) { classCacheDirectory = new File("./tmp"); } else { classCacheDirectory = new File(classCachePath); } classCache = new ClassCache(new File(classCacheDirectory, "cached-robolectric-classes.jar").getAbsolutePath(), AndroidTranslator.CACHE_VERSION); try { ClassPool classPool = new ClassPool(); classPool.appendClassPath(new LoaderClassPath(RobolectricClassLoader.class.getClassLoader())); androidTranslator = new AndroidTranslator(classHandler, classCache, customClassNames); addTranslator(classPool, androidTranslator); } catch (NotFoundException e) { throw new RuntimeException(e); } catch (CannotCompileException e) { throw new RuntimeException(e); } }
super(isInstrumented() ? testClass : classLoader.bootstrap(testClass)); delegateLoadingOf(android.R.class.getName()); Class<?> delegateClass = classLoader.bootstrap(this.getClass()); try { Constructor<?> constructorForDelegate = delegateClass.getConstructor(Class.class); this.delegate = (RobolectricTestRunnerInterface) constructorForDelegate.newInstance(classLoader.bootstrap(testClass)); this.delegate.setRobolectricConfig(robolectricConfig); this.delegate.setDatabaseMap(databaseMap);
public Class<?> bootstrap(Class testClass) { String testClassName = testClass.getName(); try { return loadClass(testClassName); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
/** * Call this if you would like Robolectric to rewrite additional classes and turn them * into "do nothing" classes which proxy all method calls to shadow classes, just like it does * with the android classes by default. * * @param classOrPackageToBeInstrumented fully-qualified class or package name */ protected static void addClassOrPackageToInstrument(String classOrPackageToBeInstrumented) { if (!isInstrumented()) { defaultLoader.addCustomShadowClass(classOrPackageToBeInstrumented); } }
@Override protected Class findClass(String name) throws ClassNotFoundException { byte[] classBytes = classCache.getClassBytesFor(name); if (classBytes != null) { return defineClass(name, classBytes, 0, classBytes.length); } return super.findClass(name); } }
super(isInstrumented() ? testClass : classLoader.bootstrap(testClass)); delegateLoadingOf(android.R.class.getName()); Class<?> delegateClass = classLoader.bootstrap(this.getClass()); try { Constructor<?> constructorForDelegate = delegateClass.getConstructor(Class.class); this.delegate = (RobolectricTestRunnerInterface) constructorForDelegate.newInstance(classLoader.bootstrap(testClass)); this.delegate.setRobolectricConfig(robolectricConfig); this.delegate.setDatabaseMap(databaseMap);
private static RobolectricClassLoader getDefaultLoader() { if (defaultLoader == null) { defaultLoader = new RobolectricClassLoader(ShadowWrangler.getInstance()); } return defaultLoader; }
protected void delegateLoadingOf(final String className) { classLoader.delegateLoadingOf(className); }