Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
Component used: androidx.media:media
Version used: 1.3.1 and 1.4.3
Devices/Android versions reproduced on: None - JUnit
In v1.3.1 of AndroidX Media, this change was introduced:
This static field was introduced into
MediaSessionCompat
:For reasons that are not immediately obvious, this has prevented normal mocking of the
MediaSessionCompat
class.Frameworks such as Mockito presumably attempt to instantiate an empty version of the class via their bytecode mechanisms, and for JVM-related reasons, this has the consequence of initialising this static property. In the JUnit context, Build.VERSION returns null for all of its fields and therefore this causes a null pointer exception. It also cannot be conventionally set or mocked.
We currently have a workaround available to us, in the form of a test setter that uses reflection:
and
However, as you might hope, this is flagged by the build process as a warning and ultimately due to be prohibited - therefore not a sustainable solution.
I realise that JUnit-based mocking of Android platform components is potentially fraught with difficulty and that we should not expect all of them to work seamlessly. However this did work and the approach taken here has broken it in a way that could probably be avoided.
Is it possible please to move this code back to an inline position in the constructor, or an instance method?