1

I'm trying to unit test some code that uses a library (android priority jobqueue) that requires the powermanager service to exist in some form, but when it tries to access it, getsystemservice returns null, and the library crashes with a NullPointerException.

I've tried:

  • using older code to inject a mock power manager into robolectric, but the code doesn't work anymore due to api changes in 3.0/3.1.
  • using a custom NetworkUtil class for android-priority-jobqueue, but it never does not acknowledge I've set it, and it creates it's own that looks up the power manager.
  • not using robolectric at all, and mocking getsystemservice

Nothing has so far worked. How are people testing code using android-priority-jobqueue, or the powermanager via robolectric? How should it be done?

Thanks :)

Tomasu
  • 181
  • 1
  • 13
  • some code please? – piotrek1543 Sep 03 '16 at 21:22
  • It appears it was a mix of issues. I haven't gone back to figure out the exact causes, but my problems are solved. I imagine the latest snapshot of robolectric caused issues, and potentially allowing robolectric to create my actual Application caused issues. not 100% sure. Anyhow, thank you for responding. – Tomasu Sep 05 '16 at 18:26

0 Answers0