### Question:
SerieReviewRepository extends CrudRepository<SerieReviewDao, SerieReview> { public List<SerieReview> findAllByTitle(boolean asc) { QueryBuilder<SerieReview> serieReviewQueryBuilder = dao.queryBuilder(); List<SerieReview> list = serieReviewQueryBuilder.build().list(); Collections.sort(list, new Comparator<SerieReview>() { @Override public int compare(SerieReview o1, SerieReview o2) { Review review1 = o1.getReview(); Review review2 = o2.getReview(); if (review1 == null || review1.getTitle() == null) { return -1; } else if (review2 == null || review2.getTitle() == null) { return 1; } else { return Collator.getInstance().compare(review1.getTitle(), review2.getTitle()); } } }); if(!asc){ 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 findAllByTitleAsc() { Review aReview = mock(Review.class); Review anotherReview = mock(Review.class); doReturn("Banane").when(aReview).getTitle(); doReturn("Pingouin").when(anotherReview).getTitle(); SerieReview aSerieReview = mock(SerieReview.class); doReturn(anotherReview).when(serieReview).getReview(); doReturn(aReview).when(aSerieReview).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, aSerieReview)).when(query).list(); assertEquals( Arrays.asList(aSerieReview, serieReview), new SerieReviewRepository(daoSession).findAllByTitle(true) ); }
@Test public void findAllByTitleDesc() { Review aReview = mock(Review.class); Review anotherReview = mock(Review.class); doReturn("Banane").when(aReview).getTitle(); doReturn("Pingouin").when(anotherReview).getTitle(); SerieReview aSerieReview = mock(SerieReview.class); doReturn(anotherReview).when(serieReview).getReview(); doReturn(aReview).when(aSerieReview).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, aSerieReview)).when(query).list(); assertEquals( Arrays.asList(serieReview, aSerieReview), new SerieReviewRepository(daoSession).findAllByTitle(false) ); }