Skip to content
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

Correct the playing status logic. #367

Merged
merged 6 commits into from
Jul 12, 2022
Merged

Conversation

yschimke
Copy link
Collaborator

@yschimke yschimke commented Jul 12, 2022

WHAT

Correct logic from #360

See #360

WHY

Loading state is a broken proxy for Buffering. So use the correct value.

HOW

Checklist 📋

  • Add explicit visibility modifier and explicit return types for public declarations
  • Run spotless check
  • Run tests
  • Update metalava's signature text files

@yschimke yschimke requested a review from luizgrp July 12, 2022 09:43
@yschimke yschimke marked this pull request as ready for review July 12, 2022 09:43
PlayerStateMapper.map(player.playbackState)
}
_currentState.value =
if ((player.playbackState == Player.STATE_BUFFERING || player.playbackState == Player.STATE_READY) && player.playWhenReady) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: is player.isPlaying not relevant at all for the state to be playing?

nit: if so, kdoc should be updated (maybe to a more generic text this time #360 (comment))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

playing is strictly whether time is moving forward. It's not relevant for the UI components, because it should be a subset of this logic.

@yschimke yschimke requested a review from luizgrp July 12, 2022 10:38
* limitations under the License.
*/

package com.google.android.horologist.media.data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should this be placed in a broader package (I've been using com.google.android.horologist.test.toolbox.testdoubles) so it can be used by other tests in other packages? ignore this comment if this test double is specific to the tests in this package

import com.google.common.truth.Truth.assertThat
import org.junit.Test

class PlayerStateMapperTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the tests in this file don't look like unit tests for PlayerStateMapper itself, they look like integration tests for media3.Player and PlayerStateMapper in the FakePlayer implementation. Which is odd given it looks like it is testing a test double implementation.

I'd question if this is necessary. If yes, then I would consider moving the test double to an individual module ("media-data-fixtures"), where the implementation is in main folder and this test is in the test folder.

Alternatively, as a quick win would be to just rename this file and move to another package (suggestion, prefix with integration so it is clear: integration.player.PlayerTest).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to clarify my previous comment, I think it's valid to have the test for the test double, if it is complex enough and we would like to provide it as fixture, where I suggested to check if it's "necessary" I meant to check if it's intended

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it's focused on PlayerStateMapper. I've introduced PlayerStateMapper and MediaItemPositionMapper, because they are evidently things that are discussion worthy, even a doc for one of them. Pulling it out because they don't appear to be just minor implementation details of PlayerRepositoryImpl, but standalone business logic.

I don't understand the comment about it testing the test double, it's hard to use the TestExoPlayer to test specific states like this (or if it's simple, then we can follow up on this PR). The test double just extends StubPlayer to return specific values, and I really want a test that documents the various cases for PlayerStateMapper. It's not a general purpose one, just enough to get specific player states.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally agree with the benefits of extracting out those classes.

re "testing the test double", my apologies, I missed the call to PlayerStateMapper.map in line 52 (or this was added now after my comment) so I had the impression that this test class was only calling functions from FakePlayer class

nit: suggestion for clarity:

@Test
    fun `check playback state while playing`() {
        val player = fakeStatePlayer.overrideState(
            playbackState = Player.STATE_READY,
            playWhenReady = true
        )

        val state = PlayerStateMapper.map(fakeStatePlayer)

        assertThat(state).isEqualTo(PlayerState.Playing)
    }

it adds two extra lines to each test, but it makes clearer which function is being tested, specially now that the class has more than one public function

@yschimke yschimke merged commit e8c15b4 into google:main Jul 12, 2022
@yschimke yschimke deleted the playing_status branch July 15, 2022 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants