### Question:
SerieReviewRepository extends CrudRepository<SerieReviewDao, SerieReview> { public List<SerieReview> findAllByRating(boolean asc) { QueryBuilder<SerieReview> localKinoQueryBuilder = dao.queryBuilder(); List<SerieReview> list = localKinoQueryBuilder.build().list(); Collections.sort(list, new RatingComparator()); if(asc){ return list; } Collections.reverse(list); return list; } SerieReviewRepository(DaoSession daoSession); SerieReview findByMovieId(long movieId); List<SerieReview> findAllByRating(boolean asc); List<SerieReview> findAllByTitle(boolean asc);  }### Answer:
@Test public void findAllByRatingAsc() { Review badReview = mock(Review.class); Review betterReview = mock(Review.class); doReturn(10.0f).when(badReview).getRating(); doReturn(30).when(badReview).getMaxRating(); doReturn(5.0f).when(betterReview).getRating(); doReturn(10).when(betterReview).getMaxRating(); SerieReview badSerieReview = mock(SerieReview.class); doReturn(betterReview).when(serieReview).getReview(); doReturn(badReview).when(badSerieReview).getReview(); QueryBuilder queryBuilder = mock(QueryBuilder.class); doReturn(queryBuilder).when(serieReviewDao).queryBuilder(); Query query = mock(Query.class); doReturn(query).when(queryBuilder).build(); doReturn(Arrays.asList(serieReview, badSerieReview)).when(query).list(); assertEquals( Arrays.asList(badSerieReview, serieReview), new SerieReviewRepository(daoSession).findAllByRating(true) ); }
@Test public void findAllByRatingDesc() { Review badReview = mock(Review.class); Review betterReview = mock(Review.class); doReturn(10.0f).when(badReview).getRating(); doReturn(30).when(badReview).getMaxRating(); doReturn(5.0f).when(betterReview).getRating(); doReturn(10).when(betterReview).getMaxRating(); SerieReview badSerieReview = mock(SerieReview.class); doReturn(betterReview).when(serieReview).getReview(); doReturn(badReview).when(badSerieReview).getReview(); QueryBuilder queryBuilder = mock(QueryBuilder.class); doReturn(queryBuilder).when(serieReviewDao).queryBuilder(); Query query = mock(Query.class); doReturn(query).when(queryBuilder).build(); doReturn(Arrays.asList(serieReview, badSerieReview)).when(query).list(); assertEquals( Arrays.asList(serieReview, badSerieReview), new SerieReviewRepository(daoSession).findAllByRating(false) ); }