@Implements(Context.class)
public class CustomContext
{
private final SharedPreferences preferences = new TestSharedPreferences(new HashMap<String, Map<String, Object>>(), "__default__", Context.MODE_PRIVATE);
@Implementation
public SharedPreferences getSharedPreferences(String name, int mode)
{
System.out.println("ShadowSharedPreferenceSavableContext");
return preferences;
}
}I'm just starting to learn Robolectric. I hope that you can help me with my problem. Thank you
Carlo
I wanted to ask on how to create a custom runner that can inject the custom Context class. I'm hoping that you can help me. Thank you for your replies
--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public class CustomTestRunner extends RobolectricTestRunner {
private static final List<String> CUSTOM_SHADOW_TARGETS = Collections.unmodifiableList(Arrays.asList("com.myPackage.android.CustomContext"));
public CustomTestRunner(Class<?> testClass) throws InitializationError { super(testClass); }
@Override protected ShadowMap createShadowMap() { return super.createShadowMap().newBuilder().addShadowClass(CustomContext.class).build(); }
@Override public Setup createSetup() { return new CustomSetup(); }
public class CustomSetup extends Setup {
@Override public boolean shouldInstrument(ClassInfo classInfo) { return CUSTOM_SHADOW_TARGETS.contains(classInfo.getName()) || super.shouldInstrument(classInfo); } }
}