New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ShadowPreference doesn't implement getContext() #1671
Comments
Methods that aren't shadowed simply call through to the underlying android object. If anything, |
Sure. I have an annotation processing library that generates boilerplate Corresponding Robolectric test The generated code looks like this: public class CustomPreference$$Barbershop<T extends io.sweers.barber.sample.testing.CustomPreference> implements Barber.IBarbershop<T> {
protected WeakHashSet lastStyledTargets = new WeakHashSet();
@Override
public void style(final T target, final AttributeSet set, final int[] attrs, final int defStyleAttr, final int defStyleRes) {
this.lastStyledTargets.add(target);
if (set == null) {
return;
}
TypedArray a = target.getContext().obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes);
// Retrieve custom attributes
if (a.hasValue(0)) {
target.titleColor = a.getColor(0, -1);
}
if (a.hasValue(1)) {
target.summaryColor = a.getColor(1, -1);
}
a.recycle();
}
protected boolean hasStyled(final T target) {
return this.lastStyledTargets.contains(target);
}
} The problem occurs via NPE on this line: TypedArray a = target.getContext().obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes); Because Let me know if you need any other info! |
Robolectric 4.0 fixes many longstanding issues; could you check to see if this remains a problem? If so, please feel free to reopen this issue and include a link to a public git repo demonstrating the problem to help us diagnose. Thank you! |
Real Preferences have a getContext() method, but the current ShadowPreference implementation currently doesn't. This breaks verifying custom styleable attributes on custom preference objects.
The text was updated successfully, but these errors were encountered: