robolectric/robolectric — pull request #1137 by srsudar (2014-06-07 22:07:55+00:00)
Title: Made ShadowPreference call real object constructor.

This ensures that `Preference` objects set their private Context member variables correctly. Allows `PreferenceFragment`s to be added during the lifecycle of the hosting activity. Closes #1133.

The [recommended way](http://developer.android.com/guide/topics/ui/settings.html) to handle preferences using fragments involves adding a `PreferenceFragment` during the hosting activity's lifecycle. This was throwing null pointer exceptions in robolectric because the `Preference`'s context was null.

It is strange that the `PreferenceFragment` objects were able to be instantiated and added to activities without this fix. Someone more familiar with the robolectric way of doing things should double check this to make sure it makes sense. Added tests for this case and modified the existing ShadowPreference tests to account for the fact that `defStyle` must now be a real style attr.