Refactor: Extract HEVC and AV1 codec modules#5646
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
|
||
| class Av1CodecCapabilities( | ||
| private val query: MediaCodecQuery, | ||
| private val sdkInt: Int = Build.VERSION.SDK_INT, |
There was a problem hiding this comment.
Why do we need to set the sdkInt as a parameter? It's a constant (see the default value you're assigning).
There was a problem hiding this comment.
There's branching logic in Av1CodecCapabilities based on the value of sdkInt, which I wanted to stress in the unit tests. Mocking Build.VERSION.SDK_INT within the test file itself might be possible but there's not a pattern for it in the code, so I'd need to invent one (Robolectric? Reflection? Both feel more controversial than exposing the defaulted param)
Alternatively I might be able to remove the branching completely if it's truly dead code (and therefore have no need to test it), but my goal was to move and test the existing logic, not delete it.
What do you think? My preference personally would be to merge as-is, but happy to defer to your opinion on it.
There was a problem hiding this comment.
I believe you can just mock the version_sdk_int with mockk for that
There was a problem hiding this comment.
I think Build.VERSION.SDK_INT can't be directly mocked. I tried it and the tests failed with IllegalAccessException.
I've added a commit to remove the field by adding a small layer of indirection via a new DeviceSdk internal object that I can mock. Let me know if that is better
…ject Remove the sdkInt parameter from Av1CodecCapabilities and HevcCodecCapabilities. Instead, read Build.VERSION.SDK_INT via an internal DeviceSdk object that tests can mock with mockkObject.
Changes
This follows up on #5604 by extracting the HEVC and AV1 codec detection logic out of MediaCodecCapabilitiesTest into their own modules. After this change, MediaCodecCapabilitiesTest is just a thin delegation facade with no logic of its own.
Code assistance
Claude Code was used as an assistant during implementation, code review, and test authoring.