Skip to content

Fixing NoSuchElement list empty in PostDayViewsUseCase#10850

Merged
planarvoid merged 5 commits intodevelopfrom
issue/10830-no-such-element-list-empty
Nov 29, 2019
Merged

Fixing NoSuchElement list empty in PostDayViewsUseCase#10850
planarvoid merged 5 commits intodevelopfrom
issue/10830-no-such-element-list-empty

Conversation

@develric
Copy link
Copy Markdown
Contributor

@develric develric commented Nov 25, 2019

Fixes #10830

This PR does two things:

  1. Attempt to fix issue NoSuchElementException: List is empty. #10830: was not actually able to reproduce but applied same approach as used in OverviewUseCase.buildUiModel (that is introduced a check for the list not being empty)
  2. In PostDayViewsUseCase.fetchRemoteData in case of error I used selectedDateProvider.onDateLoadingFailed insetad of selectedDateProvider.onDateLoadingSucceeded

To test:

Since it was not possible to reproduce, I think we can only make sure we did not introduce issues in the relevant stats card, so smoke test the post day/views card with different sites/posts and compare with the not modified WordPress app to check you get the same visualizations.

PR submission checklist:

  • I have considered adding unit tests where possible.

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@develric develric added this to the 13.8 milestone Nov 25, 2019
@develric develric requested a review from planarvoid November 25, 2019 23:25
@develric develric self-assigned this Nov 25, 2019
@peril-wordpress-mobile
Copy link
Copy Markdown

peril-wordpress-mobile bot commented Nov 25, 2019

You can test the changes on this Pull Request by downloading the APK here.

Copy link
Copy Markdown
Contributor

@planarvoid planarvoid left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, the code looks good 👍 Do you think you can add a test for the PostDayViewsUseCase for the case when the dayViews list is empty?

# Resolved Conflicts in:
#	WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/PostDayViewsUseCase.kt
@develric
Copy link
Copy Markdown
Contributor Author

Hey @planarvoid 👋

Do you think you can add a test for the PostDayViewsUseCase for the case when the dayViews list is empty?

Sure, makes sense! I added a test case as requested; since I'm not much familiar with the stats part of the app (as you are instead 😊), I'm not fully sure the Empty state is what we actually expect (that is if I created the correct preconditions for the test) so appreciate your usual valuable feedback! 😎

@planarvoid planarvoid self-requested a review November 28, 2019 16:27
@planarvoid
Copy link
Copy Markdown
Contributor

hey @develric, thanks for the changes. If I understand it correctly, we're fixing here an edge case where the fetch actually returns some data (so the result is not empty) and the get does return an empty list. I have no idea how this happens but I think we can emulate it in the test. The way you wrote it it will never go to the buildUiModel method because fetch is empty and it will just emit State.EMPTY and that's it. I think to get the correct behaviour we need something like this. In this we actually get a SUCCESS result and an empty list. I don't think this is a state we want but it's what we were getting.

val forced = false
        whenever(emptyModel.dayViews).thenReturn(listOf())
        whenever(model.dayViews).thenReturn(listOf(Day("2019-10-10", 50)))
        whenever(store.getPostDetail(site, postId)).thenReturn(emptyModel)
        whenever(store.fetchPostDetail(site, postId, forced)).thenReturn(
                OnStatsFetched(
                        model
                )
        )

        val result = loadData(true, forced)

        Assertions.assertThat(result.state).isEqualTo(SUCCESS)
        Assertions.assertThat(result.data).isEmpty()

@develric
Copy link
Copy Markdown
Contributor Author

develric commented Nov 28, 2019

Thanks for the clarifying explanation @planarvoid 🙇‍♂️! I have reported changes here with an extra comment to get the context. Let me know 😊.

@planarvoid
Copy link
Copy Markdown
Contributor

thanks for the change @develric ! The comment makes a lot of sense 👍

Copy link
Copy Markdown
Contributor

@planarvoid planarvoid left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@planarvoid planarvoid merged commit 2dceeff into develop Nov 29, 2019
@planarvoid planarvoid deleted the issue/10830-no-such-element-list-empty branch November 29, 2019 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NoSuchElementException: List is empty.

2 participants